|
@@ -154,7 +154,7 @@ void Atm_AccelStepper::action( int id ) {
|
|
stepper_update();
|
|
stepper_update();
|
|
if(last_trigger == EVT_ON_TARGET){push( connectors, ON_ONTARGET, 0, _currentStep, 0 );};
|
|
if(last_trigger == EVT_ON_TARGET){push( connectors, ON_ONTARGET, 0, _currentStep, 0 );};
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 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 ;
|
|
enabled = _enableReversed ? LOW : HIGH ;
|
|
//reset limit state so that they trigger again if we're stopped on it
|
|
//reset limit state so that they trigger again if we're stopped on it
|
|
limitLow_State = 0;
|
|
limitLow_State = 0;
|
|
@@ -169,23 +169,30 @@ void Atm_AccelStepper::action( int id ) {
|
|
stepper->moveTo(_targetStep);
|
|
stepper->moveTo(_targetStep);
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
- stepper_update();
|
|
|
|
|
|
+ // stepper_update();
|
|
return;
|
|
return;
|
|
|
|
|
|
case LP_RUNNING:
|
|
case LP_RUNNING:
|
|
// if on limits and limits are hard, stop moving in one direction
|
|
// if on limits and limits are hard, stop moving in one direction
|
|
- if(limitLow_State && _limitLow_Hard && (stepper->speed()<0.)) {
|
|
|
|
|
|
+ if(limitLow_State && _limitLow_Hard && (_currentSpeed<0.)) {
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
|
|
|
|
}
|
|
}
|
|
- if(limitHigh_State && _limitHigh_Hard && ((stepper->speed()>0.))) {
|
|
|
|
|
|
+ if( limitHigh_State && _limitHigh_Hard && (_currentSpeed>0.)) {
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
}
|
|
}
|
|
|
|
+ // if hard limits and homing is done, check current position is within limits
|
|
|
|
+ if (_limitLow_Hard && homingLow_done) {
|
|
|
|
+ if( (_currentStep<0) && (_currentSpeed<0.)) {trigger(EVT_EMERGENCY_STOP);}
|
|
|
|
+ }
|
|
|
|
+ if (_limitHigh_Hard && _maxStep) { //maxstep is 0 if not defined
|
|
|
|
+ if( (_currentStep>_maxStep) && (_currentSpeed>0.)) {trigger(EVT_EMERGENCY_STOP);}
|
|
|
|
+ }
|
|
|
|
|
|
stepper_update();
|
|
stepper_update();
|
|
|
|
|
|
- if(runMode && stepper->speed() == 0.) {trigger(EVT_EMERGENCY_STOP);}//trigger(EVT_ON_TARGET);
|
|
|
|
- if(!runMode && stepper->distanceToGo() == 0){trigger(EVT_EMERGENCY_STOP);}
|
|
|
|
|
|
+ if(runMode && _currentSpeed == 0.) {trigger(EVT_EMERGENCY_STOP);}//trigger(EVT_ON_TARGET);
|
|
|
|
+ if(!runMode && (_currentStep==_targetStep)){trigger(EVT_EMERGENCY_STOP);}
|
|
return;
|
|
return;
|
|
|
|
|
|
case ENT_STOP:
|
|
case ENT_STOP:
|
|
@@ -214,19 +221,20 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
|
|
|
case LP_STOP:
|
|
case LP_STOP:
|
|
stepper_update();
|
|
stepper_update();
|
|
- if(stepper->speed() == 0.) {trigger(EVT_ENABLE);}
|
|
|
|
|
|
+ if(_currentSpeed == 0.) {trigger(EVT_ENABLE);}
|
|
return;
|
|
return;
|
|
|
|
|
|
case ENT_HOMING_LOW:
|
|
case ENT_HOMING_LOW:
|
|
homingLow_done = 0;
|
|
homingLow_done = 0;
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 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;
|
|
runMode = 1;
|
|
//_isHoming = 1 ;
|
|
//_isHoming = 1 ;
|
|
stepper->setSpeed(-1*homing_speed);
|
|
stepper->setSpeed(-1*homing_speed);
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
return;
|
|
return;
|
|
|
|
+
|
|
case LP_HOMING_LOW:
|
|
case LP_HOMING_LOW:
|
|
stepper_update();
|
|
stepper_update();
|
|
// if (changed && (limitHigh_State||limitLow_State)){
|
|
// if (changed && (limitHigh_State||limitLow_State)){
|
|
@@ -244,15 +252,8 @@ void Atm_AccelStepper::action( int id ) {
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
push(connectors, ON_ONHOMINGLOW, 0, _currentStep, homingLow_done);
|
|
push(connectors, ON_ONHOMINGLOW, 0, _currentStep, homingLow_done);
|
|
}//Serial.println("homing low failed");}
|
|
}//Serial.println("homing low failed");}
|
|
-
|
|
|
|
- // 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;
|
|
// runMode = 0;
|
|
// //_isHoming = 0;
|
|
// //_isHoming = 0;
|
|
@@ -266,15 +267,17 @@ void Atm_AccelStepper::action( int id ) {
|
|
// push(connectors, ON_ONHOMINGLOW, 0, _currentStep, homingLow_done);
|
|
// push(connectors, ON_ONHOMINGLOW, 0, _currentStep, homingLow_done);
|
|
// trigger(EVT_EMERGENCY_STOP);
|
|
// 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);
|
|
- push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
|
|
|
+ push(connectors, ON_CHANGEPOSITION, 0, _currentStep, _currentSpeed);
|
|
runMode = 1;
|
|
runMode = 1;
|
|
//_isHoming = 2 ;
|
|
//_isHoming = 2 ;
|
|
stepper->setSpeed(homing_speed);
|
|
stepper->setSpeed(homing_speed);
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
return;
|
|
return;
|
|
|
|
+
|
|
case LP_HOMING_HIGH:
|
|
case LP_HOMING_HIGH:
|
|
stepper_update();
|
|
stepper_update();
|
|
//if (changed && (limitHigh_State||limitLow_State)){
|
|
//if (changed && (limitHigh_State||limitLow_State)){
|
|
@@ -294,14 +297,8 @@ void Atm_AccelStepper::action( int id ) {
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
push(connectors, ON_ONHOMINGHIGH, 0, _currentStep, homingHigh_done);
|
|
push(connectors, ON_ONHOMINGHIGH, 0, _currentStep, homingHigh_done);
|
|
}//Serial.println("homing high failed");}
|
|
}//Serial.println("homing high failed");}
|
|
- // push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //stepper_update();
|
|
|
|
-
|
|
|
|
- //}
|
|
|
|
- // push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
|
return;
|
|
return;
|
|
|
|
+
|
|
case EXT_HOMING_HIGH:
|
|
case EXT_HOMING_HIGH:
|
|
//
|
|
//
|
|
// runMode = 0;
|
|
// runMode = 0;
|
|
@@ -319,6 +316,7 @@ void Atm_AccelStepper::action( int id ) {
|
|
// push(connectors, ON_ONHOMINGHIGH, 0, _currentStep, homingHigh_done);
|
|
// push(connectors, ON_ONHOMINGHIGH, 0, _currentStep, homingHigh_done);
|
|
// trigger(EVT_EMERGENCY_STOP);
|
|
// trigger(EVT_EMERGENCY_STOP);
|
|
// return;
|
|
// 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
|
|
@@ -326,7 +324,7 @@ void Atm_AccelStepper::action( int id ) {
|
|
the free direction, until a trigger comes with state 0
|
|
the free direction, until a trigger comes with state 0
|
|
*/
|
|
*/
|
|
push( connectors, ON_ONLIMITLOW, 0, limitLow_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);}
|
|
if (!limitLow_State){trigger(EVT_MOVE);}
|
|
return;
|
|
return;
|
|
|
|
|
|
@@ -344,15 +342,17 @@ void Atm_AccelStepper::action( int id ) {
|
|
stepper_update();
|
|
stepper_update();
|
|
//else{} // _isHoming ? trigger(EVT_STOP):
|
|
//else{} // _isHoming ? trigger(EVT_STOP):
|
|
return;
|
|
return;
|
|
|
|
+
|
|
case ENT_LIMIT_HIGH:
|
|
case ENT_LIMIT_HIGH:
|
|
push( connectors, ON_ONLIMITHIGH, 0, limitHigh_State, 0 );
|
|
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);};
|
|
if (!limitHigh_State){trigger(EVT_MOVE);};
|
|
return;
|
|
return;
|
|
|
|
+
|
|
case LP_LIMIT_HIGH:
|
|
case LP_LIMIT_HIGH:
|
|
//stop motor if going down, allow going up
|
|
//stop motor if going down, allow going up
|
|
|
|
|
|
- if(_limitHigh_Hard && ((stepper->speed()>0.))) {
|
|
|
|
|
|
+ if(_limitHigh_Hard && (_currentSpeed>0.)) {
|
|
// Serial.println("youpi");
|
|
// Serial.println("youpi");
|
|
_currentStep = stepper->currentPosition();
|
|
_currentStep = stepper->currentPosition();
|
|
stepper->moveTo(_currentStep);
|
|
stepper->moveTo(_currentStep);
|
|
@@ -400,19 +400,23 @@ void Atm_AccelStepper::stepper_update(void) {
|
|
stepper->runSpeed();
|
|
stepper->runSpeed();
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
- // Serial.print("update ");
|
|
|
|
- // Serial.println(stepper->speed());
|
|
|
|
|
|
+ _currentSpeed = stepper->speed();
|
|
long int tempStep = stepper->currentPosition();
|
|
long int tempStep = stepper->currentPosition();
|
|
if (tempStep != _currentStep){
|
|
if (tempStep != _currentStep){
|
|
_currentStep = tempStep;
|
|
_currentStep = tempStep;
|
|
//Serial.println(stepper->currentPosition());
|
|
//Serial.println(stepper->currentPosition());
|
|
if (position_timer.expired(this)){
|
|
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);
|
|
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){
|
|
Atm_AccelStepper& Atm_AccelStepper::setMaxSpeed( long int maxSpeed){
|
|
max_speed = maxSpeed ;
|
|
max_speed = maxSpeed ;
|
|
stepper->setMaxSpeed(max_speed);
|
|
stepper->setMaxSpeed(max_speed);
|
|
@@ -483,6 +487,7 @@ Atm_AccelStepper& Atm_AccelStepper::rotate( long int speed) {
|
|
runMode = 1;
|
|
runMode = 1;
|
|
// _isHoming = 0 ;
|
|
// _isHoming = 0 ;
|
|
stepper->setSpeed( speed);
|
|
stepper->setSpeed( speed);
|
|
|
|
+ stepper->runSpeed();
|
|
enable();
|
|
enable();
|
|
trigger( EVT_MOVE );
|
|
trigger( EVT_MOVE );
|
|
return *this;
|
|
return *this;
|