pkerspe / ESP-FlexyStepper

This library is used to control one or more stepper motors from an ESP32 device. It is based on the FlexyStepper library by S.Reifel but provides some additional functionality
MIT License
150 stars 32 forks source link

SetSpeed(0) doesnt stop the motor #21

Closed dansoskin closed 3 years ago

dansoskin commented 3 years ago

hey, id like to use jog functions and change speed on the go, but setting the speed to 0 doesnt stop the motor and it keeps spinning slowly

pkerspe commented 3 years ago

Did you try setting the distance/target to zero?

pkerspe commented 3 years ago

Since you also stated you use the jogging function, did you actually call the stopJogging() function?

dansoskin commented 3 years ago

I want to perform PID on the motor's speed, and I need the motor to stop when the PID output equals to 0

in the library, the setspeed command calculates the interval time by dividing: desiredPeriod_InUSPerStep = 1000000.0 / desiredSpeed_InStepsPerSecond; so it divides by zero

maybe theres some kind of quick fix to make the motor stop when the setspeed(0) function is called? what is the lowest speed possible by the library?

pkerspe commented 3 years ago

Just call stopJogging function instead of setting speed to zero. Should be a very simple if/else statement in your code. As you mentioned already there will be a divide by zero issue when you use an invalid speed value. Also the reason for the slow movement you are expecting might be due to rounding issues in the stepping speed calculation routine. The library simply considers traveling with a speed of zero, as a non valid speed requirement. Thus, to stop the motion, there are explicit functions (like stopJogging) that should do the trick

dansoskin commented 3 years ago

alrighty, thanks for the quick response