Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop the stepper motor immediately #17

Open
Portia-Lin opened this issue Sep 2, 2022 · 4 comments
Open

Stop the stepper motor immediately #17

Portia-Lin opened this issue Sep 2, 2022 · 4 comments

Comments

@Portia-Lin
Copy link

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
Copy link

DougF42 commented Dec 20, 2023

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.

@lightzero
Copy link

create new fucntion estop()
void AccelStepper::eStop() { _speed=0.0; _targetPos=_currentPos; }

@DougF42
Copy link

DougF42 commented Oct 9, 2024

@lightzero - I like your approach - it is much cleaner than my work-around. The estop() function will need one minor addition - also set _stepInterval=0. This will cause runspeed() to return false immediately, (properly indicating no motion) instead of doing another step (if the step interval has elapsed).

Resulting function:
void AccelStepper::eStop() { _speed=0.0; _targetPos=_currentPos; _stepInterval=0 }

@lightzero
Copy link

lightzero commented Oct 10, 2024

if set _stepInterval=0;the stepper motor starts moving at maximum speed without using acceleration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants