|
@@ -8,14 +8,14 @@ Atm_AccelStepper& Atm_AccelStepper::begin(int step_pin, int dir_pin) {
|
|
// clang-format off
|
|
// clang-format off
|
|
const static state_t state_table[] PROGMEM = {
|
|
const static state_t state_table[] PROGMEM = {
|
|
/* ON_ENTER ON_LOOP ON_EXIT EVT_DISABLE EVT_ENABLE EVT_ENABLED_TIMEOUT EVT_MOVE EVT_STOP EVT_EMERGENCY_STOP EVT_ON_LIMIT_LOW EVT_ON_LIMIT_HIGH EVT_ON_TARGET EVT_HOMING_LOW EVT_HOMING_HIGH ELSE */
|
|
/* ON_ENTER ON_LOOP ON_EXIT EVT_DISABLE EVT_ENABLE EVT_ENABLED_TIMEOUT EVT_MOVE EVT_STOP EVT_EMERGENCY_STOP EVT_ON_LIMIT_LOW EVT_ON_LIMIT_HIGH EVT_ON_TARGET EVT_HOMING_LOW EVT_HOMING_HIGH ELSE */
|
|
- /* DISABLE */ ENT_DISABLED, -1, -1, -1, ENABLED, -1, RUNNING, -1, -1, -1, -1, -1, HOMING_LOW, HOMING_HIGH, -1,
|
|
|
|
- /* ENABLED */ ENT_ENABLED, -1, -1, DISABLE, -1, DISABLE, RUNNING, STOP, STOP, -1, -1, -1, HOMING_LOW, HOMING_HIGH, -1,
|
|
|
|
- /* RUNNING */ ENT_RUNNING, LP_RUNNING, -1, DISABLE, -1, -1, RUNNING, STOP, STOP, LIMIT_LOW, LIMIT_HIGH, ENABLED, -1, -1, -1,
|
|
|
|
- /* STOP */ ENT_STOP, LP_STOP, -1, DISABLE, -1, -1, RUNNING, -1, -1, -1, -1, ENABLED, -1, -1, -1,
|
|
|
|
- /* HOMING_LOW */ ENT_HOMING_LOW, LP_HOMING_LOW, EXT_HOMING_LOW, DISABLE, -1, -1, -1, STOP, STOP, ENABLED, ENABLED, -1, -1, -1, -1,
|
|
|
|
- /* HOMING_HIGH */ ENT_HOMING_HIGH, LP_HOMING_HIGH, EXT_HOMING_HIGH, DISABLE, -1, -1, -1, STOP, STOP, ENABLED, ENABLED, -1, -1, -1, -1,
|
|
|
|
- /* LIMIT_LOW */ ENT_LIMIT_LOW, LP_LIMIT_LOW, -1, -1, -1, -1, RUNNING, STOP, STOP, LIMIT_LOW, -1, -1, -1, -1, -1,
|
|
|
|
- /* LIMIT_HIGH */ ENT_LIMIT_HIGH, LP_LIMIT_HIGH, -1, -1, -1, -1, RUNNING, STOP, STOP, -1, LIMIT_HIGH, -1, -1, -1, -1
|
|
|
|
|
|
+ /* DISABLE */ ENT_DISABLED, -1, -1, -1, ENABLED, -1, RUNNING, -1, -1, DISABLE, DISABLE, -1, HOMING_LOW, HOMING_HIGH, -1,
|
|
|
|
+ /* ENABLED */ ENT_ENABLED, -1, -1, DISABLE, -1, DISABLE, RUNNING, STOP, STOP, ENABLED, ENABLED, -1, HOMING_LOW, HOMING_HIGH, -1,
|
|
|
|
+ /* RUNNING */ ENT_RUNNING, LP_RUNNING, -1, DISABLE, -1, -1, RUNNING, STOP, STOP, RUNNING, RUNNING, ENABLED, -1, -1, -1,
|
|
|
|
+ /* STOP */ ENT_STOP, LP_STOP, -1, DISABLE, -1, -1, RUNNING, STOP, STOP, STOP, STOP, ENABLED, -1, -1, -1,
|
|
|
|
+ /* HOMING_LOW */ ENT_HOMING_LOW, LP_HOMING_LOW, EXT_HOMING_LOW, DISABLE, -1, -1, -1, STOP, STOP, HOMING_LOW, HOMING_LOW, -1, -1, -1, -1,
|
|
|
|
+ /* HOMING_HIGH */ ENT_HOMING_HIGH, LP_HOMING_HIGH, EXT_HOMING_HIGH, DISABLE, -1, -1, -1, STOP, STOP, HOMING_HIGH, HOMING_HIGH, -1, -1, -1, -1,
|
|
|
|
+ /* LIMIT_LOW */ ENT_LIMIT_LOW, LP_LIMIT_LOW, -1, -1, -1, -1, RUNNING, STOP, STOP, -1, -1, -1, -1, -1, -1,
|
|
|
|
+ /* LIMIT_HIGH */ ENT_LIMIT_HIGH, LP_LIMIT_HIGH, -1, -1, -1, -1, RUNNING, STOP, STOP, -1, -1, -1, -1, -1, -1
|
|
};
|
|
};
|
|
// clang-format on
|
|
// clang-format on
|
|
Machine::begin( state_table, ELSE );
|
|
Machine::begin( state_table, ELSE );
|
|
@@ -34,7 +34,7 @@ Atm_AccelStepper& Atm_AccelStepper::begin(int step_pin, int dir_pin) {
|
|
|
|
|
|
int Atm_AccelStepper::event( int id ) {
|
|
int Atm_AccelStepper::event( int id ) {
|
|
bool tempState ;
|
|
bool tempState ;
|
|
- bool changed = 0 ;
|
|
|
|
|
|
+
|
|
switch ( id ) {
|
|
switch ( id ) {
|
|
case EVT_DISABLE:
|
|
case EVT_DISABLE:
|
|
return 0;
|
|
return 0;
|
|
@@ -73,6 +73,8 @@ int Atm_AccelStepper::event( int id ) {
|
|
limitLow_State = limitLow_avg(limitLow_State_raw);
|
|
limitLow_State = limitLow_avg(limitLow_State_raw);
|
|
changed = limitLow_State != limitLow_State_prev ? 1 : 0 ;
|
|
changed = limitLow_State != limitLow_State_prev ? 1 : 0 ;
|
|
limitLow_State_prev = limitLow_State ;
|
|
limitLow_State_prev = limitLow_State ;
|
|
|
|
+ //Serial.println(limitLow_State);
|
|
|
|
+ if (changed){push( connectors, ON_ONLIMITLOW, 0, limitLow_State, 0 );}
|
|
return changed ;
|
|
return changed ;
|
|
|
|
|
|
|
|
|
|
@@ -100,6 +102,7 @@ int Atm_AccelStepper::event( int id ) {
|
|
limitHigh_State = limitHigh_avg(limitHigh_State_raw);
|
|
limitHigh_State = limitHigh_avg(limitHigh_State_raw);
|
|
changed = limitHigh_State != limitHigh_State_prev ? 1 : 0;
|
|
changed = limitHigh_State != limitHigh_State_prev ? 1 : 0;
|
|
limitHigh_State_prev = limitHigh_State;
|
|
limitHigh_State_prev = limitHigh_State;
|
|
|
|
+ if (changed){push( connectors, ON_ONLIMITHIGH, 0, limitHigh_State, 0 );}
|
|
return changed;
|
|
return changed;
|
|
|
|
|
|
case EVT_ON_TARGET:
|
|
case EVT_ON_TARGET:
|
|
@@ -156,8 +159,25 @@ void Atm_AccelStepper::action( int id ) {
|
|
//stepper_update();
|
|
//stepper_update();
|
|
//push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
//push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
|
|
+ stepper_update();
|
|
return;
|
|
return;
|
|
case LP_RUNNING:
|
|
case LP_RUNNING:
|
|
|
|
+ // if on limits and limits are hard, stop moving in one direction
|
|
|
|
+ if(limitLow_State && _limitLow_Hard && (stepper->speed()<0.)) {
|
|
|
|
+ // Serial.println("youpi");
|
|
|
|
+ _currentStep = stepper->currentPosition();
|
|
|
|
+ stepper->moveTo(_currentStep);
|
|
|
|
+ _targetStep = _currentStep;
|
|
|
|
+ stepper->setSpeed(0);
|
|
|
|
+ }
|
|
|
|
+ if(limitHigh_State && _limitHigh_Hard && ((stepper->speed()>0.))) {
|
|
|
|
+ // Serial.println("youpi");
|
|
|
|
+ _currentStep = stepper->currentPosition();
|
|
|
|
+ stepper->moveTo(_currentStep);
|
|
|
|
+ _targetStep = _currentStep;
|
|
|
|
+ stepper->setSpeed(0);
|
|
|
|
+ }
|
|
|
|
+
|
|
stepper_update();
|
|
stepper_update();
|
|
if(stepper->speed() == 0.) {trigger(EVT_ON_TARGET);}
|
|
if(stepper->speed() == 0.) {trigger(EVT_ON_TARGET);}
|
|
return;
|
|
return;
|
|
@@ -191,23 +211,46 @@ void Atm_AccelStepper::action( int id ) {
|
|
runMode = 1;
|
|
runMode = 1;
|
|
//_isHoming = 1 ;
|
|
//_isHoming = 1 ;
|
|
stepper->setSpeed(-1*homing_speed);
|
|
stepper->setSpeed(-1*homing_speed);
|
|
|
|
+ position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
return;
|
|
return;
|
|
case LP_HOMING_LOW:
|
|
case LP_HOMING_LOW:
|
|
stepper_update();
|
|
stepper_update();
|
|
|
|
+ // if (changed && (limitHigh_State||limitLow_State)){
|
|
|
|
+ if(limitLow_State) {
|
|
|
|
+ stepper->setCurrentPosition(0);
|
|
|
|
+ _currentStep = 0;
|
|
|
|
+ homingLow_done = 1 ;
|
|
|
|
+ runMode = 0;
|
|
|
|
+ trigger(EVT_EMERGENCY_STOP);
|
|
|
|
+ push(connectors, ON_ONHOMINGLOW, 0, _currentStep, homingLow_done);
|
|
|
|
+ }
|
|
|
|
+ else if (changed && limitHigh_State){
|
|
|
|
+ homingLow_done = 0 ;
|
|
|
|
+ runMode = 0;
|
|
|
|
+ trigger(EVT_EMERGENCY_STOP);
|
|
|
|
+ push(connectors, ON_ONHOMINGLOW, 0, _currentStep, homingLow_done);
|
|
|
|
+ }//Serial.println("homing low failed");}
|
|
|
|
+
|
|
|
|
+ // push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //}
|
|
// push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
// push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
return;
|
|
return;
|
|
case EXT_HOMING_LOW:
|
|
case EXT_HOMING_LOW:
|
|
- runMode = 0;
|
|
|
|
- //_isHoming = 0;
|
|
|
|
- if(last_trigger == EVT_ON_LIMIT_LOW) {
|
|
|
|
- stepper->setCurrentPosition(0);
|
|
|
|
- _currentStep = 0;
|
|
|
|
- homingLow_done = 1 ;
|
|
|
|
- }
|
|
|
|
- else{homingLow_done = 0 ;};//Serial.println("homing low failed");}
|
|
|
|
- push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
|
- push(connectors, ON_ONHOMINGLOW, 0, _currentStep, homingLow_done);
|
|
|
|
- trigger(EVT_EMERGENCY_STOP);
|
|
|
|
|
|
+ // runMode = 0;
|
|
|
|
+ // //_isHoming = 0;
|
|
|
|
+ // if(last_trigger == EVT_ON_LIMIT_LOW) {
|
|
|
|
+ // stepper->setCurrentPosition(0);
|
|
|
|
+ // _currentStep = 0;
|
|
|
|
+ // homingLow_done = 1 ;
|
|
|
|
+ // }
|
|
|
|
+ // else{homingLow_done = 0 ;};//Serial.println("homing low failed");}
|
|
|
|
+ // push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
|
+ // push(connectors, ON_ONHOMINGLOW, 0, _currentStep, homingLow_done);
|
|
|
|
+ // trigger(EVT_EMERGENCY_STOP);
|
|
return;
|
|
return;
|
|
case ENT_HOMING_HIGH:
|
|
case ENT_HOMING_HIGH:
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
@@ -215,28 +258,52 @@ void Atm_AccelStepper::action( int id ) {
|
|
runMode = 1;
|
|
runMode = 1;
|
|
//_isHoming = 2 ;
|
|
//_isHoming = 2 ;
|
|
stepper->setSpeed(homing_speed);
|
|
stepper->setSpeed(homing_speed);
|
|
|
|
+ position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
return;
|
|
return;
|
|
case LP_HOMING_HIGH:
|
|
case LP_HOMING_HIGH:
|
|
stepper_update();
|
|
stepper_update();
|
|
- // push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
|
- return;
|
|
|
|
- case EXT_HOMING_HIGH:
|
|
|
|
|
|
+ //if (changed && (limitHigh_State||limitLow_State)){
|
|
|
|
+ if(limitHigh_State) {
|
|
|
|
+ _maxStep = stepper->currentPosition();
|
|
|
|
+ _currentStep = _maxStep;
|
|
|
|
+
|
|
|
|
+ homingHigh_done = 1;
|
|
|
|
+ runMode = 0 ;
|
|
|
|
+ trigger(EVT_EMERGENCY_STOP);
|
|
|
|
+ push(connectors, ON_ONHOMINGHIGH, 0, _currentStep, homingHigh_done);
|
|
|
|
+ //Serial.println("homing high done");
|
|
|
|
+ }
|
|
|
|
+ else if (changed && limitLow_State){
|
|
|
|
+ homingHigh_done = 0;
|
|
|
|
+ runMode = 0 ;
|
|
|
|
+ trigger(EVT_EMERGENCY_STOP);
|
|
|
|
+ push(connectors, ON_ONHOMINGHIGH, 0, _currentStep, homingHigh_done);
|
|
|
|
+ }//Serial.println("homing high failed");}
|
|
|
|
+ // push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
|
|
|
- runMode = 0;
|
|
|
|
- //_isHoming = 0;
|
|
|
|
- if(last_trigger == EVT_ON_LIMIT_HIGH) {
|
|
|
|
- _maxStep = stepper->currentPosition();
|
|
|
|
- _currentStep = _maxStep;
|
|
|
|
|
|
|
|
- homingHigh_done = 1;
|
|
|
|
- //Serial.println("homing high done");
|
|
|
|
- }
|
|
|
|
- else{homingHigh_done = 0;};//Serial.println("homing high failed");}
|
|
|
|
- push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
|
- //_targetStep = _currentStep;
|
|
|
|
- push(connectors, ON_ONHOMINGHIGH, 0, _currentStep, homingHigh_done);
|
|
|
|
- trigger(EVT_EMERGENCY_STOP);
|
|
|
|
|
|
+ //stepper_update();
|
|
|
|
+
|
|
|
|
+ //}
|
|
|
|
+ // push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
return;
|
|
return;
|
|
|
|
+ case EXT_HOMING_HIGH:
|
|
|
|
+ //
|
|
|
|
+ // runMode = 0;
|
|
|
|
+ // //_isHoming = 0;
|
|
|
|
+ // if(last_trigger == EVT_ON_LIMIT_HIGH) {
|
|
|
|
+ // _maxStep = stepper->currentPosition();
|
|
|
|
+ // _currentStep = _maxStep;
|
|
|
|
+ //
|
|
|
|
+ // homingHigh_done = 1;
|
|
|
|
+ // //Serial.println("homing high done");
|
|
|
|
+ // }
|
|
|
|
+ // else{homingHigh_done = 0;};//Serial.println("homing high failed");}
|
|
|
|
+ // push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
|
+ // //_targetStep = _currentStep;
|
|
|
|
+ // push(connectors, ON_ONHOMINGHIGH, 0, _currentStep, homingHigh_done);
|
|
|
|
+ // trigger(EVT_EMERGENCY_STOP);
|
|
|
|
+ // return;
|
|
case ENT_LIMIT_LOW:
|
|
case ENT_LIMIT_LOW:
|
|
/*triggered by a change in limit state
|
|
/*triggered by a change in limit state
|
|
if state is 0, we may leave this state for running
|
|
if state is 0, we may leave this state for running
|
|
@@ -422,11 +489,11 @@ int Atm_AccelStepper::limitLow_avg(bool limistate){
|
|
} else {
|
|
} else {
|
|
limitLow_buf_head++;
|
|
limitLow_buf_head++;
|
|
}
|
|
}
|
|
- for (int i =0; i<limit_buf_size; i++){
|
|
|
|
- Serial.print(limitLow_state_buf[i]);
|
|
|
|
- Serial.print(" ");
|
|
|
|
- }
|
|
|
|
- Serial.println();
|
|
|
|
|
|
+ // for (int i =0; i<limit_buf_size; i++){
|
|
|
|
+ // Serial.print(limitLow_state_buf[i]);
|
|
|
|
+ // Serial.print(" ");
|
|
|
|
+ // }
|
|
|
|
+ // Serial.println();
|
|
return limitLow_state_total > limit_buf_size / 2; //all values should agree
|
|
return limitLow_state_total > limit_buf_size / 2; //all values should agree
|
|
}
|
|
}
|
|
|
|
|