Browse Source

added moves relative to maxStep

allow positionning in percentage of maxstep
titi 5 years ago
parent
commit
4eb7df7f5e
2 changed files with 27 additions and 2 deletions
  1. 23 0
      Atm_AccelStepper.cpp
  2. 4 2
      Atm_AccelStepper.h

+ 23 - 0
Atm_AccelStepper.cpp

@@ -483,6 +483,29 @@ Atm_AccelStepper& Atm_AccelStepper::moveTo( long int stepAbs) {
   return *this;
 }
 
+Atm_AccelStepper& Atm_AccelStepper::movePercent( float percent) {
+  constrain(percent, -1., 1.);
+  _targetStep   = _currentStep + percent*_maxStep;
+  runMode = 0;
+  // _isHoming = 0;
+  //Serial.println(_targetStep);
+  stepper->moveTo(_targetStep);
+  enable();
+  trigger( EVT_MOVE );
+  return *this;
+}
+
+Atm_AccelStepper& Atm_AccelStepper::moveToPercent( float percent) {
+  constrain(percent, 0., 1.);
+  _targetStep   = percent*_maxStep;
+  // _isHoming = 0 ;
+  runMode = 0;
+  stepper->moveTo(_targetStep);
+  enable();
+  trigger( EVT_MOVE );
+  return *this;
+}
+
 Atm_AccelStepper& Atm_AccelStepper::rotate( long  int speed) {
   runMode = 1;
   // _isHoming = 0 ;

+ 4 - 2
Atm_AccelStepper.h

@@ -57,8 +57,10 @@ class Atm_AccelStepper: public Machine {
   bool isRunning();
   float getSpeed();
 
-  Atm_AccelStepper& move(long int stepRel );
-  Atm_AccelStepper& moveTo(long int stepAbs );
+  Atm_AccelStepper& move(long int stepRel);
+  Atm_AccelStepper& moveTo(long int stepAbs);
+  Atm_AccelStepper& movePercent(float percent);
+  Atm_AccelStepper& moveToPercent(float percent);
   Atm_AccelStepper& rotate(long int speed );
   Atm_AccelStepper& homing( bool direction );
   int runMode = 0; // 0 uses run() for positioning, 1 uses runSpeed() for constant speed