FastAccelStepper
FastAccelStepper copied to clipboard
RampGenerator.cpp code inquiry
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?
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.
On deceleration, the ramp steps are counted down. Means the relation for the next point sy is
sy = sx - planning_steps
thank you. All answers are understandable. But I'm still not quite sure what 2ms means.
2ms = 0.002 seconds ?!
2ms = 0.002 We know this. I don't know why the standard is 2ms
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.
thank you.