Stage 09 · Lesson 12/15

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.

A glass mug of tea on a blue checked tablecloth
A glass of tea — the classic jerk test. Sudden starts and stops make it slosh; a smooth change of acceleration keeps it calm.Photo: Nevit Dilmen · CC BY-SA 3.0 · Source: Wikimedia Commons · resized, converted to WebP

Concept

Jerk, S-curves and why smooth stops matter

Position → velocity → acceleration → jerk

QuantityMeaningYou feel it as…
VelocityChange of position per secondHow fast you are going
AccelerationChange of velocity per secondBeing pushed back into the seat
JerkChange of acceleration per secondThe sudden “kick” when the push starts or stops

Where each profile has acceleration jumps

ProfileAccelerationJerk
TrapezoidJumps at 0, t_a, T − t_a and TInfinite spikes at those four instants
CubicJumps from 0 to 6d/T² at the start (and at the end)Infinite spikes at the ends
QuinticStarts and ends at 0, smoothFinite everywhere
S-curveRamps up and down at a set jerk JLimited 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. 1. Jerk +J

    Acceleration ramps up from 0 to a.

  2. 2. Constant acceleration

    Speed rises steadily.

  3. 3. Jerk −J

    Acceleration ramps down to 0 exactly when speed reaches v.

  4. 4. Cruise

    Constant speed v.

  5. 5. Jerk −J

    Deceleration ramps in.

  6. 6. Constant deceleration

    Speed falls steadily.

  7. 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

Quintic polynomial rest-to-rest trajectoryJerk and smooth motion comparisonMulti-joint synchronization shared progress

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)

Profilepeak |q̇|peak |q̈|peak |jerk|
Linear36.00.0∞ (edge)
Cubic54.086.469.1
Quintic67.583.1345.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 · Python
# 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

Quintic polynomial rest-to-rest trajectoryJerk and smooth motion comparisonMulti-joint synchronization shared progress

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)

Profilepeak |q̇|peak |q̈|peak |jerk|
Linear36.00.0∞ (edge)
Cubic54.086.469.1
Quintic67.583.1345.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.
A large CNC nesting router with a vacuum hose over a white board in a wide factory hall
A CNC nesting router in a factory. Machines like this cut sheets at high speed, and jerk control helps keep cuts clean and the machine steady.Photo: ChazGoodman · CC BY-SA 4.0 · Source: Wikimedia Commons · resized, converted to WebP

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.

Wiring
FromToNote
Servo signalD9Metal-gear servo preferred
Servo + and −Separate 5–6 V supply, 1 A or moreNever the Arduino 5 V pin
Supply −Arduino GNDCommon ground
ButtonsD2 ↔ GND (trapezoid), D3 ↔ GND (S-curve)INPUT_PULLUP
  1. Set up a camera

    Film the ruler tip in slow motion with a phone, from above.

  2. Trapezoid

    Press D2 a few times. Count how many wobbles the tip makes after it stops.

  3. S-curve

    Press D3 a few times and count again.

  4. Change J

    Set J_MAX to 600 and then 6000. What happens to T and to the wobble?

  5. Optional sensor

    Fix an MPU-6050 accelerometer module near the tip and log its readings at the stop for both profiles.

scurve_servo.ino · Arduino C++
// 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); }
}
A blue GY-521 breakout board with an MPU-6050 chip and pins labelled VCC, GND, SCL, SDA, XDA, XCL, AD0, INT
A GY-521 MPU-6050 module (3-axis gyroscope + accelerometer). Fixed to a moving link, it lets you measure the vibrations a profile causes.Photo: Nevit Dilmen · CC BY-SA 3.0 · Source: Wikimedia Commons · resized, converted to WebP

Debugging

Debugging jerky motion

SymptomLikely causeFix
Clunk at start and stopAcceleration jumps (trapezoid, cubic)Use an S-curve or quintic
Wobble after every stopKick excites the link’s natural frequencyLower J; avoid sudden changes in acceleration; stiffen the link
S-curve ends short or longPhase times rounded to the step sizeRound phases to whole steps; snap to the target at the end
S-curve formula gives negative timesMove too short for all 7 phasesUse fewer phases or lower v/a for short moves
Still jerky even with a smooth planUpdate rate too slow, or the servo’s own controllerUpdate 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

  1. Run the program and fill a table: profile, T, acceleration jump, wobble.
  2. Change J to 600 and then 6000. How do the S-curve’s T and wobble change?
  3. Change `fn` (link frequency) to 1.5 and 6 Hz. Does the ranking of wobble stay the same?
  4. Check the worked S-curve numbers by hand (t_j, constant-acceleration time, cruise time).
  5. In the comparator, point at every place where acceleration jumps.
  6. Optional: film the stick with both profiles and count the wobbles.

Interactive · Motion profile comparator

Quintic polynomial rest-to-rest trajectoryJerk and smooth motion comparisonMulti-joint synchronization shared progress

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)

Profilepeak |q̇|peak |q̈|peak |jerk|
Linear36.00.0∞ (edge)
Cubic54.086.469.1
Quintic67.583.1345.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

  1. Run python3 jerk.py and copy the table of peak jerk and residual wobble for each profile.
  2. Write which profile has the highest jerk and which has the lowest wobble.
  3. Change the link frequency fn (default 3.0 Hz in residual_wobble) to two other values, e.g. 2.0 and 5.0. Does the ranking change?
  4. In the motion profile comparator, compare trapezoid and S-curve and sketch the acceleration curve of each.
  5. Optional bench: run scurve_servo.ino with a stick on the horn, then compare with the trapezoid sketch and count wobbles after each stop.

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. Jerk is how fast acceleration changes; a jump in acceleration means very high jerk.
  2. A trapezoid has acceleration jumps at 0, t_a, T − t_a and T.
  3. 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

Self-attested for now — keep artifacts in your lab notebook.

Complete

Today's goal

0 of 1 done today

0-day streak
Daily goal:lessons, quizzes or assignments a day

Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).

Stuck somewhere?

Ask a doubt about this lesson

Saved with this lesson's id and your email so we can reply. Privacy · or email contact@aihubstation.in