|
@@ -80,7 +80,7 @@ int Atm_AccelStepper::event( int id ) {
|
|
|
return limitHigh_State;
|
|
|
}
|
|
|
case EVT_ON_TARGET:
|
|
|
- return _currentStep == _targetStep;
|
|
|
+ return runMode ? 0 : _currentStep == _targetStep;
|
|
|
case EVT_HOMING_LOW:
|
|
|
return 0;
|
|
|
case EVT_HOMING_HIGH:
|
|
@@ -109,14 +109,17 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
digitalWrite(_enablePin, enabled);
|
|
|
return;
|
|
|
case ENT_ENABLED:
|
|
|
+ _isHoming = 0 ;
|
|
|
+ if(last_trigger == EVT_ON_TARGET){push( connectors, ON_ONTARGET, 0, _currentStep, 0 );};
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
enabled = _enableReversed ? LOW : HIGH ;
|
|
|
digitalWrite(_enablePin, enabled);
|
|
|
- if(last_trigger == EVT_ON_TARGET){push( connectors, ON_ONTARGET, 0, stepper->currentPosition(), 0 );};
|
|
|
+
|
|
|
|
|
|
return;
|
|
|
case ENT_RUNNING:
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
+ _isHoming = 0;
|
|
|
//push(connectors, ON_CHANGEPOSITION, 0, _currentStep, stepper->speed());
|
|
|
position_timer.setFromNow(this, POSITION_SEND_TIMER);
|
|
|
return;
|
|
@@ -126,6 +129,7 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
case ENT_STOP:
|
|
|
push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
if (last_trigger == EVT_STOP) {
|
|
|
+ runMode = 0 ;
|
|
|
stepper->stop();
|
|
|
_targetStep = stepper->targetPosition();
|
|
|
push( connectors, ON_STOP, 0, 0, 0 );
|
|
@@ -143,7 +147,9 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
_currentStep = stepper->currentPosition();
|
|
|
return;
|
|
|
case ENT_HOMING_LOW:
|
|
|
+ push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
runMode = 1;
|
|
|
+ _isHoming = 1 ;
|
|
|
stepper->setSpeed(-1*homing_speed);
|
|
|
return;
|
|
|
case LP_HOMING_LOW:
|
|
@@ -156,10 +162,13 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
Serial.println("homing low done");
|
|
|
}
|
|
|
else{Serial.println("homing low failed");}
|
|
|
+ _targetStep = _currentStep;
|
|
|
|
|
|
return;
|
|
|
case ENT_HOMING_HIGH:
|
|
|
+ push(connectors, ON_CHANGESTATE, 0, state(), 0);
|
|
|
runMode = 1;
|
|
|
+ _isHoming = 2 ;
|
|
|
stepper->setSpeed(homing_speed);
|
|
|
return;
|
|
|
case LP_HOMING_HIGH:
|
|
@@ -172,12 +181,15 @@ void Atm_AccelStepper::action( int id ) {
|
|
|
Serial.println("homing high done");
|
|
|
}
|
|
|
else{Serial.println("homing high failed");}
|
|
|
+ _targetStep = _currentStep;
|
|
|
return;
|
|
|
case ENT_LIMIT_LOW:
|
|
|
push( connectors, ON_ONLIMITLOW, 0, 0, 0 );
|
|
|
//stop motor if going down, allow going up
|
|
|
if(_limitLow_Hard && (stepper->speed()<0) ) {trigger(EVT_EMERGENCY_STOP);}
|
|
|
- else{stepper_update(); trigger(EVT_MOVE);}
|
|
|
+ else{
|
|
|
+ stepper_update();
|
|
|
+ switch(_isHoming) trigger.EVT_HOMINGtrigger(EVT_MOVE);}
|
|
|
return;
|
|
|
case ENT_LIMIT_HIGH:
|
|
|
push( connectors, ON_ONLIMITHIGH, 0, 1, 0 );
|
|
@@ -255,6 +267,7 @@ Atm_AccelStepper& Atm_AccelStepper::position_refresh(long int refresh_ms){
|
|
|
Atm_AccelStepper& Atm_AccelStepper::move( long int stepRel) {
|
|
|
_targetStep = _currentStep + stepRel;
|
|
|
runMode = 0;
|
|
|
+ _isHoming = 0;
|
|
|
//Serial.println(_targetStep);
|
|
|
stepper->moveTo(_targetStep);
|
|
|
enable();
|
|
@@ -264,6 +277,7 @@ Atm_AccelStepper& Atm_AccelStepper::move( long int stepRel) {
|
|
|
|
|
|
Atm_AccelStepper& Atm_AccelStepper::moveTo( long int stepAbs) {
|
|
|
_targetStep = stepAbs;
|
|
|
+ _isHoming = 0 ;
|
|
|
runMode = 0;
|
|
|
stepper->moveTo(_targetStep);
|
|
|
enable();
|
|
@@ -273,6 +287,7 @@ Atm_AccelStepper& Atm_AccelStepper::moveTo( long int stepAbs) {
|
|
|
|
|
|
Atm_AccelStepper& Atm_AccelStepper::rotate( long int speed) {
|
|
|
runMode = 1;
|
|
|
+ _isHoming = 0 ;
|
|
|
stepper->setSpeed( speed);
|
|
|
enable();
|
|
|
trigger( EVT_MOVE );
|
|
@@ -280,7 +295,11 @@ Atm_AccelStepper& Atm_AccelStepper::rotate( long int speed) {
|
|
|
}
|
|
|
|
|
|
Atm_AccelStepper& Atm_AccelStepper::homing( bool direction ){
|
|
|
+ enable();
|
|
|
+ direction == 1 ? _isHoming = 2 : _isHoming = 1;
|
|
|
direction == 1 ? this->trigger(EVT_HOMING_HIGH) : this->trigger(EVT_HOMING_LOW);
|
|
|
+
|
|
|
+ return *this;
|
|
|
}
|
|
|
|
|
|
// Atm_AccelStepper& Atm_AccelStepper::rotationReversed(bool reversed){
|