Robotics

Trajectory Planning

Smooth motion that respects speed and accel limits

Trajectory planning is the step that converts a geometric path into a fully timed motion — position, velocity, acceleration and jerk as functions of time — so an actuator travels from one setpoint to the next as fast as possible without ever exceeding its speed, acceleration or jerk limits. The workhorse profiles are the trapezoidal velocity profile (constant accelerate, cruise, decelerate) and the S-curve, which bounds jerk to keep the torque command smooth. The same time-scaling math drives CNC feed scheduling, pick-and-place arms, elevators, surgical robots and the toolhead of every 3D printer.

  • Definesq(t), q̇(t), q̈(t), q⃛(t)
  • Trapezoidal move timeT = 2·v/a + (D − v²/a)/v
  • Triangular peak speedv_pk = √(a·D)
  • S-curve segments7 (jerk-limited)
  • Sample ratetyp. 1 kHz
  • Jerk unitsm/s³ or rad/s³

Interactive visualization

Press play, or step through manually. The visualization is yours to drive — try it before reading on.

Open visualization fullscreen ↗

Watch the 60-second explainer

A condensed visual walkthrough — narrated, captioned, under a minute.

From path to trajectory

A path is purely geometric — the ordered set of configurations the robot passes through, with no clock attached. A trajectory is that path plus a time law q(t), and from the time law everything else follows by differentiation: velocity q̇(t), acceleration q̈(t), and jerk q⃛(t). The planner's job is to choose q(t) so that the motion is fast, smooth, and inside the machine's physical envelope.

Given:  start q0, goal q1, distance D = q1 − q0
Limits: v_max (speed), a_max (accel), j_max (jerk)

Find a time law q(t), t ∈ [0, T], with:
   q(0) = q0,  q(T) = q1
   |q̇(t)|  ≤ v_max     (motor / encoder limit)
   |q̈(t)|  ≤ a_max     (torque limit:  T = J·q̈)
   |q⃛(t)| ≤ j_max     (vibration / shock limit)
   minimize T  (or track a fixed sample clock)

Why these three limits? Speed is capped by the motor's rated rpm and the encoder's countable rate. Acceleration is capped by torque, because for a rotary inertia J the torque is T = J·q̈ — demanding more acceleration than the drive can deliver simply saturates the amplifier. Jerk is capped because torque proportional to acceleration means a step in acceleration is a step in torque, which the current loop cannot produce instantly and which rings every lightly-damped resonance in the belts, couplings and structure.

The trapezoidal velocity profile

The simplest practical profile accelerates at a constant a_max, cruises at v_max, then decelerates at −a_max. Plotted against time, velocity traces a trapezoid; position is the area under it. The move has two regimes:

Distance to reach v_max from rest:  d_ramp = v_max² / (2·a_max)

If  2·d_ramp ≤ D   →   trapezoidal (a cruise phase exists)
    t_a = v_max / a_max                       (accel time)
    d_cruise = D − v_max² / a_max
    t_c = d_cruise / v_max                     (cruise time)
    T   = 2·t_a + t_c

If  2·d_ramp > D    →   triangular (never reaches v_max)
    v_peak = √(a_max · D)
    T      = 2 · √(D / a_max)

Worked example. A SCARA joint must rotate D = 1.5 rad with v_max = 4 rad/s and a_max = 30 rad/s². The ramp distance is 4²/(2·30) = 0.267 rad, so 2·d_ramp = 0.533 rad < 1.5 rad — the move is trapezoidal. Accel time t_a = 4/30 = 0.133 s, cruise distance = 1.5 − 16/30 = 0.967 rad, cruise time = 0.967/4 = 0.242 s, and total T = 2(0.133) + 0.242 = 0.508 s. The same joint asked to move only 0.3 rad would never reach 4 rad/s: it is triangular, peaks at √(30·0.3) = 3.0 rad/s, and finishes in 2·√(0.3/30) = 0.20 s.

S-curve: bounding jerk

The trapezoidal profile's flaw is at the corners. Acceleration jumps from 0 to +a_max instantly, then from +a_max to −a_max at the top of the trapezoid — infinite jerk at each kink. The motor torque mirrors that step exactly, and the mechanism answers with an audible knock and residual ringing that the servo must wait out before the next move.

The S-curve (also called seven-segment, or double-S) fixes this by limiting jerk to a finite j_max. Acceleration now ramps linearly up and down, so the velocity curve gains rounded shoulders shaped like an "S". A full S-curve has seven phases: jerk up, constant accel, jerk down, cruise, jerk down (to decelerate), constant decel, jerk up (to zero). When the move is short, phases drop out — the cruise vanishes first, then the constant-accel segments, leaving a pure jerk-limited "mini-S".

Seven-segment S-curve phases (each bounded by a_max, j_max):
  1. q⃛ = +j_max   accel ramps  0 → a_max
  2. q⃛ = 0        accel held at a_max
  3. q⃛ = −j_max   accel ramps  a_max → 0   (top speed reached)
  4. q⃛ = 0        cruise at v_max
  5. q⃛ = −j_max   accel ramps  0 → −a_max
  6. q⃛ = 0        decel held at −a_max
  7. q⃛ = +j_max   accel ramps  −a_max → 0  (stop)

Extra time vs. trapezoid ≈ a_max / j_max  (per ramp pair)

The price is roughly a_max/j_max of extra duration per acceleration ramp. With a_max = 30 rad/s² and a generous j_max = 600 rad/s³, that is 0.05 s per ramp — about 0.1 s added to the 0.5 s move above. In return, settling time after the move frequently drops by more than that, so the net cycle time often improves while the machine runs quieter and the gears live longer.

Profile comparison

TrapezoidalS-curve (7-seg)Cubic polynomialQuintic polynomialMinimum-time (bang-bang)
Bounds velocityYes (flat top)Yes (flat top)Peak onlyPeak onlyYes
Bounds accelerationYesYesPeak onlyPeak onlyYes (saturated)
Bounds jerkNo (∞ at kinks)YesNo (∞ at ends)Yes (smooth)No (∞)
ContinuityC¹ (vel)C² (accel)C² and beyondC⁰
Move timeNear minimumSlightly longerLongerLongestTheoretical min
Residual vibrationNoticeableLowModerateVery lowSevere
Typical useCNC rapid, basic PLC movesPick-and-place, elevators, packagingSmooth point-to-pointVibration-sensitive optics, waferTextbook only; rarely real

Polynomial trajectories

Instead of stitching constant-jerk segments, you can fit a single polynomial that meets the boundary conditions. A cubic q(t) = a₀ + a₁t + a₂t² + a₃t³ has four coefficients — exactly enough to match start/end position and start/end velocity (typically zero at both ends). Its acceleration is linear and finite, but it has a velocity step problem only at the endpoints if you chain moves.

A quintic q(t) of degree five carries six coefficients, enough to also pin start and end acceleration to zero — giving continuous acceleration (C²) and therefore finite jerk throughout. Quintics are the go-to for vibration-critical motion such as optical scanners and lithography stages, where the cost of a slightly longer move is trivial next to the cost of a smeared exposure.

Quintic with rest-to-rest boundary conditions (D over time T):
  q(t) = q0 + D·[ 10(t/T)³ − 15(t/T)⁴ + 6(t/T)⁵ ]
  q̇(t)  = (D/T)·[ 30τ² − 60τ³ + 30τ⁴ ]        peaks at  1.875·D/T
  q̈(t)  = (D/T²)·[ 60τ − 180τ² + 120τ³ ]       peaks at  5.77·D/T²
  where τ = t/T,  and q̇(0)=q̇(T)=q̈(0)=q̈(T)=0

Note the peak-velocity factor of 1.875: a quintic rest-to-rest move reaches a peak speed almost twice the average speed D/T. Size T so that 1.875·D/T stays under v_max, and 5.77·D/T² stays under a_max, or the drive will saturate mid-move.

Multi-segment and blended trajectories

  • Via points. Real tasks pass through several intermediate poses. Stopping at each one (a sequence of rest-to-rest moves) is simple but slow.
  • Blending. Instead of stopping, the planner rounds the corner between segments with a parabolic or jerk-limited blend, trading a small path deviation (the "corner radius" or CNC look-ahead tolerance) for continuous motion.
  • Linear-segment-with-parabolic-blends (LSPB). The classic industrial scheme: straight constant-velocity legs joined by parabolic blends — effectively a multi-point trapezoidal profile.
  • Spline interpolation. Cubic or B-splines through the via points give C² paths; the time law is then layered on top by reparameterizing arc length.
  • Look-ahead. CNC and printer firmware buffer dozens of upcoming segments so they can pre-plan deceleration into sharp corners and keep feedrate high on gentle ones.

Time scaling: the universal fix

Suppose a planned trajectory turns out to violate a limit — perhaps an inverse-kinematics solution demands a wrist velocity above its rating. Time scaling replaces the time variable t with s·t for a single scalar s > 1, stretching the whole motion uniformly. Position is unchanged at every point along the path, but velocity scales by 1/s, acceleration by 1/s², and jerk by 1/s³. Pick the smallest s that brings every quantity under its limit and you have the fastest feasible version of the exact same path — no replanning of geometry required. This is why path planning and trajectory planning are kept separate: the geometry can be solved once, then time-scaled freely to fit whatever hardware runs it.

Failure modes and trade-offs

  • Velocity/acceleration saturation. Commanding more than the drive can deliver makes actual motion lag the command; following error grows until the controller trips a position-error fault or overshoots the goal. Size the profile to the limits up front.
  • Residual vibration from infinite jerk. Trapezoidal corners excite structural resonances; the arm keeps ringing after it "arrives", forcing a settling delay before the next operation. Bound jerk with an S-curve or quintic.
  • Sampling artifacts. A continuous profile must be discretized at the controller rate (often 1 kHz). Too coarse a sample injects high-frequency content of its own; round-off in the accumulator can leave a sub-count position error at the goal.
  • Over-smoothing. Crank jerk limits too low and cycle time balloons — a packaging line that should run 60 cycles/min drops to 40 for no measurable vibration benefit. Tune j_max to the actual resonance, not to zero.
  • Corner deviation in blends. Blending for speed pulls the path inside sharp corners; on a CNC mill that is a dimensional error, so the tolerance band must be set against the part's spec.
  • Inertia variation. A robot's effective joint inertia changes with configuration and payload, so a profile tuned for one pose may saturate torque in another. Worst-case sizing or online adaptation is needed for arms that carry heavy, variable loads.

Frequently asked questions

What is trajectory planning?

Trajectory planning is the step that turns a geometric path into a fully timed motion. A path tells you which positions to pass through; a trajectory adds the schedule — position, velocity, acceleration and jerk as functions of time — so that an actuator reaches its goal as fast as possible without ever exceeding its speed limit, torque-limited acceleration, or vibration-limited jerk. In practice a planner picks a velocity profile (trapezoidal or S-curve), sizes its segments to the move distance and the limits, and samples it at the controller rate (commonly 1 kHz) to feed the servo loop.

What is the difference between a path and a trajectory?

A path is purely geometric — the ordered set of configurations a robot passes through, with no notion of time. A trajectory is a path plus a time law: it specifies when the robot is at each point, and therefore the velocities and accelerations along the way. Two robots can follow the identical path but with completely different trajectories — one slow and gentle, one fast and aggressive. Path planning answers "where", trajectory planning answers "when and how fast".

Why use an S-curve profile instead of a trapezoidal one?

A trapezoidal velocity profile has constant-acceleration segments, so acceleration jumps instantly at the segment boundaries. That step in acceleration is infinite jerk — the derivative of acceleration — and it slaps the mechanism with an impulsive torque that rings the structure, wears gear teeth, and shows up as residual vibration after the move ends. An S-curve (seven-segment) profile bounds jerk to a finite value, ramping acceleration up and down smoothly. The move takes slightly longer, but settling time often drops enough that net cycle time improves, and audible knock disappears.

What is jerk and why does it matter in motion control?

Jerk is the time derivative of acceleration, measured in m/s³ or rad/s³. Because motor torque is proportional to acceleration (T = Jα for a rotary load), a step change in acceleration is a step change in commanded torque — which the current loop cannot deliver instantly and which excites every lightly-damped resonance in the drivetrain. Limiting jerk smooths the torque command, reduces overshoot and structural ringing, protects couplings and belts from shock, and is essential anywhere a payload can topple, spill or scratch, such as wafer handlers and liquid-filled vials.

How do you compute the duration of a trapezoidal move?

First check whether the move is long enough to reach cruise speed. The distance covered while accelerating from rest to v_max at acceleration a is v_max²/(2a), and the same again to decelerate. If twice that exceeds the total distance D, the profile is triangular — it never cruises — and peak speed is √(a·D). Otherwise the move is trapezoidal: accel time t_a = v_max/a, cruise distance D − v_max²/a, cruise time t_c = (D − v_max²/a)/v_max, and total time T = 2·t_a + t_c. The S-curve adds jerk-limited ramps and a small extra time of order v_max/j_max per blend.

What happens when a planned trajectory exceeds actuator limits?

If the commanded velocity or acceleration exceeds what the drive can deliver, the servo saturates: the actual motion lags the command, following error builds up, and the controller may trip on a position-error fault or, worse, silently fall behind and overshoot the goal. The fix is time scaling — stretch the trajectory's time axis by a single factor so every velocity, acceleration and jerk drops below the limits while the geometric path is preserved exactly. Good planners size the profile to the limits up front so saturation never occurs.