Stage 09 · Lesson 13/15

Trajectory Planning & Motion Generation · Lesson 13

Time Scaling & Motion Duration

Est. 45–60 min

Why

Why this lesson matters

*Modern Robotics* splits every trajectory into a path θ(s), with s from 0 to 1, and a time scaling s(t) that says where on the path you are at time t. Together they give θ(s(t)). In this lesson you will use that split to answer a very practical question: how long should this move take? Too short breaks limits; too long wastes cycle time.

By the end of this lesson you will be able to: explain path vs time scaling; predict how peak speed, acceleration and jerk change when you stretch or squeeze T; compute the shortest legal T from one trial run; and pick T with a knob on the servo bench while the sketch refuses illegal choices.

An electronic train status board above passengers in the hall of New Delhi railway station
The train status board at New Delhi railway station. Same tracks, different timetables — path and timing are separate decisions.Photo: Ravi Dwivedi · CC BY-SA 4.0 · Source: Wikimedia Commons · resized, converted to WebP

Concept

Shape and timing are separate — and T scales everything

Path and time scaling

PartAnswersExample
Path θ(s), s ∈ [0, 1]Where does the robot go?A Cartesian line with IK at each s (Lesson 9)
Time scaling s(t), t ∈ [0, T]When is it at each point?Quintic s = 10u³ − 15u⁴ + 6u⁵ with u = t/T

By the chain rule, joint velocity is θ̇ = (dθ/ds)·ṡ (MR eq. 9.1). The path decides dθ/ds; the time scaling decides ṡ. So you can change the timing without touching the path.

Stretching T: the 1, 2, 3 rule

If you keep the shape of s(t) (for example the quintic) and only change T, then u = t/T and every derivative picks up another 1/T:

QuantityScales asHalve T →
Peak speed1/T× 2
Peak acceleration1/T²× 4
Peak jerk1/T³× 8

Shortest legal T from one trial

  1. Trial

    Play the path once (on paper) with any T₀ and measure the peaks v₀, a₀, j₀ over all joints.

  2. Speed

    T_v = T₀ · v₀ / v_max

  3. Acceleration

    T_a = T₀ · √(a₀ / a_max)

  4. Jerk

    T_j = T₀ · ∛(j₀ / j_max)

  5. Choose

    T = the largest of the three (plus a small safety margin).

A brass and glass hourglass with white sand on a wooden base
An hourglass: the same sand, the same path — only the timing changes if you change the neck.Photo: John Morgan · CC BY 2.0 · Source: Wikimedia Commons · resized, converted to WebP

Visual

Visualise it: same path, different durations

The path is fixed; only the duration changes. Shorter T means steeper joint curves — higher speed, much higher acceleration.

Interactive · Cartesian trajectory planner (2R educational · Stage 8 IK)

Cartesian path with IK to jointsTime scaling same path different duration

Interpolate a straight line in task space, then call Stage 8 ik2R each sample. Labeled simplified — not industrial 6DOF.

EE (x,y)
100.0, 40.0
Joints (°)
-18.4, 96.4
Path health (samples)
unreachable=0 · joint-limit≈0 · singular=0

Code lab

Code lab: one trial, the shortest legal T

time_scaling.py plays the Lesson 9 line (14, 2) → (2, 14) on the 10 cm + 8 cm arm with a quintic s(t) at different T, measures peak joint speed, acceleration and jerk, and then computes the shortest legal T from a single trial. Run python3 time_scaling.py.

time_scaling.py · Python
# time_scaling.py - Stage 9 Lesson 13: time scaling and motion duration
# The same Cartesian line (Lesson 9) is played with different durations T.
# Peak joint speed scales as 1/T, acceleration as 1/T^2, jerk as 1/T^3, so the
# shortest legal T can be computed from ONE trial run. Pure Python.
import math

L1, L2 = 10.0, 8.0
A, B = (14.0, 2.0), (2.0, 14.0)
VMAX, AMAX, JMAX = 120.0, 300.0, 3000.0      # deg/s, deg/s^2, deg/s^3 (example limits)

def ik(x, y):                                  # elbow-up 2R IK (Stage 8), degrees
    c2 = (x*x + y*y - L1*L1 - L2*L2) / (2*L1*L2)
    t2 = math.acos(max(-1.0, min(1.0, c2)))
    t1 = math.atan2(y, x) - math.atan2(L2*math.sin(t2), L1 + L2*math.cos(t2))
    return math.degrees(t1), math.degrees(t2)

def quintic(u):
    return 10*u**3 - 15*u**4 + 6*u**5

def peaks(T, n=2000):
    """Peak |speed|, |acc|, |jerk| over both joints, by finite differences."""
    h = T / n
    q = []
    for k in range(n + 1):
        s = quintic(k / n)
        q.append(ik(A[0] + s*(B[0] - A[0]), A[1] + s*(B[1] - A[1])))
    pv = pa = pj = 0.0
    for j in range(2):
        x = [p[j] for p in q]
        v = [(x[i+1] - x[i]) / h for i in range(n)]
        a = [(v[i+1] - v[i]) / h for i in range(n - 1)]
        jk = [(a[i+1] - a[i]) / h for i in range(n - 2)]
        pv, pa, pj = max(pv, max(map(abs, v))), max(pa, max(map(abs, a))), max(pj, max(map(abs, jk)))
    return pv, pa, pj

print("Part 1 - same path, different durations (quintic timing)")
print("     T(s)   peak speed  peak acc   peak jerk")
for T in (0.5, 1.0, 2.0, 4.0):
    pv, pa, pj = peaks(T)
    print(f"   {T:5.2f}   {pv:8.1f}  {pa:9.1f}  {pj:10.1f}")

print("\nPart 2 - shortest legal T from ONE trial at T0 = 2 s")
T0 = 2.0
pv, pa, pj = peaks(T0)
Tv = T0 * pv / VMAX
Ta = T0 * math.sqrt(pa / AMAX)
Tj = T0 * (pj / JMAX) ** (1/3)
Tmin = max(Tv, Ta, Tj)
print(f"  speed needs T >= {Tv:.2f} s, acceleration T >= {Ta:.2f} s, jerk T >= {Tj:.2f} s")
which = ["speed", "acceleration", "jerk"][[Tv, Ta, Tj].index(Tmin)]
print(f"  shortest legal T = {Tmin:.2f} s (limited by {which})")
pv, pa, pj = peaks(Tmin)
print(f"  check at T = {Tmin:.2f}: speed {pv:.1f} (<= {VMAX:.0f}), acc {pa:.1f} (<= {AMAX:.0f}), jerk {pj:.1f} (<= {JMAX:.0f})")

print("\nPart 3 - rule of thumb: halve T and the peaks grow")
pv1, pa1, pj1 = peaks(2.0)
pv2, pa2, pj2 = peaks(1.0)
print(f"  speed x{pv2/pv1:.2f}, acceleration x{pa2/pa1:.2f}, jerk x{pj2/pj1:.2f}")

Output (run with python3 time_scaling.py)

Part 1 - same path, different durations (quintic timing)
     T(s)   peak speed  peak acc   peak jerk
    0.50      336.0     2976.9     50577.8
    1.00      168.0      744.2      6322.2
    2.00       84.0      186.1       790.3
    4.00       42.0       46.5        98.8

Part 2 - shortest legal T from ONE trial at T0 = 2 s
  speed needs T >= 1.40 s, acceleration T >= 1.58 s, jerk T >= 1.28 s
  shortest legal T = 1.58 s (limited by acceleration)
  check at T = 1.58: speed 106.7 (<= 120), acc 300.0 (<= 300), jerk 1618.0 (<= 3000)

Part 3 - rule of thumb: halve T and the peaks grow
  speed x2.00, acceleration x4.00, jerk x8.00

Try it: plan a tool line, then change the duration and watch the joint curves get steeper or gentler — the path itself stays the same (simplified 2R arm).

Interactive · Cartesian trajectory planner (2R educational · Stage 8 IK)

Cartesian path with IK to jointsTime scaling same path different duration

Interpolate a straight line in task space, then call Stage 8 ik2R each sample. Labeled simplified — not industrial 6DOF.

EE (x,y)
100.0, 40.0
Joints (°)
-18.4, 96.4
Path health (samples)
unreachable=0 · joint-limit≈0 · singular=0

Real world

Choosing durations in the real world

  • Cycle time in factories is the sum of move durations; choosing the shortest legal T for each move saves seconds that add up to hours.
  • 3D printers and CNC machines plan every move inside per-axis limits on feedrate and acceleration (Marlin M203 and M201), so the same path runs slower when the limits are lower.
  • Lesson 9’s planner used a fixed T; with today’s rule it can pick T itself.
An analogue stopwatch hanging on a plain white wall
An analogue stopwatch. Measuring real move times on the bench tells you whether your limits match your motors.Photo: Al Riaz Uddin · CC BY-SA 4.0 · Source: Wikimedia Commons · resized, converted to WebP

Bench build

Bench build: a duration knob with a safety check

duration_knob.ino lets a potentiometer choose T between 0.5 s and 4 s for a 120° quintic move. Before moving it predicts the peaks with the quintic formulas from Lesson 8 (15d/(8T) and 10d/(√3·T²)) and refuses if they break the limits. At start-up it prints the shortest legal T: 1.88 s for these numbers.

Wiring
FromToNote
Servo signalD9
Servo + and −Separate 5–6 V supply, 1 A or moreNever the Arduino 5 V pin
Supply −Arduino GNDCommon ground
10 kΩ potentiometerEnds to 5 V and GND, wiper to A0Pot only — the servo stays on its own supply
ButtonD2 ↔ GNDINPUT_PULLUP
  1. Read the minimum

    Open the Serial Monitor (115200). Note the shortest legal T.

  2. Too short

    Turn the knob fully left (T ≈ 0.5 s) and press D2. It should refuse and not move.

  3. Just legal

    Turn until the printed T is just above the minimum and press D2. Time it.

  4. Slow

    Try T = 4 s. Compare how calm the motion looks.

  5. Your limits

    Change V_MAX and A_MAX and predict the new minimum before you upload.

duration_knob.ino · Arduino C++
// duration_knob.ino - Stage 9 Lesson 13: choose the duration T with a knob
// The knob on A0 sets T from 0.5 s to 4.0 s for a 120 deg quintic move.
// Before moving, the sketch predicts the peaks (quintic: v = 15d/(8T), a = 10d/(sqrt(3) T^2))
// and REFUSES if they break the limits. Press D2 to move 30 <-> 150 deg.
// Wiring: servo signal D9. Servo on a SEPARATE 5-6 V supply (1 A+); supply GND -> Arduino GND.
//         10k potentiometer: ends to 5 V and GND, wiper to A0. Button D2 -> GND (INPUT_PULLUP).
#include <Servo.h>

Servo joint;
const float D = 120.0;
const float V_MAX = 120.0, A_MAX = 300.0;      // deg/s, deg/s^2 (example limits)
const unsigned long DT_MS = 20;
float pos = 30;

void writeDeg(float deg) {
  deg = constrain(deg, 0, 180);
  joint.writeMicroseconds(544 + (int)(deg * (2400 - 544) / 180.0));
}

float quintic(float u) { return u * u * u * (10 - 15 * u + 6 * u * u); }

void setup() {
  Serial.begin(115200);
  pinMode(2, INPUT_PULLUP);
  joint.attach(9);
  writeDeg(pos);                                // quick move to 30 deg at power-up
  float tMin = max(15.0 * D / (8.0 * V_MAX), sqrt(10.0 * D / (sqrt(3.0) * A_MAX)));
  Serial.print(F("Shortest legal T for this move: ")); Serial.print(tMin, 2); Serial.println(F(" s"));
  Serial.println(F("Turn the knob to choose T, press D2 to move."));
}

void loop() {
  if (digitalRead(2) != LOW) return;
  float T = 0.5 + 3.5 * analogRead(A0) / 1023.0;
  float vPeak = 15.0 * D / (8.0 * T);
  float aPeak = 10.0 * D / (sqrt(3.0) * T * T);
  Serial.print(F("T = ")); Serial.print(T, 2);
  Serial.print(F(" s  peak speed ")); Serial.print(vPeak, 0);
  Serial.print(F("  peak acc ")); Serial.print(aPeak, 0);
  if (vPeak > V_MAX || aPeak > A_MAX) {
    Serial.println(F("  -> REFUSED, turn the knob to a longer T"));
  } else {
    Serial.println(F("  -> OK"));
    float start = pos, target = (pos < 90) ? 150 : 30;
    unsigned long t0 = millis();
    while (true) {
      float u = (millis() - t0) / 1000.0 / T;
      if (u > 1) u = 1;
      writeDeg(start + (target - start) * quintic(u));
      if (u >= 1) break;
      delay(DT_MS);
    }
    pos = target;
  }
  while (digitalRead(2) == LOW) delay(10);
  delay(200);
}

Debugging

Debugging durations

SymptomLikely causeFix
Robot misses its limits after you shorten TOnly speed was checkedCheck speed, acceleration and jerk
Move slower than computedReal motor slower than v_maxMeasure; lower v_max
Peaks wrong in the trialToo few samples in finite differencesUse more samples, especially for jerk
Knob reading jumpsLoose wiper or noisy supplyCheck wiring; average a few readings
Different joints finish at different timesEach joint got its own TOne T for the whole path (Lesson 14)

Think

Think about it

Think

A move is too fast: its speed is 1.2× the limit and its acceleration is 1.5× the limit. By how much must you stretch T, and which limit decides?

Experiment

Try it in the lab

About 30 minutes with time_scaling.py and the planner; the knob build takes 15 more minutes.

Experiment

Squeeze and stretch

You will need

  • `time_scaling.py` and Python 3
  • Cartesian trajectory planner (in your browser)
  • Optional: servo, separate 5–6 V supply, 10 kΩ potentiometer, button

Steps

  1. Run the program and check the 1, 2, 3 rule in Part 1 with a calculator.
  2. Change AMAX to 600. Which limit decides now, and what is the new shortest T?
  3. Change the path to the Lesson 9 arc (edit A and B or write the arc). Recompute T.
  4. Lower JMAX until jerk becomes the bottleneck. At what value does that happen?
  5. In the planner, compare a short and a long duration for the same line.
  6. Optional: use the knob build to find the shortest T that your servo can really follow.

Interactive · Cartesian trajectory planner (2R educational · Stage 8 IK)

Cartesian path with IK to jointsTime scaling same path different duration

Interpolate a straight line in task space, then call Stage 8 ik2R each sample. Labeled simplified — not industrial 6DOF.

EE (x,y)
100.0, 40.0
Joints (°)
-18.4, 96.4
Path health (samples)
unreachable=0 · joint-limit≈0 · singular=0

The path stays the same; only the time scaling changes. Speed, acceleration and jerk scale as 1/T, 1/T² and 1/T³, so one trial gives the shortest legal T for any limits.

Knowledge check

Check your understanding

Knowledge check

1. A trajectory is…

2. Halving T (same shape) multiplies peak acceleration by…

3. Halving T multiplies peak jerk by…

4. Acceleration is 1.44× its limit. Stretch T by…

5. In the code, the shortest legal T for the line was limited by…

6. Joint velocity along a path is…

7. What does the knob sketch do if T is too short?

Mini assignment

Hands-on assignment

Mini assignment

Duration worksheet

For three moves of your arm, find the shortest legal duration from one trial each and verify it.

Deliverables

  • The three paths (joint or Cartesian) and your limits.
  • Trial peaks at T₀ and the three T values (speed, acceleration, jerk) for each move.
  • The chosen T with a 10% safety margin and the check run at that T.
  • Total cycle time for the three moves.
  • Optional: measured times on the servo bench next to the planned ones.

Do this, step by step

  1. Run python3 time_scaling.py and read Part 1: the same path at different durations.
  2. In Part 2, note the three T values (speed, acceleration, jerk) found from one trial at T0. Which one is largest?
  3. Change T0 to a different trial value and re-run. The final T should stay the same — check it.
  4. Add a 10% safety margin to the chosen T and write the new peaks.
  5. Optional bench: run duration_knob.ino, turn the knob to change T and watch when the sketch refuses a move that is too fast.

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. Halve T and speed doubles, acceleration ×4, jerk ×8.
  2. So T_needed = T0 × (peak/limit)¹ for speed, ^(1/2) for acceleration and ^(1/3) for jerk.
  3. Choose the largest of the three; that is the limit that decides.

Challenges (pick by level)

  • 🟢 Easy: A move has peak speed 90°/s at T = 2 s. What is it at T = 3 s?
  • 🟢 Easy: Explain path vs timing with a bus route example.
  • 🟡 Medium: Add a 10% safety margin option to time_scaling.py and print the final T.
  • 🟠 Hard-ish: Make the Lesson 9 planner choose T automatically with today’s rule instead of refusing for speed.
  • 🔴 Hard: Use a non-uniform time scaling: slow down only near the middle of the line where the joint speeds peak, and compare total T.
  • ⚫ Research: Read *Modern Robotics* §9.4 (time-optimal time scaling) and explain how it differs from scaling one fixed shape.

Next step

One T for one joint is easy. In Lesson 14 — Multi-Joint Synchronization you will make all six joints of an arm start and finish together, smoothly and inside every joint’s limits.

Look back: Lesson 12: Jerk & Smooth Motion. Next: Lesson 14: Multi-Joint Synchronization. Related: Stage 10 — ROS 2.

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