|
@@ -154,7 +154,7 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
stepper_update();
|
|
|
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());
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, _currentSpeed);
|
|
|
enabled = _enableReversed ? LOW : HIGH ;
|
|
|
|
|
|
limitLow_State = 0;
|
|
@@ -169,23 +169,30 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
stepper->moveTo(_targetStep);
|
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
|
- stepper_update();
|
|
|
+
|
|
|
return;
|
|
|
|
|
|
case LP_RUNNING:
|
|
|
|
|
|
- if(limitLow_State && _limitLow_Hard && (stepper->speed()<0.)) {
|
|
|
+ if(limitLow_State && _limitLow_Hard && (_currentSpeed<0.)) {
|
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
|
|
|
|
}
|
|
|
- if(limitHigh_State && _limitHigh_Hard && ((stepper->speed()>0.))) {
|
|
|
+ if( limitHigh_State && _limitHigh_Hard && (_currentSpeed>0.)) {
|
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
|
}
|
|
|
+
|
|
|
+ if (_limitLow_Hard && homingLow_done) {
|
|
|
+ if( (_currentStep<0) && (_currentSpeed<0.)) {trigger(EVT_EMERGENCY_STOP);}
|
|
|
+ }
|
|
|
+ if (_limitHigh_Hard && _maxStep) {
|
|
|
+ if( (_currentStep>_maxStep) && (_currentSpeed>0.)) {trigger(EVT_EMERGENCY_STOP);}
|
|
|
+ }
|
|
|
|
|
|
stepper_update();
|
|
|
|
|
|
- if(runMode && stepper->speed() == 0.) {trigger(EVT_EMERGENCY_STOP);}
|
|
|
- if(!runMode && stepper->distanceToGo() == 0){trigger(EVT_EMERGENCY_STOP);}
|
|
|
+ if(runMode && _currentSpeed == 0.) {trigger(EVT_EMERGENCY_STOP);}
|
|
|
+ if(!runMode && (_currentStep==_targetStep)){trigger(EVT_EMERGENCY_STOP);}
|
|
|
return;
|
|
|
|
|
|
case ENT_STOP:
|
|
@@ -214,19 +221,20 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
|
|
|
case LP_STOP:
|
|
|
stepper_update();
|
|
|
- if(stepper->speed() == 0.) {trigger(EVT_ENABLE);}
|
|
|
+ if(_currentSpeed == 0.) {trigger(EVT_ENABLE);}
|
|
|
return;
|
|
|
|
|
|
case ENT_HOMING_LOW:
|
|
|
homingLow_done = 0;
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
- push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, _currentSpeed);
|
|
|
runMode = 1;
|
|
|
|
|
|
stepper->setSpeed(-1*homing_speed);
|
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
|
return;
|
|
|
+
|
|
|
case LP_HOMING_LOW:
|
|
|
stepper_update();
|
|
|
|
|
@@ -244,15 +252,8 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
|
push(connectors, ON_ONHOMINGLOW, 0, _currentStep, homingLow_done);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return;
|
|
|
+
|
|
|
case EXT_HOMING_LOW:
|
|
|
|
|
|
|
|
@@ -266,15 +267,17 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
|
|
|
|
|
|
return;
|
|
|
+
|
|
|
case ENT_HOMING_HIGH:
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
- push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, _currentSpeed);
|
|
|
runMode = 1;
|
|
|
|
|
|
stepper->setSpeed(homing_speed);
|
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
|
return;
|
|
|
+
|
|
|
case LP_HOMING_HIGH:
|
|
|
stepper_update();
|
|
|
|
|
@@ -294,14 +297,8 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
|
push(connectors, ON_ONHOMINGHIGH, 0, _currentStep, homingHigh_done);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return;
|
|
|
+
|
|
|
case EXT_HOMING_HIGH:
|
|
|
|
|
|
|
|
@@ -319,6 +316,7 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
case ENT_LIMIT_LOW:
|
|
|
|
|
|
if state is 0, we may leave this state for running
|
|
@@ -326,7 +324,7 @@ 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());
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, _currentSpeed);
|
|
|
if (!limitLow_State){trigger(EVT_MOVE);}
|
|
|
return;
|
|
|
|
|
@@ -344,15 +342,17 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
stepper_update();
|
|
|
|
|
|
return;
|
|
|
+
|
|
|
case ENT_LIMIT_HIGH:
|
|
|
push( connectors, ON_ONLIMITHIGH, 0, limitHigh_State, 0 );
|
|
|
- push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, _currentSpeed);
|
|
|
if (!limitHigh_State){trigger(EVT_MOVE);};
|
|
|
return;
|
|
|
+
|
|
|
case LP_LIMIT_HIGH:
|
|
|
|
|
|
|
|
|
- if(_limitHigh_Hard && ((stepper->speed()>0.))) {
|
|
|
+ if(_limitHigh_Hard && (_currentSpeed>0.)) {
|
|
|
|
|
|
_currentStep = stepper->currentPosition();
|
|
|
stepper->moveTo(_currentStep);
|
|
@@ -400,19 +400,23 @@ void Atm_AccelStepper::stepper_update(void) {
|
|
|
stepper->runSpeed();
|
|
|
break;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ _currentSpeed = stepper->speed();
|
|
|
long int tempStep = stepper->currentPosition();
|
|
|
if (tempStep != _currentStep){
|
|
|
_currentStep = tempStep;
|
|
|
|
|
|
if (position_timer.expired(this)){
|
|
|
- push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, _currentSpeed);
|
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+Atm_AccelStepper& Atm_AccelStepper::setMaxStep( long int maxStep ) {
|
|
|
+ _maxStep = maxStep;
|
|
|
+ return *this ;
|
|
|
+}
|
|
|
+
|
|
|
Atm_AccelStepper& Atm_AccelStepper::setMaxSpeed( long int maxSpeed){
|
|
|
max_speed = maxSpeed ;
|
|
|
stepper->setMaxSpeed(max_speed);
|
|
@@ -483,6 +487,7 @@ Atm_AccelStepper& Atm_AccelStepper::rotate( long int speed) {
|
|
|
runMode = 1;
|
|
|
|
|
|
stepper->setSpeed( speed);
|
|
|
+ stepper->runSpeed();
|
|
|
enable();
|
|
|
trigger( EVT_MOVE );
|
|
|
return *this;
|