Trajectory Planning & Motion Generation · Lesson 12
Jerk & Smooth Motion
Est. 50–70 min
Why
Why this lesson matters
Jerk is the rate of change of acceleration (units: °/s³ or m/s³). Lesson 11 gave you the fastest motion for speed and acceleration limits — the trapezoid — but its acceleration jumps at four instants, which in theory means infinite jerk. Jumps in acceleration kick the structure, make springy parts wobble, spill liquids, mark cut surfaces and wear gears. This lesson shows how to measure that, and how the S-curve and the quintic fix it.
By the end of this lesson you will be able to: explain jerk with everyday examples; spot where each profile has acceleration jumps; describe the seven phases of an S-curve; compare trapezoid, S-curve, cubic and quintic for time, peak acceleration, acceleration jumps and leftover wobble; and run an S-curve on a servo.

Concept
Jerk, S-curves and why smooth stops matter
Position → velocity → acceleration → jerk
| Quantity | Meaning | You feel it as… |
|---|---|---|
| Velocity | Change of position per second | How fast you are going |
| Acceleration | Change of velocity per second | Being pushed back into the seat |
| Jerk | Change of acceleration per second | The sudden “kick” when the push starts or stops |
Where each profile has acceleration jumps
| Profile | Acceleration | Jerk |
|---|---|---|
| Trapezoid | Jumps at 0, t_a, T − t_a and T | Infinite spikes at those four instants |
| Cubic | Jumps from 0 to 6d/T² at the start (and at the end) | Infinite spikes at the ends |
| Quintic | Starts and ends at 0, smooth | Finite everywhere |
| S-curve | Ramps up and down at a set jerk J | Limited to ±J |
*Modern Robotics* (§9.2.2.3) puts it plainly: trapezoidal motions cause discontinuous jumps in acceleration, and the S-curve is “a popular motion profile in motor control because it avoids vibrations or oscillations induced by step changes in acceleration.”
The seven phases of an S-curve
1. Jerk +J
Acceleration ramps up from 0 to a.
2. Constant acceleration
Speed rises steadily.
3. Jerk −J
Acceleration ramps down to 0 exactly when speed reaches v.
4. Cruise
Constant speed v.
5. Jerk −J
Deceleration ramps in.
6. Constant deceleration
Speed falls steadily.
7. Jerk +J
Deceleration ramps out; speed and acceleration reach 0 exactly at the target.
Visual
Visualise it: jerk in four profiles
Velocity and acceleration of trapezoid, cubic and quintic for the same move. A vertical step in acceleration means a jerk spike.
Interactive · Motion profile comparator
Overlay linear, cubic, and quintic rest-to-rest profiles. Linear has velocity steps (harsh); cubic zeros velocity; quintic also zeros acceleration — lowest jerk among the three.
Position q(t)
Velocity q̇(t)
Acceleration q̈(t)
Jerk q⃛(t)
| Profile | peak |q̇| | peak |q̈| | peak |jerk| |
|---|---|---|---|
| Linear | 36.0 | 0.0 | ∞ (edge) |
| Cubic | 54.0 | 86.4 | 69.1 |
| Quintic | 67.5 | 83.1 | 345.6 |
Educational 1-DOF overlays — not full multi-DOF dynamics. Linear jerk shown as edge impulse in table.
Code lab
Code lab: four profiles and a springy link
jerk.py builds four profiles for the same 120° move with v_max 120°/s and a_max 300°/s² (each one as fast as those limits allow; the S-curve also has J = 1500°/s³). It measures peak acceleration and the biggest jump of acceleration between two 1 ms samples, then drives a simple springy link (a mass on a spring at 3 Hz with 2% damping) and measures the wobble left after the move. Run python3 jerk.py.
# jerk.py - Stage 9 Lesson 12: jerk and smooth motion
# Builds four profiles for the same 120 deg move, measures peak acceleration and jerk,
# then shakes a springy link (3 Hz, 2% damping) with each and measures the wobble left
# after the move. Pure Python.
import math
D, V, A, J = 120.0, 120.0, 300.0, 1500.0 # move (deg), limits (deg/s, deg/s^2, deg/s^3)
DT = 0.0005
def trapezoid(t, T):
ta = V / A
if t <= 0: return 0.0
if t < ta: return 0.5 * A * t * t
if t < T - ta: return 0.5 * A * ta * ta + V * (t - ta)
if t < T: r = T - t; return D - 0.5 * A * r * r
return D
def poly(t, T, kind):
u = min(max(t / T, 0.0), 1.0)
s = 3*u**2 - 2*u**3 if kind == "cubic" else 10*u**3 - 15*u**4 + 6*u**5
return D * s
def scurve_table():
"""7-phase jerk-limited profile, made by integrating the jerk. Returns (T, list of positions)."""
tj = A / J # time to ramp acceleration up or down
ta = V / A - tj # time at constant acceleration
tacc = ta + 2 * tj
tv = (D - V * tacc) / V # cruise time (accel + decel distance = V * tacc)
phases = [(J, tj), (0, ta), (-J, tj), (0, tv), (-J, tj), (0, ta), (J, tj)]
x = v = a = 0.0
xs = [0.0]
for jerk, dur in phases:
for _ in range(round(dur / DT)):
a += jerk * DT; v += a * DT; x += v * DT
xs.append(x)
return len(xs) * DT, xs
T_trap = D / V + V / A
T_cub = max(1.5 * D / V, math.sqrt(6 * D / A))
T_quin = max(15 * D / (8 * V), math.sqrt(10 * D / (math.sqrt(3) * A)))
T_s, S_TAB = scurve_table()
profiles = {
"trapezoid": (T_trap, lambda t: trapezoid(t, T_trap)),
"S-curve": (T_s, lambda t: S_TAB[min(max(round(t / DT), 0), len(S_TAB) - 1)] * D / S_TAB[-1]),
"cubic": (T_cub, lambda t: poly(t, T_cub, "cubic")),
"quintic": (T_quin, lambda t: poly(t, T_quin, "quintic")),
}
def derivs(f, T):
"""Peak |acc| and the biggest jump of acc between two 1 ms samples (a jump = a jerk spike)."""
h = 0.001
n = int(T / h) + 3
x = [f(i * h - h) for i in range(n + 3)]
v = [(x[i+1] - x[i]) / h for i in range(len(x) - 1)]
a = [(v[i+1] - v[i]) / h for i in range(len(v) - 1)]
jumps = [abs(a[i+1] - a[i]) for i in range(len(a) - 1)]
return max(abs(q) for q in a), max(jumps)
def residual_wobble(f, T, fn=3.0, zeta=0.02):
"""Springy link: the tip y follows the base x through a spring. Wobble = max |y - D| after the move."""
w = 2 * math.pi * fn
y = yd = 0.0
xprev = f(0.0)
t, worst = 0.0, 0.0
while t < T + 2.0:
x = f(t); xd = (x - xprev) / DT; xprev = x
ydd = -w * w * (y - x) - 2 * zeta * w * (yd - xd)
yd += ydd * DT; y += yd * DT
if t > T: worst = max(worst, abs(y - D))
t += DT
return worst
print(f"Move {D:.0f} deg with v_max {V:.0f} deg/s, a_max {A:.0f} deg/s^2 (S-curve jerk limit {J:.0f} deg/s^3)")
print(" profile T(s) peak acc biggest acc jump in 1 ms wobble after stop")
for name, (T, f) in profiles.items():
pa, pj = derivs(f, T)
print(f" {name:9s} {T:5.2f} {pa:7.0f} {pj:10.1f} deg/s^2 {residual_wobble(f, T):5.2f} deg")
print("\nA jump of hundreds of deg/s^2 in 1 ms is a step in acceleration: in theory infinite jerk.")
print(f"S-curve jerk limit {J:.0f} deg/s^3 allows at most {J*0.001:.1f} deg/s^2 change per ms.")Output (run with python3 jerk.py)
Move 120 deg with v_max 120 deg/s, a_max 300 deg/s^2 (S-curve jerk limit 1500 deg/s^3) profile T(s) peak acc biggest acc jump in 1 ms wobble after stop trapezoid 1.40 300 150.0 deg/s^2 0.29 deg S-curve 1.60 300 1.5 deg/s^2 0.14 deg cubic 1.55 300 196.7 deg/s^2 0.73 deg quintic 1.88 197 1.1 deg/s^2 0.21 deg A jump of hundreds of deg/s^2 in 1 ms is a step in acceleration: in theory infinite jerk. S-curve jerk limit 1500 deg/s^3 allows at most 1.5 deg/s^2 change per ms.
Try it: compare the acceleration curves of trapezoid, cubic and quintic. Where does the acceleration jump?
Interactive · Motion profile comparator
Overlay linear, cubic, and quintic rest-to-rest profiles. Linear has velocity steps (harsh); cubic zeros velocity; quintic also zeros acceleration — lowest jerk among the three.
Position q(t)
Velocity q̇(t)
Acceleration q̈(t)
Jerk q⃛(t)
| Profile | peak |q̇| | peak |q̈| | peak |jerk| |
|---|---|---|---|
| Linear | 36.0 | 0.0 | ∞ (edge) |
| Cubic | 54.0 | 86.4 | 69.1 |
| Quintic | 67.5 | 83.1 | 345.6 |
Educational 1-DOF overlays — not full multi-DOF dynamics. Linear jerk shown as edge impulse in table.
Real world
Jerk control in the real world
- Motor drives and CNC machines: S-curve (jerk-limited) profiles are popular in motor control to avoid vibrations from step changes in acceleration — better surface finish and less wear.
- Lifts and metro trains: gentle ramps of acceleration so standing passengers are not thrown off balance.
- Robots carrying liquids or fragile parts: chai trays, test tubes, glass panels.
- Cameras and gimbals: jerk-free pans look smooth on video.

Bench build
Bench build: trapezoid vs S-curve on a springy stick
Tape a thin, springy 25–30 cm plastic ruler to a servo horn with a coin at the far end. scurve_servo.ino makes the same 120° move either as a trapezoid (D2, T = 1.40 s) or as a 7-phase S-curve (D3, T = 1.60 s), using the same numbers as jerk.py. The S-curve is made by integrating jerk → acceleration → velocity → position every 2 ms.
| From | To | Note |
|---|---|---|
| Servo signal | D9 | Metal-gear servo preferred |
| Servo + and − | Separate 5–6 V supply, 1 A or more | Never the Arduino 5 V pin |
| Supply − | Arduino GND | Common ground |
| Buttons | D2 ↔ GND (trapezoid), D3 ↔ GND (S-curve) | INPUT_PULLUP |
Set up a camera
Film the ruler tip in slow motion with a phone, from above.
Trapezoid
Press D2 a few times. Count how many wobbles the tip makes after it stops.
S-curve
Press D3 a few times and count again.
Change J
Set J_MAX to 600 and then 6000. What happens to T and to the wobble?
Optional sensor
Fix an MPU-6050 accelerometer module near the tip and log its readings at the stop for both profiles.
// scurve_servo.ino - Stage 9 Lesson 12: trapezoid vs jerk-limited S-curve on a springy stick
// D2: 120 deg move with a trapezoid (acceleration jumps at the corners).
// D3: the same move with a 7-phase S-curve (acceleration ramps, jerk <= J_MAX).
// Each press goes 30 -> 150 or back. Watch the stick tip wobble when it stops.
// Wiring: servo signal D9. Servo on a SEPARATE 5-6 V supply (1 A+); supply GND -> Arduino GND.
// Buttons D2 -> GND and D3 -> GND (INPUT_PULLUP).
#include <Servo.h>
Servo joint;
const float D = 120.0, V_MAX = 120.0, A_MAX = 300.0, J_MAX = 1500.0;
const float STEP = 0.002; // 2 ms integration step
float pos = 30;
void writeDeg(float deg) {
deg = constrain(deg, 0, 180);
joint.writeMicroseconds(544 + (int)(deg * (2400 - 544) / 180.0));
}
// Plays a list of (jerk, duration) phases by integrating jerk -> acc -> vel -> pos.
void play(const float jerk[], const float dur[], int n, float dir) {
float x = 0, v = 0, a = 0, start = pos;
unsigned long next = micros();
for (int p = 0; p < n; p++) {
long steps = lround(dur[p] / STEP);
for (long k = 0; k < steps; k++) {
a += jerk[p] * STEP; v += a * STEP; x += v * STEP;
writeDeg(start + dir * x);
next += (unsigned long)(STEP * 1e6);
while ((long)(micros() - next) < 0) {}
}
}
pos = start + dir * D;
writeDeg(pos);
Serial.print(F(" ended at ")); Serial.print(start + dir * x, 1); Serial.println(F(" deg (planned exactly 120 deg away)"));
}
void trapezoid(float dir) {
// a jerk "phase" of zero duration is a jump: we set acceleration directly instead
float ta = V_MAX / A_MAX, tv = D / V_MAX - ta;
float x = 0, v = 0, start = pos;
unsigned long next = micros();
float T = 2 * ta + tv;
for (float t = 0; t < T; t += STEP) {
float a = (t < ta) ? A_MAX : (t < ta + tv ? 0 : -A_MAX);
v += a * STEP; x += v * STEP;
writeDeg(start + dir * x);
next += (unsigned long)(STEP * 1e6);
while ((long)(micros() - next) < 0) {}
}
pos = start + dir * D;
writeDeg(pos);
Serial.print(F("trapezoid, T = ")); Serial.print(T, 2); Serial.println(F(" s"));
}
void scurve(float dir) {
float tj = A_MAX / J_MAX, ta = V_MAX / A_MAX - tj, tv = (D - V_MAX * (ta + 2 * tj)) / V_MAX;
float jerk[7] = { J_MAX, 0, -J_MAX, 0, -J_MAX, 0, J_MAX };
float dur[7] = { tj, ta, tj, tv, tj, ta, tj };
Serial.print(F("S-curve, T = ")); Serial.print(4 * tj + 2 * ta + tv, 2); Serial.println(F(" s"));
play(jerk, dur, 7, dir);
}
void setup() {
Serial.begin(115200);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
joint.attach(9);
writeDeg(pos); // quick move to 30 deg at power-up
Serial.println(F("D2: trapezoid. D3: S-curve. Each press moves 120 deg."));
}
void loop() {
float dir = (pos < 90) ? 1 : -1;
if (digitalRead(2) == LOW) { trapezoid(dir); while (digitalRead(2) == LOW) delay(10); }
if (digitalRead(3) == LOW) { scurve(dir); while (digitalRead(3) == LOW) delay(10); }
}
Debugging
Debugging jerky motion
| Symptom | Likely cause | Fix |
|---|---|---|
| Clunk at start and stop | Acceleration jumps (trapezoid, cubic) | Use an S-curve or quintic |
| Wobble after every stop | Kick excites the link’s natural frequency | Lower J; avoid sudden changes in acceleration; stiffen the link |
| S-curve ends short or long | Phase times rounded to the step size | Round phases to whole steps; snap to the target at the end |
| S-curve formula gives negative times | Move too short for all 7 phases | Use fewer phases or lower v/a for short moves |
| Still jerky even with a smooth plan | Update rate too slow, or the servo’s own controller | Update every 2–20 ms; try a different servo |
Think
Think about it
Think
The S-curve took only 0.2 s longer than the trapezoid but the quintic took 0.48 s longer. Why is the S-curve so much faster than the quintic for the same limits, even though both are smooth?
Experiment
Try it in the lab
About 35 minutes with jerk.py and the comparator; the stick build takes 20 more minutes.
Experiment
Measure jerk and wobble
You will need
- `jerk.py` and Python 3
- Motion profile comparator (in your browser)
- Optional: servo, separate 5–6 V supply, two buttons, springy ruler, coin, phone camera, MPU-6050 module
Steps
- Run the program and fill a table: profile, T, acceleration jump, wobble.
- Change J to 600 and then 6000. How do the S-curve’s T and wobble change?
- Change `fn` (link frequency) to 1.5 and 6 Hz. Does the ranking of wobble stay the same?
- Check the worked S-curve numbers by hand (t_j, constant-acceleration time, cruise time).
- In the comparator, point at every place where acceleration jumps.
- Optional: film the stick with both profiles and count the wobbles.
Interactive · Motion profile comparator
Overlay linear, cubic, and quintic rest-to-rest profiles. Linear has velocity steps (harsh); cubic zeros velocity; quintic also zeros acceleration — lowest jerk among the three.
Position q(t)
Velocity q̇(t)
Acceleration q̈(t)
Jerk q⃛(t)
| Profile | peak |q̇| | peak |q̈| | peak |jerk| |
|---|---|---|---|
| Linear | 36.0 | 0.0 | ∞ (edge) |
| Cubic | 54.0 | 86.4 | 69.1 |
| Quintic | 67.5 | 83.1 | 345.6 |
Educational 1-DOF overlays — not full multi-DOF dynamics. Linear jerk shown as edge impulse in table.
Acceleration jumps (trapezoid, cubic) mean jerk spikes and kicks. The S-curve limits jerk at a small time cost; the quintic is smooth but slower for the same limits. How much wobble each causes depends on the link’s own frequency.
Knowledge check
Check your understanding
Knowledge check
1. Jerk is…
2. Where does a trapezoid have infinite jerk?
3. How many phases does a full S-curve have?
4. With a = 300°/s² and J = 1500°/s³, how long does acceleration take to ramp up?
5. In jerk.py, which profile left the most wobble?
6. Why is the S-curve faster than the quintic for the same limits?
7. An arm rings after every stop. What should you check first?
Mini assignment
Hands-on assignment
Mini assignment
Smoothness ladder
Rank trapezoid, cubic, quintic and S-curve for a move your arm really makes, using numbers and a video.
Deliverables
- Choose a move and the joint limits (from your Lesson 11 limit sheet).
- Run `jerk.py` with your numbers and copy the table.
- Repeat for two link frequencies and comment on the ranking.
- A short video (or tally of wobbles) of trapezoid vs S-curve on the stick.
- Your recommendation: which profile for a pick-and-place arm carrying a glass of water, and why.
Do this, step by step
- Run
python3 jerk.pyand copy the table of peak jerk and residual wobble for each profile. - Write which profile has the highest jerk and which has the lowest wobble.
- Change the link frequency
fn(default 3.0 Hz inresidual_wobble) to two other values, e.g. 2.0 and 5.0. Does the ranking change? - In the motion profile comparator, compare trapezoid and S-curve and sketch the acceleration curve of each.
- Optional bench: run
scurve_servo.inowith a stick on the horn, then compare with the trapezoid sketch and count wobbles after each stop.
Stuck? Hints, one at a time
- Jerk is how fast acceleration changes; a jump in acceleration means very high jerk.
- A trapezoid has acceleration jumps at 0, t_a, T − t_a and T.
- An S-curve ramps acceleration up and down, so it takes a little longer but shakes the arm less.
Challenges (pick by level)
- 🟢 Easy: Give two everyday examples of high jerk and two of low jerk.
- 🟢 Easy: For v = 100°/s, a = 200°/s², J = 1000°/s³, find t_j and the constant-acceleration time.
- 🟡 Medium: Plot acceleration vs time for all four profiles in
jerk.py. - 🟠 Hard-ish: Make the S-curve code handle short moves where v is never reached (no cruise phase).
- 🔴 Hard: Log the MPU-6050 at 200 Hz during both bench moves and compare the peak vibration after the stop.
- ⚫ Research: Read *Modern Robotics* §9.2.2.3 and exercises 9.14–9.17 on S-curves, and explain how many of v, a, J and T you may choose freely.
Next step
You can now shape motions in many ways. In Lesson 13 — Time Scaling & Motion Duration you will separate the shape of a path from its timing and learn how to choose T — and how to stretch a plan that breaks a limit.
Look back: Lesson 11: Velocity & Acceleration Constraints. Next: Lesson 13: Time Scaling & Motion Duration. Related: Stage 12 — Simulation & Digital Twin.
Sources
- Modern Robotics (Lynch & Park) — book home page and free PDF — §9.2.2.3 S-curve time scalings (seven stages; avoids vibrations from step changes in acceleration; trapezoid acceleration jumps at 0, t_a, T − t_a, T); §9.2.2.1 cubic’s infinite jerk at the ends.
- Wikipedia — Jerk (physics) — jerk as the rate of change of acceleration.
- Wikipedia — Acceleration — acceleration as the rate of change of velocity.
- Arduino — Servo library —
writeMicroseconds()used to stream the profiles. - Photos: Wikimedia Commons (credits under each image).
Self-attested for now — keep artifacts in your lab notebook.
Complete
Today's goal
0 of 1 done today
Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).