gin66 / FastAccelStepper

A high speed stepper library for Atmega 168/328p (nano), Atmega32u4, Atmega 2560, ESP32, ESP32S2, ESP32S3, ESP32C3 and Atmel SAM Due
MIT License
286 stars 67 forks source link

Different acceleration and deceleration #118

Closed ninamercedez closed 2 years ago

ninamercedez commented 2 years ago

Is there a possibility to have a different acceleration and deceleration in one movement. e.g. moving 100 mm with an acceleration of 3000 mm/s² and decelerate with 10000 mm/s² ?

gin66 commented 2 years ago

The current ramp generator does not support this. Eventually there will be a new one, which can support this feature, but there is no plan to start on implementation in the coming weeks.

From application side, you can try this approach:

void loop() {
   if (!stepper->isRunning()) {
      stepper->setSpeed(500);
      stepper->setAcceleration(3000);
      stepper->moveTo(10000 - stepper->getCurrentPosition());
   }
   if ((stepper->rampState() & RAMP_STATE_MASK) == RAMP_STATE_COAST) {
       stepper->setAcceleration(10000);
       stepper->applySpeedAcceleration();
   }
}

Hope this compiles. The stepper will run back and forth between position 0 and 10000. If in your app, the ramp does not reach the max. speed, then the proposed code will not be able to set the deceleration value.