|
@@ -115,6 +115,7 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
_isHoming = 0 ;
|
|
|
if(last_trigger == EVT_ON_TARGET){push( connectors, ON_ONTARGET, 0, _currentStep, 0 );};
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
enabled = _enableReversed ? LOW : HIGH ;
|
|
|
digitalWrite(_enablePin, enabled);
|
|
|
|
|
@@ -122,6 +123,7 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
return;
|
|
|
case ENT_RUNNING:
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
_isHoming = 0;
|
|
|
//reset limit state so that they trigger again if we're stopped on it
|
|
|
// limitLow_State = 0;
|
|
@@ -136,59 +138,69 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
return;
|
|
|
case LP_RUNNING:
|
|
|
stepper_update();
|
|
|
+ if(stepper->speed() == 0.) {trigger(EVT_ON_TARGET);}
|
|
|
return;
|
|
|
case ENT_STOP:
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
if (last_trigger == EVT_STOP) {
|
|
|
- runMode = 0 ;
|
|
|
+ // runMode = 0 ;
|
|
|
stepper->stop();
|
|
|
_targetStep = stepper->targetPosition();
|
|
|
push( connectors, ON_STOP, 0, 0, 0 );
|
|
|
}
|
|
|
if (last_trigger == EVT_EMERGENCY_STOP) {
|
|
|
+ stepper->setSpeed(0);
|
|
|
_currentStep = stepper->currentPosition();
|
|
|
_targetStep = _currentStep ;
|
|
|
stepper->moveTo(_targetStep);
|
|
|
- stepper->setSpeed(0);
|
|
|
push( connectors, ON_STOP, 0, 1, 0 );
|
|
|
}
|
|
|
return;
|
|
|
case LP_STOP:
|
|
|
stepper_update();
|
|
|
- _currentStep = stepper->currentPosition();
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
+ if(stepper->speed() == 0.) {trigger(EVT_ON_TARGET);}
|
|
|
+ // _currentStep = stepper->currentPosition();
|
|
|
return;
|
|
|
case ENT_HOMING_LOW:
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
runMode = 1;
|
|
|
_isHoming = 1 ;
|
|
|
stepper->setSpeed(-1*homing_speed);
|
|
|
return;
|
|
|
case LP_HOMING_LOW:
|
|
|
stepper_update();
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
return;
|
|
|
case EXT_HOMING_LOW:
|
|
|
runMode = 0;
|
|
|
_isHoming = 0;
|
|
|
- trigger(EVT_EMERGENCY_STOP);
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
if(last_trigger == EVT_ON_LIMIT_LOW) {
|
|
|
stepper->setCurrentPosition(0);
|
|
|
_currentStep = 0;
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
Serial.println("homing low done");
|
|
|
}
|
|
|
else{Serial.println("homing low failed");}
|
|
|
- _targetStep = _currentStep;
|
|
|
+ trigger(EVT_EMERGENCY_STOP);
|
|
|
|
|
|
return;
|
|
|
case ENT_HOMING_HIGH:
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
runMode = 1;
|
|
|
_isHoming = 2 ;
|
|
|
stepper->setSpeed(homing_speed);
|
|
|
return;
|
|
|
case LP_HOMING_HIGH:
|
|
|
stepper_update();
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
return;
|
|
|
case EXT_HOMING_HIGH:
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
runMode = 0;
|
|
|
_isHoming = 0;
|
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
@@ -207,35 +219,39 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
the free direction, until a trigger comes with state 0
|
|
|
*/
|
|
|
push( connectors, ON_ONLIMITLOW, 0, limitLow_State, 0 );
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
if (!limitLow_State){trigger(EVT_MOVE);}
|
|
|
return;
|
|
|
|
|
|
case LP_LIMIT_LOW:
|
|
|
//stop motor if going down, allow going up
|
|
|
- stepper_update();
|
|
|
+
|
|
|
if(_limitLow_Hard && (_targetStep < _currentStep)) {
|
|
|
// Serial.println("youpi");
|
|
|
_currentStep = stepper->currentPosition();
|
|
|
- //stepper->moveTo(_currentStep);
|
|
|
- //_targetStep = _currentStep;
|
|
|
+ stepper->moveTo(_currentStep);
|
|
|
+ _targetStep = _currentStep;
|
|
|
stepper->setSpeed(0);
|
|
|
}
|
|
|
+ stepper_update();
|
|
|
//else{} // _isHoming ? trigger(EVT_STOP):
|
|
|
return;
|
|
|
case ENT_LIMIT_HIGH:
|
|
|
push( connectors, ON_ONLIMITHIGH, 0, limitHigh_State, 0 );
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
if (!limitHigh_State){trigger(EVT_MOVE);};
|
|
|
return;
|
|
|
case LP_LIMIT_HIGH:
|
|
|
//stop motor if going down, allow going up
|
|
|
- stepper_update();
|
|
|
+
|
|
|
if(_limitHigh_Hard && (_targetStep > _currentStep)) {
|
|
|
// Serial.println("youpi");
|
|
|
_currentStep = stepper->currentPosition();
|
|
|
- //stepper->moveTo(_currentStep);
|
|
|
- //_targetStep = _currentStep;
|
|
|
+ stepper->moveTo(_currentStep);
|
|
|
+ _targetStep = _currentStep;
|
|
|
stepper->setSpeed(0);
|
|
|
}
|
|
|
+ stepper_update();
|
|
|
// else{}
|
|
|
return;
|
|
|
}
|