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
282 stars 67 forks source link

Linear acceleration only works on "speed 0" limits #223

Closed dakcantagalli closed 3 months ago

dakcantagalli commented 6 months ago

Hey guys.

Firstly, I would really like to thanks for the incredible work that was developed in this library!

I would like to share a strange behavior of the "setLinearAcceleration()" function. I expected that the linear variation in acceleration would occur with every change in speed, but it only occurs at the beginning and end of the movement. Below is a graph (speed x time) that I plotted. image

In RED the behavior I expected: image

If deceleration is initiated before reaching maximum speed, this is the behavior: image

In RED the behavior I expected: image

Am I doing something wrong or is this the expected behavior of this function?

gin66 commented 6 months ago

Good observation and the behavior like that is by design. As the doc states:

setLinearAcceleration expects as parameter the number of steps, where the acceleration is increased linearly from standstill up to the configured acceleration value. If this parameter is 0, then there will be no linear acceleration phase

The background is, that this implementation is quite straightforward. The math is described here. Add a linear acceleration increase phase for an already running stepper requires IMHO way more sophisticated math.

gin66 commented 3 months ago

stale