//-------------------------------------------------------------- void Winch::update() { stepperEmu::update(); curPosition = (stepperEmu::curPosi / 25600.) * WINCH_DIA * PI; if (curPosition < LIMIT_TOP) { hardStop(); curPosi = LIMIT_TOP*25600. / ( WINCH_DIA*PI ); } else if (curPosition > LIMIT_BOTTOM) { hardStop(); curPosi = LIMIT_BOTTOM*25600. / ( WINCH_DIA*PI ); } curPosition = TRUSS_HEIGHT - curPosition + LIMIT_TOP; }
void SampleChannel::kill(int frame) { if (wave != NULL && status != STATUS_OFF) { if (mute || mute_i || (status == STATUS_WAIT && mode & LOOP_ANY)) hardStop(frame); else setFadeOut(DO_STOP); } }
void SampleChannel::stop() { if (mode == SINGLE_PRESS && status == STATUS_PLAY) { if (mute || mute_i) hardStop(0); /// FIXME - wrong frame value else setFadeOut(DO_STOP); } else // stop a SINGLE_PRESS immediately, if the quantizer is on if (mode == SINGLE_PRESS && qWait == true) qWait = false; }
void SampleChannel::onZero(int frame) { if (wave == NULL) return; if (mode & LOOP_ANY) { /* do a crossfade if the sample is playing. Regular chanReset * instead if it's muted, otherwise a click occurs */ if (status == STATUS_PLAY) { /* if (mute || mute_i) reset(frame); else setXFade(frame); */ reset(frame); } else if (status == STATUS_ENDING) hardStop(frame); } if (status == STATUS_WAIT) { /// FIXME - should be inside previous if! status = STATUS_PLAY; sendMidiLplay(); tracker = fillChan(vChan, tracker, frame); } if (recStatus == REC_ENDING) { recStatus = REC_STOPPED; setReadActions(false); // rec stop } else if (recStatus == REC_WAITING) { recStatus = REC_READING; setReadActions(true); // rec start } }
void L6470::init(int k_value) { // This is the generic initialization function to set up the Arduino to // communicate with the dSPIN chip. // set up the input/output pins for the application. pinMode(SLAVE_SELECT_PIN, OUTPUT); // The SPI peripheral REQUIRES the hardware SS pin- // pin 10- to be an output. This is in here just // in case some future user makes something other // than pin 10 the SS pin. pinMode(_SSPin, OUTPUT); digitalWrite(_SSPin, HIGH); pinMode(MOSI, OUTPUT); pinMode(MISO, INPUT); pinMode(SCK, OUTPUT); pinMode(BUSYN, INPUT); #if (ENABLE_RESET_PIN == 1) pinMode(RESET, OUTPUT); // reset the dSPIN chip. This could also be accomplished by // calling the "L6470::ResetDev()" function after SPI is initialized. digitalWrite(RESET, HIGH); delay(10); digitalWrite(RESET, LOW); delay(10); digitalWrite(RESET, HIGH); delay(10); #endif // initialize SPI for the dSPIN chip's needs: // most significant bit first, // SPI clock not to exceed 5MHz, // SPI_MODE3 (clock idle high, latch data on rising edge of clock) SPI.begin(); SPI.setBitOrder(MSBFIRST); SPI.setClockDivider(SPI_CLOCK_DIV16); // or 2, 8, 16, 32, 64 SPI.setDataMode(SPI_MODE3); // First things first: let's check communications. The CONFIG register should // power up to 0x2E88, so we can use that to check the communications. if (GetParam(CONFIG) == 0x2E88) { //Serial.println('good to go'); } else { //Serial.println('Comm issue'); } #if (ENABLE_RESET_PIN == 0) resetDev(); #endif // First, let's set the step mode register: // - SYNC_EN controls whether the BUSY/SYNC pin reflects the step // frequency or the BUSY status of the chip. We want it to be the BUSY // status. // - STEP_SEL_x is the microstepping rate- we'll go full step. // - SYNC_SEL_x is the ratio of (micro)steps to toggles on the // BUSY/SYNC pin (when that pin is used for SYNC). Make it 1:1, despite // not using that pin. //SetParam(STEP_MODE, !SYNC_EN | STEP_SEL_1 | SYNC_SEL_1); SetParam(KVAL_RUN, k_value); SetParam(KVAL_ACC, k_value); SetParam(KVAL_DEC, k_value); SetParam(KVAL_HOLD, k_value); // Set up the CONFIG register as follows: // PWM frequency divisor = 1 // PWM frequency multiplier = 2 (62.5kHz PWM frequency) // Slew rate is 290V/us // Do NOT shut down bridges on overcurrent // Disable motor voltage compensation // Hard stop on switch low // 16MHz internal oscillator, nothing on output SetParam(CONFIG, CONFIG_PWM_DIV_1 | CONFIG_PWM_MUL_2 | CONFIG_SR_290V_us| CONFIG_OC_SD_DISABLE | CONFIG_VS_COMP_DISABLE | CONFIG_SW_HARD_STOP | CONFIG_INT_16MHZ); // Configure the RUN KVAL. This defines the duty cycle of the PWM of the bridges // during running. 0xFF means that they are essentially NOT PWMed during run; this // MAY result in more power being dissipated than you actually need for the task. // Setting this value too low may result in failure to turn. // There are ACC, DEC, and HOLD KVAL registers as well; you may need to play with // those values to get acceptable performance for a given application. //SetParam(KVAL_RUN, 0xFF); // Calling GetStatus() clears the UVLO bit in the status register, which is set by // default on power-up. The driver may not run without that bit cleared by this // read operation. getStatus(); hardStop(); //engage motors }
void SampleChannel::sum(int frame, bool running) { if (wave == NULL || status & ~(STATUS_PLAY | STATUS_ENDING)) return; if (frame != frameRewind) { /* volume envelope, only if seq is running */ if (running) { volume_i += volume_d; if (volume_i < 0.0f) volume_i = 0.0f; else if (volume_i > 1.0f) volume_i = 1.0f; } /* fadein or fadeout processes. If mute, delete any signal. */ /** TODO - big issue: fade[in/out]Vol * internal_volume might be a * bad choice: it causes glitches when muting on and off during a * volume envelope. */ if (mute || mute_i) { vChan[frame] = 0.0f; vChan[frame+1] = 0.0f; } else if (fadeinOn) { if (fadeinVol < 1.0f) { vChan[frame] *= fadeinVol * volume_i; vChan[frame+1] *= fadeinVol * volume_i; fadeinVol += 0.01f; } else { fadeinOn = false; fadeinVol = 0.0f; } } else if (fadeoutOn) { if (fadeoutVol > 0.0f) { // fadeout ongoing if (fadeoutType == XFADE) { vChan[frame] *= volume_i; vChan[frame+1] *= volume_i; vChan[frame] = pChan[frame] * fadeoutVol * volume_i; vChan[frame+1] = pChan[frame+1] * fadeoutVol * volume_i; } else { vChan[frame] *= fadeoutVol * volume_i; vChan[frame+1] *= fadeoutVol * volume_i; } fadeoutVol -= fadeoutStep; } else { // fadeout end fadeoutOn = false; fadeoutVol = 1.0f; /* QWait ends with the end of the xfade */ if (fadeoutType == XFADE) { qWait = false; } else { if (fadeoutEnd == DO_MUTE) mute = true; else if (fadeoutEnd == DO_MUTE_I) mute_i = true; else // DO_STOP hardStop(frame); } } } else { vChan[frame] *= volume_i; vChan[frame+1] *= volume_i; } } else { if (mode & (SINGLE_BASIC | SINGLE_PRESS | SINGLE_RETRIG) || (mode == SINGLE_ENDLESS && status == STATUS_ENDING) || (mode & LOOP_ANY && !running)) // stop loops when the seq is off { status = STATUS_OFF; sendMidiLplay(); } /* temporary stop LOOP_ONCE not in ENDING status, otherwise they * would return in wait, losing the ENDING status */ //if (mode == LOOP_ONCE && status != STATUS_ENDING) if ((mode & (LOOP_ONCE | LOOP_ONCE_BAR)) && status != STATUS_ENDING) { status = STATUS_WAIT; sendMidiLplay(); } /* check for end of samples. SINGLE_ENDLESS runs forever unless * it's in ENDING mode. */ reset(frame); } }
void Robot::end(){ hardStop(); StatusManager::finalUpdate(); }