# Iterative calculation of trajectory

In the answer https://robotics.stackexchange.com/a/7512/22953 there is an example for trapetzoid trajectory planning that results in the following table.

$$\begin{array} {|r|r|} \hline time & t & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9\\ \hline acceleration& a & 0 & 2 & 2 & 2 & 0 & 0 & 0 & -2 & -2 & -2\\ velocity & v & 0 & 2 & 4 & 6 & 6 & 6 & 6 & 4 & 2 & 0\\ position & d & 0 & 1 & 4 & 9 & 15 & 21 & 27 & 32 & 35 & 36\\ \hline \end{array}$$

By ocular inspection it seems that

v[t] = v[t - 1] + a[t]
d[t] = d[t - 1] + (v[t - 1] + v[t]) / 2


What is the mathematical basis for this? Why is the average velocity used but not the average accelation? What would the corresponding table look like for a third degree trajectory (i.e. constant jerk instead of constant acceleration)?

Trapezoidal trajectory is basically a piecewise quadratic function. Since the function is quadratic, its second derivative is a constant. The trajectory is then basically comprises segments of constant accelerations.

Denoting a trajectory function as $$x(t)$$, for each segment we would have $$x''(t) = a(t) = a,$$ where $$a$$ is the constant acceleration of that segment. Integrating the above equation with respect to time, we would then have the velocity equation $$x'(t) = v(t) = at + v_0,$$ where the constant of the integration is $$v_0$$, which is the initial velocity of that segment. We finally obtain the displacement equation by integrating the above equation $$x(t) = \frac{1}{2}at^2 + v_0t + x_0,$$ where the constant of the integration is $$x_0$$, which is the initial displacement of the segment.

If we substitute $$at = v(t) - v_0$$ (from the velocity equation) into the displacement equation, we would then have \begin{align} x(t) &= \frac{1}{2}(v(t) - v_0)t + v_0t + x_0\\ &= \frac{1}{2}(v(t) + v_0)t + x_0. \end{align} Now you can probably see how it comes to be the average of the velocities.

From the given table, you can view it as the trajectory being given as segments where each segment has duration of 1 second.

For a third degree (piecewise cubic) trajectory, the idea is pretty much the same. You start from the fact that the jerk for each segment is constant, i.e. $$x'''(t) = j(t) = j.$$ Then all the remaining equations can be derived by integrating the above equation accordingly.

• I think you forgot a $t$ in $\frac{1}{2}(v(t) + v_0) + x_0$, it should be $\frac{1}{2}(v(t) + v_0)t + x_0$, right? Other than that, it made perfect sense. Thanks! May 9, 2019 at 18:25
• Yes, thanks, I just fixed it. If this post answers your question, please consider accepting it so that other people who might have the same question know. May 10, 2019 at 1:44

A trapezoidal move is defined by its instantaneous change in acceleration (and thus linear change in velocity) during the acceleration and deceleration phases.

Also, if a trapezoidal move never gets up to the peak velocity, because the distance is too short, it degenerates into a 'triangular' move, with the deceleration phase starting immediately after the acceleration phase ends.

If the velocity profiles use constant jolt (jerk) then it is no longer a trapezoidal trajectory, and the maths become much harder. You can approximate it with a table as above, just add a jolt row above acceleration and many more columns, but you really need to be using the polynomials to calculate the values.

From a practical point of view, calculating an acceleration and velocity profile from desired time, distance, maximum jolt, maximum acceleration and maximum velocity parameters, is much more complicated than doing the same for the time, distance, maximum acceleration and maximum velocity of a trapezoidal profile.

If you are interested in those equations, Constant Jerk Equations for a trajectory generator seems to be a pretty good summary.