Hello, I am trying to implement acceleration and deceleration control as well as coordinate movement to control my stepper motors, and have come across this tutorial video from iforce2d https://www.youtube.com/watch?v=fHAO7SW-SZI&t=1989s and have read the sketch used to achieve linear coordinate control, it was well documented, however, I can't understand the part where he calculate the estStepsToSpeed, why the equation so complicate? How to derive it? I though it should be something simple like estStepsToSpeed = (v^2 - v0^2) / 2a?. Sorry for my bad english, since it not my first language.
struct stepperInfo {
// externally defined parameters
float acceleration;
volatile unsigned long minStepInterval; // ie. max speed, smaller is faster
void (*dirFunc)(int);
void (*stepFunc)();
// derived parameters
unsigned int c0; // step interval for first step, determines acceleration
long stepPosition; // current position of stepper (total of all movements taken so far)
// per movement variables (only changed once per movement)
volatile int dir; // current direction of movement, used to keep track of position
volatile unsigned int totalSteps; // number of steps requested for current movement
volatile bool movementDone = false; // true if the current movement has been completed (used by main program to wait for completion)
volatile unsigned int rampUpStepCount; // number of steps taken to reach either max speed, or half-way to the goal (will be zero until this number is known)
volatile unsigned long estStepsToSpeed; // estimated steps required to reach max speed
volatile unsigned long estTimeForMove; // estimated time (interrupt ticks) required to complete movement
volatile unsigned long rampUpStepTime;
volatile float speedScale; // used to slow down this motor to make coordinated movement with other motors
// per iteration variables (potentially changed every interrupt)
volatile unsigned int n; // index in acceleration curve, used to calculate next interval
volatile float d; // current interval length
volatile unsigned long di; // above variable truncated
volatile unsigned int stepCount; // number of steps completed in current movement
};
void resetStepper(volatile stepperInfo& si) {
si.c0 = si.w;
si.d = si.c0;
si.di = si.d;
si.stepCount = 0;
si.n = 0;
si.rampUpStepCount = 0;
si.movementDone = false;
si.speedScale = 1;
float a = si.minStepInterval / (float)si.c0;
a *= 0.676;
float m = ((a*a - 1) / (-2 * a));
float n = m * m;
si.estStepsToSpeed = n;
}```