waspinator / AccelStepper

Fork of AccelStepper
http://www.airspayce.com/mikem/arduino/AccelStepper/
Other
146 stars 86 forks source link

Stop the stepper motor immediately #17

Open Portia-Lin opened 2 years ago

Portia-Lin commented 2 years ago

Hello everyone. I would like to stop the stepper motor immediately after the limit switch has been triggered. If I call the stop() function, the stepper motor starts to decrease its speed depending on the given acceleration. I need to stop the stepper motor now, so I use the code: if (stepper.isRunning()) { stepper.moveTo(stepper.currentPosition()); } It works. But there is a problem. After I set another position to move again, the stepper motor starts moving at maximum speed without using acceleration. This may cause the stepper motor in my device to jam. Are there any other solutions to this problem? To set the movement speed, I use the setMaxSpeed() functions, and for the stepper motor movement: run().

DougF42 commented 8 months ago

A temporary solution: Derive a subclass from AccelStepper, (1) override the 'run' function, adding a test for a new 'estopTriggered' flag. IF the flag is not set, then call AccelStepper::run().
(2) create new fucntion estop() that sets this flag, AND sets _stepInterval to 0. (3) Create new function reset_estop() that clears the flag to restore normal operations.