Stage 09 · Lesson 11/15

Trajectory Planning & Motion Generation · Lesson 11

Velocity & Acceleration Constraints

Est. 50–70 min

Why

Why this lesson matters

Until now you chose the move time T yourself and checked the speed afterwards. In real robots it is the other way round: the limits are given — maximum velocity and maximum acceleration for each joint — and the planner finds the fastest motion that respects them. This lesson shows how: the trapezoidal velocity profile, the triangle case for short moves, and how several joints share one time.

By the end of this lesson you will be able to: compute the shortest time for a rest-to-rest move with v_max and a_max; tell when the profile is a trapezoid and when it is a triangle; find the shortest legal T for cubic and quintic moves; synchronise several joints so the slowest one sets the time; and run a limited move on a servo.

Electric locomotives in blue and cream livery hauling a train around a curve on a ghat section in the rain, a rock wall on the right
WCG2 locomotives escorting an Intercity up the ghats. Heavy trains on steep sections run inside strict speed and acceleration limits.Photo: HarshWCAM3 · CC BY-SA 2.0 · Source: Wikimedia Commons · resized, converted to WebP

Concept

Limits, the trapezoid and the shortest legal time

The two limits

LimitSymbolComes fromIf you break it
Velocityv_max (°/s)Motor speed, gearbox, safety rulesMotor cannot keep up; position lags
Accelerationa_max (°/s²)Motor torque ÷ inertia, current limitMotor saturates, overshoots, gears and frame shake

The trapezoid: speed up, cruise, slow down

The fastest rest-to-rest move with these two limits accelerates at a_max until it reaches v_max, cruises, then decelerates at a_max. The velocity graph is a trapezoid, and position is parabola + straight line + parabola. *Modern Robotics* (§9.2.2.2) notes that, with known joint velocity and acceleration limits, the trapezoid using the largest allowed v and a is the fastest straight-line motion possible.

CaseTestTime TPeak speed
Trapezoidd ≥ v_max² / a_maxT = d / v_max + v_max / a_maxv_max
Triangle (“bang-bang”)d < v_max² / a_maxT = 2·√(d / a_max)√(a_max·d) — below v_max

Cubic and quintic under limits

Smooth polynomials are slower for the same limits, because their peaks are higher than their averages. From Lessons 7–8: a cubic’s peak speed is 1.5·d/T and peak acceleration 6·d/T²; a quintic’s are 15·d/(8T) and 10·d/(√3·T²). Set each peak ≤ its limit and take the larger T. The price of smoothness is time — Part 1 of the code shows how much.

Many joints, one time

For a straight line in joint space, all joints share one path variable s. Joint i moves d_i, so its speed is d_i·ṡ and its acceleration d_i·s̈. Choose the path limits as v = min(v_lim,i / |d_i|) and a = min(a_lim,i / |d_i|) (*Modern Robotics* eq. 9.14–9.15). The joint with the biggest move compared to its limits sets the time; the others move slower and arrive together.

Visual

Visualise it: profiles under limits

Same move, different profiles: the trapezoid reaches the target soonest for given limits; cubic and quintic are smoother but need more time.

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: shortest legal times

limits.py computes the trapezoid or triangle for several move sizes, the shortest legal cubic and quintic times for the same limits, and a three-joint synchronised move. Run python3 limits.py.

limits.py · Python
# limits.py - Stage 9 Lesson 11: velocity and acceleration constraints
# Shortest-time trapezoid (or triangle) for given limits, and the shortest legal
# time for cubic and quintic moves. Pure Python.
import math

def trapezoid(d, vmax, amax):
    """Rest-to-rest move of distance d with |v| <= vmax, |a| <= amax. Returns (T, peak v, shape)."""
    d = abs(d)
    if d >= vmax**2 / amax:                  # long enough to reach vmax
        return d / vmax + vmax / amax, vmax, "trapezoid"
    vpeak = math.sqrt(amax * d)              # never reaches vmax: triangle (bang-bang)
    return 2 * math.sqrt(d / amax), vpeak, "triangle"

def min_T_cubic(d, vmax, amax):
    return max(1.5 * d / vmax, math.sqrt(6 * d / amax))

def min_T_quintic(d, vmax, amax):
    return max(15 * d / (8 * vmax), math.sqrt(10 * d / (math.sqrt(3) * amax)))

VMAX, AMAX = 120.0, 300.0                    # deg/s and deg/s^2 (example servo-arm limits)
print(f"Part 1 - one joint, vmax {VMAX:.0f} deg/s, amax {AMAX:.0f} deg/s^2 (switch distance v^2/a = {VMAX**2/AMAX:.0f} deg)")
print("   move   shape       T(s)  peak v   cubic T  quintic T")
for d in (10, 30, 48, 90, 150):
    T, vp, shape = trapezoid(d, VMAX, AMAX)
    print(f"  {d:4d}   {shape:9s}  {T:5.2f}  {vp:6.1f}    {min_T_cubic(d, VMAX, AMAX):5.2f}     {min_T_quintic(d, VMAX, AMAX):5.2f}")

print("\nPart 2 - three joints, one straight joint-space line, all start and stop together")
moves = [90.0, -40.0, 20.0]                  # degrees each joint must move
vlim = [120.0, 120.0, 200.0]                 # per-joint limits
alim = [300.0, 300.0, 600.0]
# Modern Robotics eq. 9.14-9.15: |d_i| * v <= vlim_i and |d_i| * a <= alim_i, for the path speed v and accel a in s
v = min(vl / abs(d) for d, vl in zip(moves, vlim))
a = min(al / abs(d) for d, al in zip(moves, alim))
T, _, shape = trapezoid(1.0, v, a)
print(f"  path limits: v = {v:.3f} 1/s, a = {a:.3f} 1/s^2 -> {shape}, T = {T:.2f} s")
for i, (d, vl, al) in enumerate(zip(moves, vlim, alim), 1):
    Ti, _, _ = trapezoid(d, vl, al)
    print(f"  joint {i}: move {d:6.1f} deg, peak {abs(d)*min(v, math.sqrt(a)):6.1f} deg/s (limit {vl:.0f}), alone it would need {Ti:.2f} s")

print("\nPart 3 - the slowest joint sets the time")
print(f"  joint 1 alone needs {trapezoid(90, 120, 300)[0]:.2f} s; the others slow down to finish with it.")

Output (run with python3 limits.py)

Part 1 - one joint, vmax 120 deg/s, amax 300 deg/s^2 (switch distance v^2/a = 48 deg)
   move   shape       T(s)  peak v   cubic T  quintic T
    10   triangle    0.37    54.8     0.45      0.44
    30   triangle    0.63    94.9     0.77      0.76
    48   trapezoid   0.80   120.0     0.98      0.96
    90   trapezoid   1.15   120.0     1.34      1.41
   150   trapezoid   1.65   120.0     1.88      2.34

Part 2 - three joints, one straight joint-space line, all start and stop together
  path limits: v = 1.333 1/s, a = 3.333 1/s^2 -> trapezoid, T = 1.15 s
  joint 1: move   90.0 deg, peak  120.0 deg/s (limit 120), alone it would need 1.15 s
  joint 2: move  -40.0 deg, peak   53.3 deg/s (limit 120), alone it would need 0.73 s
  joint 3: move   20.0 deg, peak   26.7 deg/s (limit 200), alone it would need 0.37 s

Part 3 - the slowest joint sets the time
  joint 1 alone needs 1.15 s; the others slow down to finish with it.

Try it: compare trapezoid, cubic and quintic profiles for the same move. Look at the peak velocity and peak acceleration of each.

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

Speed and acceleration limits in the real world

  • 3D printers and CNC machines: Marlin firmware sets the maximum feedrate (M203) and maximum acceleration (M201) of each axis; every move is planned inside them.
  • Lifts: the car speeds up gently, cruises and slows down — a comfortable limit on acceleration matters as much as speed.
  • Conveyors and pick-and-place: throughput depends on how short each move can be made inside the motor limits.
  • Industrial arms: robot languages let you set speed and acceleration for moves; the controller plans the timing inside them.
A lift motor room with blue lift machines, yellow guards and controller cabinets
A lift motor room. The machines here move the cars with planned speed and acceleration — limits chosen for comfort and safety.Photo: Kgbo · CC BY-SA 4.0 · Source: Wikimedia Commons · resized, converted to WebP
A blue steel conveyor system with curved roller sections and a sloping belt inside a factory
A factory conveyor system. Speeds and accelerations are limited so boxes don’t slip or topple.Photo: falco · CC0 · Source: Wikimedia Commons · resized, converted to WebP

Bench build

Bench build: a limited servo move

trapezoid_servo.ino moves one servo with the same limits (120°/s, 300°/s²). D2 swings it 30° ↔ 150° (a 120° move, trapezoid, T = 1.40 s). D3 makes a 20° hop (triangle, T ≈ 0.52 s, peak ≈ 77°/s). The Serial Monitor prints the plan before each move.

Wiring
FromToNote
Servo signalD9Any standard hobby servo
Servo + and −Separate 5–6 V supply, 1 A or moreNever the Arduino 5 V pin
Supply −Arduino GNDCommon ground
ButtonsD2 ↔ GND, D3 ↔ GNDINPUT_PULLUP
  1. Add a load

    Tape a 15 cm stick with a coin at its end to the horn. It makes inertia visible.

  2. Long move

    Press D2. Check the printed “trapezoid, T = 1.40 s” and time it with a phone stopwatch.

  3. Short move

    Press D3 a few times. Note “triangle” and how it never reaches full speed.

  4. Push the limits

    Set A_MAX to 3000. Does the stick whip and wobble at the ends? Then set V_MAX to 1000 °/s — faster than most hobby servos can turn: does the servo still keep up with the plan?

  5. Find your servo’s limit

    Increase V_MAX in steps until the stick visibly lags the plan. That is roughly your servo’s real speed limit under this load.

trapezoid_servo.ino · Arduino C++
// trapezoid_servo.ino - Stage 9 Lesson 11: a speed- and acceleration-limited servo move
// Press D2: the servo moves between 30 and 150 deg with a trapezoid (or triangle)
// velocity profile that never exceeds V_MAX and A_MAX. Press D3: a short 20 deg hop.
// Serial Monitor (115200) prints the planned shape and time.
// 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 V_MAX = 120.0;    // deg/s
const float A_MAX = 300.0;    // deg/s^2
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));
}

void move(float target) {
  float d = fabs(target - pos), dir = (target > pos) ? 1 : -1;
  if (d < 0.01) return;
  float v = V_MAX, ta, T;
  if (d >= V_MAX * V_MAX / A_MAX) { ta = V_MAX / A_MAX; T = d / V_MAX + ta; Serial.print(F("trapezoid")); }
  else { v = sqrt(A_MAX * d); ta = v / A_MAX; T = 2 * ta; Serial.print(F("triangle")); }
  Serial.print(F(", T = ")); Serial.print(T, 2); Serial.print(F(" s, peak ")); Serial.print(v, 1); Serial.println(F(" deg/s"));
  float start = pos;
  unsigned long t0 = millis();
  while (true) {
    float t = (millis() - t0) / 1000.0, s;
    if (t >= T) break;
    if (t < ta) s = 0.5 * A_MAX * t * t;                                // speeding up
    else if (t < T - ta) s = 0.5 * A_MAX * ta * ta + v * (t - ta);      // cruising
    else { float r = T - t; s = d - 0.5 * A_MAX * r * r; }              // slowing down
    writeDeg(start + dir * s);
    delay(DT_MS);
  }
  pos = target;
  writeDeg(pos);
}

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: 30 <-> 150 deg.  D3: hop 20 deg."));
}

void loop() {
  if (digitalRead(2) == LOW) { move(pos < 90 ? 150 : 30); while (digitalRead(2) == LOW) delay(10); }
  if (digitalRead(3) == LOW) { move(pos + 20 <= 150 ? pos + 20 : pos - 20); while (digitalRead(3) == LOW) delay(10); }
}

Debugging

Debugging limited motions

SymptomLikely causeFix
Move takes longer than plannedv_max higher than the motor can really doMeasure the real speed; lower v_max
Overshoot and wobble at stopa_max too high for the loadLower a_max, or use a smoother profile (Lesson 12)
Short moves feel slowTriangle case — never reaches v_maxNormal; check d < v²/a
Tool path bendsJoints not synchronisedOne shared s(t), slowest joint sets T
Jump at the startStarting position stored wronglyTrack pos; start each plan from the real position

Think

Think about it

Think

Doubling a_max does not halve the time of a long 150° move (try it in the code). Why not, and which limit should you raise to make long moves faster?

Experiment

Try it in the lab

About 35 minutes with limits.py and the profile comparator; the servo build takes 15 more minutes.

Experiment

Limits in numbers and on the bench

You will need

  • `limits.py` and Python 3
  • Motion profile comparator (in your browser)
  • Optional: one servo, separate 5–6 V supply, two buttons, stick and coin, phone stopwatch

Steps

  1. Run the program. Check the 90° row by hand with the trapezoid formula.
  2. Double AMAX to 600. Which rows change most — short or long moves?
  3. Add a 48° row by hand: why is it exactly on the border?
  4. In Part 2, change joint 3’s move to 150°. Which joint is now the bottleneck, and what is T?
  5. In the comparator, compare peak acceleration for trapezoid, cubic and quintic.
  6. Optional: time the servo moves and compare with the printed T.

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.

Long moves are limited by v_max, short moves by a_max. Smoother profiles cost time. In multi-joint moves the slowest joint decides, and the others are slowed to match.

Knowledge check

Check your understanding

Knowledge check

1. v_max = 120°/s, a_max = 300°/s². A 90° move takes…

2. When does the profile become a triangle?

3. For the same limits, which needs the most time?

4. In a synchronised multi-joint move, who sets the time?

5. To make a long move faster, raise…

6. A 20° move with a_max = 300°/s² (and v_max 120°/s) has peak speed…

7. Which Marlin commands set max feedrate and max acceleration?

Mini assignment

Hands-on assignment

Mini assignment

Limit sheet for your arm

Measure or choose v_max and a_max for each joint of your arm (or the 2-servo arm) and plan a three-point pick-and-place cycle in the shortest legal time.

Deliverables

  • A table of v_max and a_max per joint with how you got them (datasheet or bench test).
  • Joint moves for each segment and, using `limits.py`, the synchronised T for each segment.
  • Total cycle time, and which joint was the bottleneck in each segment.
  • One change (path or limits) that cuts the cycle by at least 10%, with numbers.
  • Optional: run the cycle on the servo arm and compare measured and planned times.

Do this, step by step

  1. Run python3 limits.py. From Part 1, copy the speed-up time and total time for one joint.
  2. Check Part 1 against d ≥ v²/a: is the profile a trapezoid or a triangle?
  3. In Part 3, find the slowest joint and write why it sets the time for all joints.
  4. Change one joint’s limits to your own measured values and re-run. How much does the cycle time change?
  5. Optional bench: in trapezoid_servo.ino, set V_MAX and A_MAX to your servo’s values and time the move with your phone stopwatch.

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. If d < v²/a the joint never reaches v_max, so the profile is a triangle.
  2. Trapezoid total time T = d/v + v/a.
  3. Measure v_max on the bench: time a big move at full speed and divide angle by time; keep a 20% margin.

Challenges (pick by level)

  • 🟢 Easy: v_max = 90°/s, a_max = 180°/s². Is a 30° move a trapezoid or a triangle? Find T.
  • 🟢 Easy: Why do lifts limit acceleration even when they could go faster?
  • 🟡 Medium: Add a jerk-free “smoothing” option to limits.py by computing the shortest quintic instead, and compare cycle times.
  • 🟠 Hard-ish: Plot position, velocity and acceleration of the trapezoid in limits.py (matplotlib or a text plot).
  • 🔴 Hard: Make trapezoid_servo.ino accept a new target while moving (start a new plan from the current position and speed).
  • ⚫ Research: Read *Modern Robotics* §9.4 on time-optimal time scaling along a path and explain in your own words what “bang-bang” means there.

Next step

The trapezoid is fastest, but its acceleration jumps — which means a jerk. In Lesson 12 — Jerk & Smooth Motion you will learn why jerk shakes robots and how to limit it.

Look back: Lesson 10: Orientation Trajectories. Next: Lesson 12: Jerk & Smooth Motion. Related: Stage 4 — Electronics & Embedded Systems.

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