Hi,
On Saturday, 4 January 2025 15:04:54 AEST Jim Larson wrote:
> Try this to detect if movement is over.
> if (stepper.distanceToGo()==0) {
> // if no more steps to go, then movement is over
> stepper.disableOutputs();
> ...
>
> Also, it seems worth making Mike's suggest mod and trying it.
Im not sure thats sufficient, since its possible that the motor is still
decelerating on an overrun as it goes past the target, prior to reversing back
to the target.
Best to use isRunning(), or the return value from run() in order to tell if
the move is completely finished.
>
> -jim
>
> On Friday, January 3, 2025 at 2:47:34 PM UTC-8
gjgsm...@gmail.com wrote:
> > What about...
> > ```
> >
> > // 1. Enable outputs if not already
> >
> > stepper.enableOutputs();
> >
> > // 2. Set a new target, for example 1000 steps away
> > stepper.moveTo(1000);
> >
> > }
> >
> > // 3. Keep calling run() to step the motor. (Non-blocking)
> > stepper.run();
> >
> > // 4. Check if the motor has stopped
> > if (!stepper.isRunning()) {
> >
> > // If the motor is no longer running, disable coils
> > stepper.disableOutputs();
> >
> > ```
> >
> > This would be non-blocking but use a 'while()' instead of 'if()' for
> > blocking (Including stepper.run()).
> >
> > On Saturday, 4 January 2025 at 08:09:01 UTC+11
quil...@gmail.com wrote:
> >> I wish to disable the motor's power as soon as movement has finished. So
> >> I need some way of detecting when the deceleration phase has completed.
> >> After using *motor->stop()* I have tried a loop of
> >> * motor->run();*
> >> * if (!motor->isRunning() )*
> >> * motor->disableOutputs();*
> >> but this stops the motor immediately.
> >> If I just do this:
> >> * motor->stop();*
> >> * motor->disableOutputs();*
> >> then the motor stops but continues with the deceleration as soon as the
> >> motor is enabled again - when I want it to go in the other direction!
> >> How do I test for completed movements?
> >> Thanks for any help.
--
Mike McCauley VK4AMM
mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com 5R3MRFM2+X6
Phone
+61 7 5598-7474