|
@@ -4,7 +4,7 @@
|
|
* Add extra initialization code
|
|
* Add extra initialization code
|
|
*/
|
|
*/
|
|
|
|
|
|
-Atm_TeensyStep& Atm_TeensyStep::begin(Stepper & motorRef) {
|
|
|
|
|
|
+Atm_TeensyStep& Atm_TeensyStep::begin(Stepper & motorRef, StepControl & stepControlRef) {
|
|
// clang-format off
|
|
// clang-format off
|
|
const static state_t state_table[] PROGMEM = {
|
|
const static state_t state_table[] PROGMEM = {
|
|
/* ON_ENTER ON_LOOP ON_EXIT EVT_IDLE_TIMER EVT_ON_TARGET EVT_GOTO ELSE */
|
|
/* ON_ENTER ON_LOOP ON_EXIT EVT_IDLE_TIMER EVT_ON_TARGET EVT_GOTO ELSE */
|
|
@@ -17,6 +17,7 @@ Atm_TeensyStep& Atm_TeensyStep::begin(Stepper & motorRef) {
|
|
Machine::begin( state_table, ELSE );
|
|
Machine::begin( state_table, ELSE );
|
|
// AccelStepper _motor (1, stepPin, dirPin);
|
|
// AccelStepper _motor (1, stepPin, dirPin);
|
|
this-> motor = &motorRef;
|
|
this-> motor = &motorRef;
|
|
|
|
+ this-> controller = &stepControlRef;
|
|
// Stepper _motor(stepPin, dirPin );
|
|
// Stepper _motor(stepPin, dirPin );
|
|
// StepControl _controller;
|
|
// StepControl _controller;
|
|
// _motor.setMaxSpeed(20000);
|
|
// _motor.setMaxSpeed(20000);
|
|
@@ -36,7 +37,8 @@ int Atm_TeensyStep::event( int id ) {
|
|
case EVT_IDLE_TIMER:
|
|
case EVT_IDLE_TIMER:
|
|
return 0;
|
|
return 0;
|
|
case EVT_ON_TARGET:
|
|
case EVT_ON_TARGET:
|
|
- return 0;
|
|
|
|
|
|
+ //motor->get(targetStep);
|
|
|
|
+ return _currentStep == _targetStep ;
|
|
// return _motor.distanceToGo()== 0 ;
|
|
// return _motor.distanceToGo()== 0 ;
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
@@ -59,11 +61,13 @@ void Atm_TeensyStep::action( int id ) {
|
|
return;
|
|
return;
|
|
case ENT_RUNNING:
|
|
case ENT_RUNNING:
|
|
digitalWrite(0, HIGH);
|
|
digitalWrite(0, HIGH);
|
|
|
|
+
|
|
// _controller.moveAsync(*_motor);
|
|
// _controller.moveAsync(*_motor);
|
|
return;
|
|
return;
|
|
case LP_RUNNING:
|
|
case LP_RUNNING:
|
|
// _motor.run();
|
|
// _motor.run();
|
|
-
|
|
|
|
|
|
+ _currentStep = motor->getPosition();
|
|
|
|
+
|
|
// Serial.println(_motor.currentPosition());
|
|
// Serial.println(_motor.currentPosition());
|
|
return;
|
|
return;
|
|
case ENT_STOPPING:
|
|
case ENT_STOPPING:
|
|
@@ -99,7 +103,9 @@ int Atm_TeensyStep::state( void ) {
|
|
*/
|
|
*/
|
|
|
|
|
|
Atm_TeensyStep& Atm_TeensyStep::gotoStep(long int targetStep ) {
|
|
Atm_TeensyStep& Atm_TeensyStep::gotoStep(long int targetStep ) {
|
|
- motor->setTargetRel(targetStep);
|
|
|
|
|
|
+ _targetStep = targetStep;
|
|
|
|
+ motor->setTargetRel(_targetStep);
|
|
|
|
+ controller->moveAsync(*motor);
|
|
|
|
|
|
// _motor.move(targetStep);
|
|
// _motor.move(targetStep);
|
|
// _motor.run();
|
|
// _motor.run();
|