I solve these problems using wxMaxima or Mathcad
This is not a good Friday night problem because maybe only two or three people would be able to solve these kinds of problems. Obviously I must have these all done because I write motion control programs. Here is my simplified solution using wxMaxima. I first wrote 11 equations, eq0 - eq10 to describe the motion for the three motion segments. I am assuming this is deceleration limited. I then can solve for 10 parameters all at once. My general solution has 7 segments to it because I assume the motion is starting from v0=0 and moves to a stop at v7=0
x4 is the position where the ramp starts
v4 is the velocity when starting to ramp down
a4 is assumed to be 0 in this case. The equations get MUCH messier if not.
x45 is the distance traveled while the jerk is negative
x56 is the distance traveled while the jerk is 0 and deceleration is constant
x67 is the distance traveled while the jerk is positive.
x47 is the ramp distance
t47 is the ramp time.
Code:
/* [wxMaxima: comment start ]
SEG567 Dist
Calculate the positions, velocities times ramping up assuming the ramp is acceleration limited
x4, v4 and a4=0 are the initial conditions
d is the requested deceleration
v7 is the requested velocity
[wxMaxima: comment end ] */
/* [wxMaxima: input start ] */
remvalue(all)$
eq0: v4*t45+(a4/2)*t45^2-(j/6)*t45^3=x45$
eq1: v4+a4*t45-(j/2)*t45^2=v5$
eq2: a4-j*t45=a5$
eq3: v5*t56+(a5/2)*t56^2=x56$
eq4: v5+a5*t56=v6$
eq5: t56=(v6-v5)/a6$
eq6: v6*t67+(a6/2)*t67^2+(j/6)*t67^3=x67$
eq7: v6+a6*t67+(j/2)*t67^2=v7$
eq8: a6+j*t67=0$
eq9: t47=t45+t56+t67$
eq10: x47=x45+x56+x67$
/* [wxMaxima: input end ] */
/* [wxMaxima: comment start ]
v7=0 a4=0
[wxMaxima: comment end ] */
/* [wxMaxima: input start ] */
[eq0,eq1,eq2,eq3,eq4,eq5,eq6,eq7,eq8,eq9,eq10]$
subst([v4=v,a4=0,a5=-d,a6=-d,v7=0],%)$
solve(%,[t45,x45,v5,t56,x56,v6,t67,x67,t47,x47])$
grind(%[1]);
/* [wxMaxima: input end ] */
The solution is:
t45 = d/j,
x45 = (6*d*j*v-d^3)/(6*j^2),
v5 = (2*j*v-d^2)/(2*j),
t56 = (j*v-d^2)/(d*j),
x56 = (j*v^2-d^2*v)/(2*d*j),
v6 = d^2/(2*j),t67 = d/j,
x67 = d^3/(6*j^2),
t47 = (j*v+d^2)/(d*j),
x47 = (j*v^2+d^2*v)/(2*d*j)
If I do the calculations for the whole move from ramp up to ramp down there are 7 segments and about 19 equations are solved simultaneously.
These equations are good for a 3rd order motion profile generator which is what most motion controllers use. There are 8 basic states
State 0 v=0 a=0 j=0
State 1 v>0 a>0 j>0
State 2 v>0 a>0 J=0 constant acceleration
State 3 v>0 a>0 J<0
State 4 v>0 a=0 j=0 constant velocity
State 5 v>0 a<0 j<0
State 6 v>0 a<0 j=0 constant deceleration
State 7 v>0 a<0 j>0
State 0 v=0 a=0 j=0
I use the state machine techniques discussed in recent threads to move between the states.
This is an easy case. There are much more difficult cases like what happens when the initial acceleration is not 0 or when moving small distances and going slow speed where neither the command speed, acceleration or deceleration will be reached before have to ramp down to a stop.
Each of these problems usually must be solved in two ways. When must the deceleration occur or will the ramp distance be shorter than the distance to the stop point and then a recalculation must be done using the distance to the stop point where the jerk or decel rate is adjusted so the target stops exactly where it should.
This is why I find it amusing when people say they want to write motion code in a PLC.
I will let some one else struggle with the ramp to a stop when the constant deceleration segment is not reached.