← all notes

Unit 6 · Trajectory Planning

Trajectory planning without the jargon

So far we computed where the robot is. Trajectory planning adds when: how the robot gets from A to B over time, with positions, velocities and accelerations that the motors can actually deliver.

Section 6.2 of the course book reads like an alien language the first time. Strip the notation away and it is mostly “find the slope and intercept of a line”, with a few rules about which line to pick. Building, evaluating and analysing these trajectories is important for the exam.

Basic vocabulary

Four inputs go into any planner:

InputExample
Path specificationstart, end, waypoints, a line or an arc
Path conditionsobstacles, forbidden zones
Time specificationtotal duration, start/end speed and acceleration
Robot limitsmax joint angle, speed, acceleration

If you have used Unity’s Vector3.Lerp, you already think like this: where from, where to, how fast, what not to crash into.

Joint space or Cartesian space?

KUKA’s A, B, C are yaw (about zz), pitch (about yy), roll (about xx), the reverse of the order you say “roll-pitch-yaw” in.

Synchronous trajectory: all joints start and finish at the same time. It has nothing to do with matching a velocity, which was my first guess.

Polynomials: what “conditions” and "nn" mean

A condition (the book also says constraint) is a checkpoint the motion must hit exactly. Road-trip version: “leave Madrid at 8:00” and “arrive in Barcelona at 14:00” are two conditions. “Be doing exactly 120 km/h when you pass Zaragoza” would be a third.

nn is simply the highest power of tt in the polynomial:

nnPolynomialUnknowns
1a1t+a0a_1 t + a_02
2a2t2+a1t+a0a_2 t^2 + a_1 t + a_03
3a3t3+a2t2+a1t+a0a_3 t^3 + a_2 t^2 + a_1 t + a_04

The golden rule: a polynomial of degree nn has n+1n + 1 coefficients and can satisfy exactly n+1n + 1 conditions. One unknown per rule. So you count the conditions and subtract one:

GivenConditionsDegree
start + end position21 (linear)
+ start/end velocity43 (cubic)
+ start/end acceleration65 (quintic)

Limits are not conditions. “Speed must stay within ±50∘\pm 50^\circ/s” is an inequality, a fence you can’t cross, not a checkpoint you must hit. It does not raise the degree. It only decides how long the motion has to take.

What the coefficients mean

Plug t=0t = 0 into the polynomial and its derivatives and the first coefficients reveal themselves:

q(0)=a0,q˙(0)=a1,q¨(0)=2a2q(0) = a_0, \qquad \dot q(0) = a_1, \qquad \ddot q(0) = 2a_2

So a0a_0 is the start position, a1a_1 the start velocity, a2a_2 half the start acceleration. The higher ones have no single meaning: they bend the curve so it hits the end conditions.

Computing them (where Gauss comes in)

Every condition becomes one equation: write q(t)q(t) or q˙(t)\dot q(t) at the given time and set it equal to the given value. The t=0t = 0 ones give a0a_0, a1a_1 for free; whatever is left is a small linear system. For a cubic:

[100001001TT2T3012T3T2][a0a1a2a3]=[q0q˙0qfq˙f]\begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 1 & T & T^2 & T^3 \\ 0 & 1 & 2T & 3T^2 \end{bmatrix} \begin{bmatrix} a_0 \\ a_1 \\ a_2 \\ a_3 \end{bmatrix} = \begin{bmatrix} q_0 \\ \dot q_0 \\ q_f \\ \dot q_f \end{bmatrix}

Start and stop at rest and it solves to a2=3ΔqT2a_2 = \tfrac{3\Delta q}{T^2}, a3=−2ΔqT3a_3 = -\tfrac{2\Delta q}{T^3}.

Worked example: two joints, one speed limit

Joint 1 goes from 0∘0^\circ to 100∘100^\circ, joint 2 from 30∘30^\circ to 20∘20^\circ.

Degree. Two conditions per joint (start and end position), so degree 1: q(t)=a1t+a0q(t) = a_1 t + a_0.

With T=1T = 1 s. Remember q(t)q(t) just means “the joint angle at time tt”, so q(1)q(1) is the target.

Now add a limit of ±50∘\pm 50^\circ/s and make it synchronous. For a line, the velocity is the slope a1=Δq/Ta_1 = \Delta q / T. Keep TT as an unknown:

100T≤50  ⇒  T1≥2 s,−10T≥−50  ⇒  T2≥0.2 s\frac{100}{T} \le 50 \;\Rightarrow\; T_1 \ge 2\text{ s}, \qquad \frac{-10}{T} \ge -50 \;\Rightarrow\; T_2 \ge 0.2\text{ s}

Synchronous means one common TT for both, and the slowest joint decides: T=max⁡(2, 0.2)=2T = \max(2,\ 0.2) = 2 s. Squeezing everything into 1 s would push joint 1 to 100∘100^\circ/s and trip the limit. Instead the fast joint just takes its time. Redo both lines with T=2T = 2:

q1(t)=50t,q2(t)=−5t+30q_1(t) = 50t, \qquad q_2(t) = -5t + 30

Both speeds (50∘50^\circ/s and −5∘-5^\circ/s) are legal and both joints arrive together.

What is wrong with this profile

A linear trajectory has constant velocity and zero acceleration during the move. Sounds smooth. The problem is the edges: the robot usually starts from rest, so at t=0t = 0 the speed jumps from 0 to 50∘50^\circ/s instantly. That is an infinite acceleration spike (huge jerk), which shakes the arm and wears out the actuators. Same at the stop.

It is only fine if the joint was already moving at exactly that speed before and keeps going after. In Unity terms: a linear Lerp has no ease-in or ease-out. The fix is a higher degree (cubic or quintic), which has enough coefficients to force the start and end velocities, and accelerations, to zero.

Straight lines in the workspace

Now we plan the hand path itself. A straight line from X0X_0 to XfX_f is literally a Lerp:

X(r)=X0+r (Xf−X0),r∈[0,1]X(r) = X_0 + r\,(X_f - X_0), \qquad r \in [0, 1]

r=0r = 0 is the start, r=1r = 1 the end, anything between is on the line. rr is pure geometry. To add time, make rr a function of tt with r(0)=0r(0) = 0 and r(T)=1r(T) = 1. The simplest choice:

r(t)=tT  ⇒  X(t)=X0+tT(Xf−X0),X˙=Xf−X0Tr(t) = \frac{t}{T} \;\Rightarrow\; X(t) = X_0 + \frac{t}{T}(X_f - X_0), \qquad \dot X = \frac{X_f - X_0}{T}

Linear r(t)r(t) means constant hand speed (with the same jerk problem as above). A smooth polynomial for r(t)r(t) eases in and out.

Controllers count in steps

A robot controller is a computer. It does not compute the trajectory continuously, it computes it every sample time Δt\Delta t:

t=k Δt,k=0,1,2,…t = k\,\Delta t, \qquad k = 0, 1, 2, \dots

Example: y0=0y_0 = 0, yf=10y_f = 10, T=1T = 1 s gives y(t)=10ty(t) = 10t and y˙=10\dot y = 10. With Δt=100\Delta t = 100 ms the controller computes 11 states (count both ends!):

kk0123…910
tt [s]0.00.10.20.3…0.91.0
yy0123…910
y˙\dot y10101010…1010