// Call tick() on each active motor inline void StepTicker::tick(){ uint8_t current_id = 0; StepperMotor* current = this->active_motors[0]; while(current != NULL ){ current->tick(); current_id++; current = this->active_motors[current_id]; } }
bool Tasks::resolveTasks(Clock *clk, StepperMotor stepper) { if (this->list[0].time == clk->getTime()) { // already done once ? don't do it if (this->list[0].done) return (false); stepper.step(683); // decrease the food decreaseFoodLevel(0); // already done once, remember it this->list[0].done = true; return (true); } else if (this->list[1].time == clk->getTime()) { // already done once ? don't do it if (this->list[1].done) return (false); stepper.step(682); // decrease the food decreaseFoodLevel(1); // already done once, remember it this->list[1].done = true; return (true); } else if (this->list[2].time == clk->getTime()) { // already done once ? don't do it if (this->list[2].done) return (false); stepper.step(683); delay(10000); stepper.step(2048); // decrease the food decreaseFoodLevel(2); // already done once, remember it this->list[2].done = true; return (true); // no task to run ? reset the tokens } else { this->list[0].done = false; this->list[1].done = false; this->list[2].done = false; } // we didn't find a task to launch return (false); }
// This thread function is a friend function of the class void* threadedStep(void *value){ StepperMotor *stepper = static_cast<StepperMotor*>(value); while(stepper->threadRunning){ stepper->step(); usleep(stepper->threadedStepPeriod * 1000); // convert from ms to us if(stepper->threadedStepNumber>0) stepper->threadedStepNumber--; if(stepper->threadedStepNumber==0) stepper->threadRunning = false; } return 0; }
// Call signal_mode_finished() on each active motor that asked to be signaled. We do this instead of inside of tick() so that // all tick()s are called before we do the move finishing void StepTicker::signal_moves_finished(){ uint8_t current_id = 0; StepperMotor* current = this->active_motors[0]; while(current != NULL ){ if( current->is_move_finished ){ current->signal_move_finished(); if( current->moving == false ){ current_id--; } } current_id++; current = this->active_motors[current_id]; } this->moves_finished = false; }
static void manualIdleController(int positionPercent) { // todo: this is not great that we have to write into configuration here boardConfiguration->manIdlePosition = positionPercent; if (isCranking()) { positionPercent += engineConfiguration->crankingIdleAdjustment; } percent_t cltCorrectedPosition = interpolate2d(engine->engineState.clt, config->cltIdleCorrBins, config->cltIdleCorr, CLT_CURVE_SIZE) / PERCENT_MULT * positionPercent; // let's put the value into the right range cltCorrectedPosition = maxF(cltCorrectedPosition, 0.01); cltCorrectedPosition = minF(cltCorrectedPosition, 99.9); if (engineConfiguration->debugMode == IDLE) { tsOutputChannels.debugFloatField1 = actualIdlePosition; } if (absF(cltCorrectedPosition - actualIdlePosition) < 1) { return; // value is pretty close, let's leave the poor valve alone } actualIdlePosition = cltCorrectedPosition; if (boardConfiguration->useStepperIdle) { iacMotor.setTargetPosition(cltCorrectedPosition / 100 * engineConfiguration->idleStepperTotalSteps); } else { setIdleValvePwm(cltCorrectedPosition); } }
// This thread function is a friend function of the class void* threadedStep(void *value){ StepperMotor *stepper = static_cast<StepperMotor*>(value); while(stepper->threadRunning){ if(stepper->gpio_LSW->getValue() == GPIO::LOW){ //switch is tripped...should go right... stepper->setDirection(StepperMotor::DIRECTION::CLOCKWISE); } if(stepper->gpio_RSW->getValue() == GPIO::LOW){ stepper->setDirection(StepperMotor::DIRECTION::ANTICLOCKWISE); } stepper->step(); usleep(stepper->threadedStepPeriod * 1000); // convert from ms to us if(stepper->threadedStepNumber>0) stepper->threadedStepNumber--; if(stepper->threadedStepNumber==0) stepper->threadRunning = false; } return 0; }
static void initIdleHardware() { if (boardConfiguration->useStepperIdle) { iacMotor.initialize(boardConfiguration->idle.stepperStepPin, boardConfiguration->idle.stepperDirectionPin, engineConfiguration->idleStepperReactionTime, engineConfiguration->idleStepperTotalSteps, engineConfiguration->stepperEnablePin); } else { /** * Start PWM for idleValvePin */ startSimplePwmExt(&idleSolenoid, "Idle Valve", boardConfiguration->idle.solenoidPin, &enginePins.idleSolenoidPin, boardConfiguration->idle.solenoidFrequency, boardConfiguration->manIdlePosition / 100, applyIdleSolenoidPinState); } }
void setup() { // every _I terminated pin constant is an input pinMode(PIN_DIRECTION_DOWN_I, INPUT); pinMode(PIN_DIRECTION_RIGHT_I, INPUT); pinMode(PIN_RESET_VALUE_I, INPUT); pinMode(PIN_SWITCH_LIGHT_I, INPUT); // every _O terminated pin constant is an output pinMode(PIN_STOCK_INDICATOR_O, OUTPUT); // guess what, we start the screen lcd.begin(SCREEN_X, SCREEN_Y); // attach the stepper motor stepper.attach(STEPPER_IN1, STEPPER_IN2, STEPPER_IN3, STEPPER_IN4); // A hello screen on setup lcd.setCursor(3, 2); lcd.print("BONJOUR!"); delay(MILLIS_PER_SECOND * 3); // display clock menu events->displayMenu(0, lcd, clk, tasks); }