|
@@ -165,11 +165,11 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
|
|
|
case ENT_RUNNING:
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
-
|
|
|
- stepper->moveTo(_targetStep);
|
|
|
+ if (last_trigger!=EVT_ON_LIMIT_LOW && last_trigger!=EVT_ON_LIMIT_HIGH){compensatePlay(_currentSpeed);}
|
|
|
+ if (runMode){stepper->setSpeed( _currentSpeed);}
|
|
|
+ else{stepper->moveTo(_targetStep);}
|
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
|
-
|
|
|
return;
|
|
|
|
|
|
case LP_RUNNING:
|
|
@@ -229,7 +229,8 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
push(connectors, ON_CHANGEPOSITION, 0, _currentStep, _currentSpeed);
|
|
|
runMode = 1;
|
|
|
-
|
|
|
+ _currentSpeed = -1*homing_speed;
|
|
|
+ if (last_trigger!=EVT_ON_LIMIT_LOW && last_trigger!=EVT_ON_LIMIT_HIGH){compensatePlay(_currentSpeed);}
|
|
|
stepper->setSpeed(-1*homing_speed);
|
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
@@ -237,7 +238,6 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
|
|
|
case LP_HOMING_LOW:
|
|
|
stepper_update();
|
|
|
-
|
|
|
if(limitLow_State) {
|
|
|
stepper->setCurrentPosition(0);
|
|
|
_currentStep = 0;
|
|
@@ -251,28 +251,18 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
runMode = 0;
|
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
|
push(connectors, ON_ONHOMINGLOW, 0, _currentStep, homingLow_done);
|
|
|
- }
|
|
|
+ }
|
|
|
return;
|
|
|
|
|
|
case EXT_HOMING_LOW:
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return;
|
|
|
|
|
|
case ENT_HOMING_HIGH:
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
push(connectors, ON_CHANGEPOSITION, 0, _currentStep, _currentSpeed);
|
|
|
runMode = 1;
|
|
|
-
|
|
|
+ _currentSpeed = homing_speed;
|
|
|
+ if (last_trigger!=EVT_ON_LIMIT_LOW && last_trigger!=EVT_ON_LIMIT_HIGH){compensatePlay(_currentSpeed);}
|
|
|
stepper->setSpeed(homing_speed);
|
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
|
limits_timer.setFromNow(this, LIMIT_UPDATE_RATE);
|
|
@@ -280,7 +270,6 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
|
|
|
case LP_HOMING_HIGH:
|
|
|
stepper_update();
|
|
|
-
|
|
|
if(limitHigh_State) {
|
|
|
_maxStep = stepper->currentPosition();
|
|
|
_currentStep = _maxStep;
|
|
@@ -289,33 +278,17 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
runMode = 0 ;
|
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
|
push(connectors, ON_ONHOMINGHIGH, 0, _currentStep, homingHigh_done);
|
|
|
-
|
|
|
}
|
|
|
else if (changed && limitLow_State ){
|
|
|
homingHigh_done = 0;
|
|
|
runMode = 0 ;
|
|
|
trigger(EVT_EMERGENCY_STOP);
|
|
|
push(connectors, ON_ONHOMINGHIGH, 0, _currentStep, homingHigh_done);
|
|
|
- }
|
|
|
+ }
|
|
|
return;
|
|
|
|
|
|
case EXT_HOMING_HIGH:
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ return;
|
|
|
|
|
|
case ENT_LIMIT_LOW:
|
|
|
|
|
@@ -445,7 +418,7 @@ Atm_AccelStepper& Atm_AccelStepper::setPlayCompensation(long int steps){
|
|
|
playSteps = steps ;
|
|
|
}
|
|
|
|
|
|
-bool Atm_AccelStepper::compensatePlay(){
|
|
|
+bool Atm_AccelStepper::compensatePlay(int speed){
|
|
|
|
|
|
bool newDirection ;
|
|
|
switch (runMode) {
|
|
@@ -453,14 +426,14 @@ bool Atm_AccelStepper::compensatePlay(){
|
|
|
newDirection = _targetStep > _currentStep;
|
|
|
break;
|
|
|
case 1:
|
|
|
- newDirection = stepper->speed()>0;
|
|
|
+ newDirection = speed>0;
|
|
|
break;
|
|
|
}
|
|
|
if (direction != newDirection){
|
|
|
long int compensation = newDirection ? -playSteps : playSteps ;
|
|
|
setPosition(_currentStep + compensation);
|
|
|
Serial.print("play compensation ");
|
|
|
- Serial.println(_currentStep);
|
|
|
+ Serial.println(compensation);
|
|
|
return 1;
|
|
|
}
|
|
|
else{return 0;}
|
|
@@ -490,10 +463,7 @@ Atm_AccelStepper& Atm_AccelStepper::position_refresh(long int refresh_ms){
|
|
|
|
|
|
Atm_AccelStepper& Atm_AccelStepper::move( long int stepRel) {
|
|
|
_targetStep = _currentStep + stepRel;
|
|
|
- if(playSteps){compensatePlay();}
|
|
|
runMode = 0;
|
|
|
-
|
|
|
-
|
|
|
stepper->moveTo(_targetStep);
|
|
|
enable();
|
|
|
trigger( EVT_MOVE );
|
|
@@ -502,8 +472,6 @@ Atm_AccelStepper& Atm_AccelStepper::move( long int stepRel) {
|
|
|
|
|
|
Atm_AccelStepper& Atm_AccelStepper::moveTo( long int stepAbs) {
|
|
|
_targetStep = stepAbs;
|
|
|
- if(playSteps){compensatePlay();}
|
|
|
-
|
|
|
runMode = 0;
|
|
|
stepper->moveTo(_targetStep);
|
|
|
enable();
|
|
@@ -512,13 +480,9 @@ Atm_AccelStepper& Atm_AccelStepper::moveTo( long int stepAbs) {
|
|
|
}
|
|
|
|
|
|
Atm_AccelStepper& Atm_AccelStepper::movePercent( float percent) {
|
|
|
-
|
|
|
-
|
|
|
_targetStep = (float)_currentStep + percent/100.*float(_maxStep);
|
|
|
- if(playSteps){compensatePlay();}
|
|
|
runMode = 0;
|
|
|
-
|
|
|
- Serial.println(_targetStep);
|
|
|
+
|
|
|
stepper->moveTo(_targetStep);
|
|
|
enable();
|
|
|
trigger( EVT_MOVE );
|
|
@@ -527,8 +491,6 @@ Atm_AccelStepper& Atm_AccelStepper::movePercent( float percent) {
|
|
|
|
|
|
Atm_AccelStepper& Atm_AccelStepper::moveToPercent( float percent) {
|
|
|
_targetStep = (float) percent/100*float(_maxStep) ;
|
|
|
- if(playSteps){compensatePlay();}
|
|
|
-
|
|
|
runMode = 0;
|
|
|
stepper->moveTo(_targetStep);
|
|
|
enable();
|
|
@@ -538,10 +500,8 @@ Atm_AccelStepper& Atm_AccelStepper::moveToPercent( float percent) {
|
|
|
|
|
|
Atm_AccelStepper& Atm_AccelStepper::rotate( long int speed) {
|
|
|
runMode = 1;
|
|
|
-
|
|
|
+
|
|
|
stepper->setSpeed( speed);
|
|
|
- if(playSteps){compensatePlay();}
|
|
|
-
|
|
|
enable();
|
|
|
trigger( EVT_MOVE );
|
|
|
return *this;
|
|
@@ -549,9 +509,7 @@ Atm_AccelStepper& Atm_AccelStepper::rotate( long int speed) {
|
|
|
|
|
|
Atm_AccelStepper& Atm_AccelStepper::homing( bool homingDirection ){
|
|
|
enable();
|
|
|
-
|
|
|
homingDirection == 1 ? this->trigger(EVT_HOMING_HIGH) : this->trigger(EVT_HOMING_LOW);
|
|
|
-
|
|
|
return *this;
|
|
|
}
|
|
|
|
|
@@ -563,11 +521,6 @@ int Atm_AccelStepper::limitLow_avg(bool limistate){
|
|
|
} else {
|
|
|
limitLow_buf_head++;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
return limitLow_state_total > limit_buf_size / 2;
|
|
|
}
|
|
|
|
|
@@ -579,13 +532,9 @@ int Atm_AccelStepper::limitHigh_avg(bool limistate){
|
|
|
} else {
|
|
|
limitHigh_buf_head++;
|
|
|
}
|
|
|
-
|
|
|
return limitHigh_state_total > limit_buf_size / 2;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
|
|
|
Atm_AccelStepper& Atm_AccelStepper::setEnablePin( int enablePin ){
|
|
|
_enablePin = enablePin ;
|