FastAccelStepper icon indicating copy to clipboard operation
FastAccelStepper copied to clipboard

RampGenerator.cpp code inquiry

Open kpu0411 opened this issue 3 years ago • 7 comments

file : RampGenerator.cpp

static void _getNextCommand(const struct ramp_ro_s *ramp, const struct ramp_rw_s *rw, const struct queue_end_s *queue_end, NextCommand *command)

Please tell me what you are using planning_steps for. I don't understand the code. What does 2ms mean?

kpu0411 avatar Oct 21 '21 08:10 kpu0411

The code uses this formula to calculate from steps to the required speed:

v = sqrt(2 * s * a)

On call to getNextCommand(), the code is currently at some point on the ramp e.g. sx and needs to issue the speed for the next point sy. So the speeds are then:

vx = sqrt(2 * sx * a)
vy = sqrt(2 * sy * a)

The problem is now to determine this next point sy in a reasonable distance from sx. And this distance is the (forward) planning_steps. So simply:

sy = sx + planning_steps

This planning_steps is chosen in a way, that a typical command to the stepper queue covers 2ms. On high speeds, the planning_steps are greater than 1 and for slower speeds equal to 1.

gin66 avatar Oct 21 '21 23:10 gin66

On deceleration, the ramp steps are counted down. Means the relation for the next point sy is

sy = sx - planning_steps

gin66 avatar Oct 21 '21 23:10 gin66

thank you. All answers are understandable. But I'm still not quite sure what 2ms means.

kpu0411 avatar Oct 24 '21 23:10 kpu0411

2ms = 0.002 seconds ?!

gin66 avatar Oct 25 '21 03:10 gin66

2ms = 0.002 We know this. I don't know why the standard is 2ms

kpu0411 avatar Oct 25 '21 04:10 kpu0411

no special reason. Actually could have chosen 1ms or 3ms. For avr this makes a difference, because the manageSteppers() task per stepper is pretty slow. Driving three steppers at full speed is quite demanding for the CPU and does not leave much processing time for the application. At 2ms is already much better than with 1ms and based on my judgement acceptable. As this “acceptable” is subjective, I have not made comparisons with 3 or 4ms.

At 2ms and 25kHz step rate (avr), one command will do at most 80steps. For esp32 at 200kSteps/s, a command with e.g. 255steps lasts only 1.275ms.

gin66 avatar Oct 25 '21 21:10 gin66

thank you.

kpu0411 avatar Oct 27 '21 00:10 kpu0411