Algorithm Search⌘K

Algorithmcore

Minimum-jerk trajectory

Also called Flash-Hogan minimum jerk model.

The motion that minimizes the integral of squared jerk; for a rest-to-rest move it is a quintic, which Flash and Hogan fitted to measured human reaching.

Time
Θ(d) worst
Space
Θ(d) extra
Where
d = the number of coordinates
Properties
deterministicexactofflinenot randomized
Origin
Tamar Flash, Neville Hogan, 1985

A minimum-jerk trajectory is the motion from a start state to an end state in a fixed time TT that makes the integral of the squared jerk as small as possible. Jerk is the third derivative of the position, the rate at which the acceleration changes, and a motion with little jerk looks smooth and puts little strain on a machine. The answer is a polynomial of degree 5 in time in each coordinate. For a move from rest to rest it is x(t)=x0+(xf−x0)(10τ3−15τ4+6τ5)x(t) = x_0 + (x_f - x_0)(10\tau^3 - 15\tau^4 + 6\tau^5) with τ=t/T\tau = t/T, so the path is a straight segment and the speed has a bell shape. Flash and Hogan (1985) proposed this cost as a model of human arm movement, and the model fitted their measurements of planar reaching well. That is a measured fit, not a theorem about the brain. In robotics the same formula is used to make robot motion look natural and to give a smooth default for point-to-point moves. It is the quintic polynomial trajectory with a reason attached, and in cam design it is the 3-4-5 polynomial law of the cam follower motion laws.

In plain words

When you reach for a cup, your hand travels in a nearly straight line, speeds up smoothly, and slows down smoothly, with the top speed near the middle. Researchers asked what rule could produce that. One answer: the hand moves so that its acceleration changes as little and as gently as possible over the whole move. Make that idea exact, and a short calculation gives a single formula, a curve of degree five in time. The formula needs only the start point, the end point and the duration. Robots use it for the same reason people seem to: it is smooth, it is cheap to compute, and it looks natural.

The problem

Input: a start point x0x_0 and an end point xfx_f in Rd\mathbb R^d, and a duration T>0T > 0; more generally, a start state and an end state of position, velocity and acceleration in each coordinate. Output: the motion x(t)x(t) on [0,T][0, T] with the given end states that minimizes

J(x)=∫0T∥x...(t)∥2 dt.J(x) = \int_0^T \|\dddot x(t)\|^2\, dt.

The end conditions fix the position, the velocity and the acceleration at both ends, six numbers per coordinate. The cost and the conditions do not couple the coordinates, so each coordinate is its own problem.

The algorithm

  1. MIN-JERK(x0, xf, T, t) ▷ rest to rest, x0, xf in R^d
  2. 1τ ← t / T
  3. 2s ← τ³ (10 - 15τ + 6τ²)
  4. 3ṡ ← 30 τ² (1 - τ)² / T
  5. 4s̈ ← 60 τ (1 - τ)(1 - 2τ) / T²
  6. 5return (x0 + s (xf - x0), ṡ (xf - x0), s̈ (xf - x0))
  7. MIN-JERK-BOUNDARY(p0, v0, c0, p1, v1, c1, T) ▷ one coordinate, general end states
  8. 6return the quintic with these six end values (lines L1 to L5 of QUINTIC)

Lines L1 to L4 compute the normalized profile s(τ)s(\tau) and its time derivatives. Line L5 scales it by the displacement in every coordinate, so all coordinates arrive together along a straight line. Line L6 is the general case; its coefficients are the closed forms of the quintic polynomial trajectory.

Example

A hand moves from x0=(0,0)x_0 = (0, 0) m to xf=(0.3,0.4)x_f = (0.3, 0.4) m in T=1T = 1 s, a distance D=0.5D = 0.5 m.

  • At t=0.25t = 0.25 s: τ=0.25\tau = 0.25 and s=0.015625⋅6.625≈0.1035s = 0.015625 \cdot 6.625 \approx 0.1035, so the hand is at (0.0311,0.0414)(0.0311, 0.0414) m, about a tenth of the way.
  • At t=0.5t = 0.5 s: s=0.5s = 0.5, the hand is half way, and the speed is at its peak 1.875⋅0.5=0.93751.875 \cdot 0.5 = 0.9375 m/s.
  • The acceleration peaks at τ=(3−3)/6≈0.211\tau = (3 - \sqrt 3)/6 \approx 0.211 with (10/3)⋅0.5≈2.887(10/\sqrt 3) \cdot 0.5 \approx 2.887 m/s², and the jerk is 60⋅0.5=3060 \cdot 0.5 = 30 m/s³ at both ends.
  • The cost is 720D2/T5=180720 D^2 / T^5 = 180 m²/s⁵.

The bell-shaped speed 30τ2(1−τ)230\tau^2(1 - \tau)^2 is symmetric about the middle and starts and ends with zero slope, because the acceleration is zero at both ends.

Correctness

Theorem: for its six end conditions, the quintic of line L6 is the unique minimizer of JJ among all motions with square-integrable jerk. The proof writes any competitor as x∗+ηx^* + \eta, where η\eta and its first two derivatives vanish at both ends. Three integrations by parts show that the cross term ∫x∗′′′η′′′\int x^{*\prime\prime\prime} \eta''' is zero, because the sixth derivative of a quintic is zero. So J(x∗+η)=J(x∗)+J(η)J(x^* + \eta) = J(x^*) + J(\eta), and J(η)>0J(\eta) > 0 unless η=0\eta = 0. This is the Euler-Lagrange equation x(6)=0x^{(6)} = 0 of the cost, and the identity shows directly that its solution is the minimum. The proof also computes the cost 720D2/T5720 D^2 / T^5 of the rest-to-rest move.

Proof: The quintic is the unique minimizer of the integral of squared jerkfull

We use the notation of the page. Fix T>0T > 0 and the six end values x(0)=p0x(0) = p_0, x′(0)=v0x'(0) = v_0, x′′(0)=c0x''(0) = c_0, x(T)=p1x(T) = p_1, x′(T)=v1x'(T) = v_1, x′′(T)=c1x''(T) = c_1 of one coordinate. Let X\mathcal X be the set of functions on [0,T][0, T] with these end values whose third derivative is square integrable. The cost is

J(x)=∫0Tx′′′(t)2 dt.J(x) = \int_0^T x'''(t)^2\, dt.

Line L6 returns the coefficients of the quintic x∗x^* with these six end values. The page of the quintic polynomial trajectory proves that this quintic exists, is unique, and that the closed form of line L6 gives it.

The quintic is the unique minimizer

Theorem 1. For every x∈Xx \in \mathcal X, J(x)=J(x∗)+J(x−x∗)J(x) = J(x^*) + J(x - x^*). So J(x)≥J(x∗)J(x) \ge J(x^*), with equality only for x=x∗x = x^*.

Proof. Let η=x−x∗\eta = x - x^*. Then η\eta, η′\eta' and η′′\eta'' vanish at 00 and at TT, and

J(x)=J(x∗)+2∫0Tx∗′′′η′′′ dt+J(η).J(x) = J(x^*) + 2\int_0^T x^{*\prime\prime\prime} \eta'''\, dt + J(\eta).

Integrate the middle integral by parts three times:

∫0Tx∗(3)η(3)=[x∗(3)η′′]0T−[x∗(4)η′]0T+[x∗(5)η]0T−∫0Tx∗(6)η dt.\int_0^T x^{*(3)} \eta^{(3)} = \big[x^{*(3)} \eta''\big]_0^T - \big[x^{*(4)} \eta'\big]_0^T + \big[x^{*(5)} \eta\big]_0^T - \int_0^T x^{*(6)} \eta\, dt.

The three brackets are zero because η′′\eta'', η′\eta' and η\eta vanish at both ends. The last integral is zero because x∗x^* has degree 5, so x∗(6)=0x^{*(6)} = 0. This proves the identity. If J(η)=0J(\eta) = 0, then η′′′=0\eta''' = 0 almost everywhere, so η\eta is a polynomial of degree at most 2. Then η(0)=η′(0)=η′′(0)=0\eta(0) = \eta'(0) = \eta''(0) = 0 forces its three coefficients to be zero, so η=0\eta = 0. □\square

This is the Euler-Lagrange equation x(6)=0x^{(6)} = 0 of the cost, solved with its natural boundary data; the identity also shows that the stationary point is a minimum, with no extra argument.

Several coordinates

The cost of a motion in Rd\mathbb R^d is the sum of the costs of the coordinates, and the end conditions do not couple them. So the minimizer is the quintic minimizer in each coordinate, and the theorem applies to each. For a rest-to-rest move all coordinates follow the same profile s(τ)s(\tau), scaled by their displacements, so the path is the straight segment from x0x_0 to xfx_f. This is lines L1 to L5.

The rest-to-rest profile and its cost

With zero end velocities and accelerations, line L6 gives s(τ)=10τ3−15τ4+6τ5s(\tau) = 10\tau^3 - 15\tau^4 + 6\tau^5 with τ=t/T\tau = t/T, as on the quintic page. Its derivatives in tt are lines L3 and L4:

x˙=DT 30τ2(1−τ)2,x¨=DT2 60τ(1−τ)(1−2τ),\dot x = \frac{D}{T}\, 30\tau^2(1 - \tau)^2, \qquad \ddot x = \frac{D}{T^2}\, 60\tau(1 - \tau)(1 - 2\tau),

for a displacement DD. The jerk is DT360(6τ2−6τ+1)\frac{D}{T^3} 60(6\tau^2 - 6\tau + 1). The polynomial 6τ2−6τ+16\tau^2 - 6\tau + 1 is the shifted Legendre polynomial P2(2τ−1)P_2(2\tau - 1), whose square has the integral 1/51/5 over [0,1][0, 1]. So

J(x∗)=∫0T(60DT3)2P2(2t/T−1)2 dt=3600D2T6⋅T5=720D2T5.J(x^*) = \int_0^T \Big(\frac{60D}{T^3}\Big)^2 P_2(2t/T - 1)^2\, dt = \frac{3600 D^2}{T^6} \cdot \frac{T}{5} = \frac{720 D^2}{T^5}.

Complexity

In the real RAM, one sample of a rest-to-rest move in dd coordinates costs Θ(d)\Theta(d) operations, and line L6 costs Θ(1)\Theta(1) per coordinate. No optimization is run: the calculus of variations has solved the problem once, in closed form.

Properties

  • Straight line, bell-shaped speed. For a rest-to-rest move, the path is the segment from x0x_0 to xfx_f, and the speed is DT30τ2(1−τ)2\frac{D}{T} 30\tau^2(1 - \tau)^2, with peak 1.875 D/T1.875\, D/T at the middle (theorems).
  • Cost. J=720D2/T5J = 720 D^2 / T^5 for a rest-to-rest move of length DD: halving the time multiplies the cost by 32.
  • Fit to human reaching. Flash and Hogan reported that the model predicts the straight paths and the bell-shaped speed profiles of their subjects' planar reaching movements. This is a measurement on their data, and other costs have been proposed for movements that it fits less well.
  • Kinematic only. The model uses no masses, torques or motor limits. It does not guarantee that a robot can follow it.
  • Duration is an input. The cost decreases without bound as TT grows, so the model cannot choose TT.

Variants and improvements

  • Via points. Flash and Hogan also treated movements through a via point. The optimum is then a piecewise polynomial of degree 5, and the time at the via point is part of the optimization.
  • Minimum snap. Replace the third derivative by the fourth. For a quadrotor the snap is linked to the motor inputs, which gives the minimum-snap trajectory.
  • Minimum acceleration. Replace it by the second derivative: the cubic is the minimizer for its four end conditions.
  • Limits. If velocity, acceleration and jerk limits must be met in minimum time, use the double-S velocity profile instead.
  • Learning motions. Dynamic movement primitives are often tested on minimum-jerk demonstrations; they reproduce a motion and adapt it to new goals.
  • General costs. Trajectory optimization minimizes any cost with any dynamics and limits numerically.

When to use it

Use the minimum-jerk formula for smooth point-to-point motions of a robot arm or hand where the duration is given and the limits are loose: service and social robots, robots that move near people, and animation. Use it as a model or a baseline in studies of human movement. Use the double S or a time-optimal method if the motion must be as fast as possible under limits.

Pitfalls

  • Comparing costs with different end conditions. A cubic rest-to-rest move has the constant jerk 12D/T312D/T^3 inside (0,T)(0, T), so its integral is 144D2/T5144 D^2/T^5, smaller than 720D2/T5720 D^2/T^5. That does not beat the theorem: the cubic does not meet the zero end accelerations, and its acceleration jumps at the ends, so its jerk there is unbounded.
  • Assuming it is time-optimal. It is not. With the same peak velocity, a trapezoid or a double S is faster.
  • Applying it in joint space and expecting a straight hand path. The straight-line result holds in the space where the cost is computed. In joint space, the hand path of an arm is curved.
  • Treating the human fit as a law. The fit is a measurement on a class of movements, not a principle that holds for every task.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

minimum_jerk_trajectory.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/minimum-jerk-trajectory/. The authors are listed in prov/V2PYYM.jsonl.
"""Minimum-jerk trajectory.

min_jerk(x0, xf, T, t) is the motion of Flash and Hogan (1985) from rest at
the point x0 to rest at the point xf in time T. Points are lists of
coordinates; each coordinate follows the same scalar profile, so the path is
the straight segment from x0 to xf.

min_jerk_boundary(...) is the minimizer for general end positions,
velocities and accelerations of one coordinate: a quintic polynomial.
jerk_cost(coeffs, T) is the integral of the squared third derivative.
"""


def min_jerk(x0, xf, T, t):
    """Return (x, x', x'') at time t of the rest-to-rest minimum-jerk motion."""
    if T <= 0:
        raise ValueError("T must be positive")
    tau = t / T  # @line L1
    s = tau ** 3 * (10 - 15 * tau + 6 * tau * tau)  # @line L2
    ds = 30 * tau ** 2 * (1 - tau) ** 2 / T  # @line L3
    dds = 60 * tau * (1 - tau) * (1 - 2 * tau) / (T * T)  # @line L4
    d = [b - a for a, b in zip(x0, xf)]
    return ([a + e * s for a, e in zip(x0, d)], [e * ds for e in d], [e * dds for e in d])  # @line L5


def min_jerk_boundary(p0, v0, c0, p1, v1, c1, T):
    """Coefficients (a0, ..., a5) of the minimum-jerk motion with general end states.

    The minimizer is the unique quintic that meets the six end conditions;
    these are the closed form coefficients of that quintic.
    """
    if T <= 0:
        raise ValueError("T must be positive")
    h = p1 - p0
    a3 = (20 * h - (8 * v1 + 12 * v0) * T - (3 * c0 - c1) * T ** 2) / (2 * T ** 3)  # @line L6
    a4 = (-30 * h + (14 * v1 + 16 * v0) * T + (3 * c0 - 2 * c1) * T ** 2) / (2 * T ** 4)
    a5 = (12 * h - 6 * (v1 + v0) * T + (c1 - c0) * T ** 2) / (2 * T ** 5)
    return (p0, v0, c0 / 2, a3, a4, a5)


def poly_eval(a, t, d=0):
    """Value at t of the d-th derivative of the polynomial with coefficients a."""
    c = list(a)
    for _ in range(d):
        c = [i * c[i] for i in range(1, len(c))] or [0]
    v = 0
    for x in reversed(c):
        v = v * t + x
    return v


def jerk_cost(a, T):
    """Integral over [0, T] of the square of the third derivative of the polynomial a."""
    c = list(a)
    for _ in range(3):
        c = [i * c[i] for i in range(1, len(c))] or [0]
    total = 0
    for i, x in enumerate(c):
        for j, y in enumerate(c):
            total += x * y * T ** (i + j + 1) / (i + j + 1)
    return total
test_minimum_jerk_trajectory.py 108 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/minimum-jerk-trajectory/. The authors are listed in prov/V2PYYM.jsonl.
"""Tests: end states, the cost 720 D^2 / T^5, perturbations, and a direct minimization over degree 9."""

import math
import random
from fractions import Fraction as F

from minimum_jerk_trajectory import jerk_cost, min_jerk, min_jerk_boundary, poly_eval


def solve(m, b):
    """Gauss-Jordan elimination in exact arithmetic."""
    n = len(m)
    a = [[F(x) for x in m[i]] + [F(b[i])] for i in range(n)]
    for c in range(n):
        p = next(r for r in range(c, n) if a[r][c] != 0)
        a[c], a[p] = a[p], a[c]
        for r in range(n):
            if r != c and a[r][c] != 0:
                f = a[r][c] / a[c][c]
                a[r] = [x - f * y for x, y in zip(a[r], a[c])]
    return [a[i][n] / a[i][i] for i in range(n)]


def deriv_row(t, d, deg):
    return [F(math.perm(k, d)) * F(t) ** (k - d) if k >= d else F(0) for k in range(deg + 1)]


def test_rest_to_rest_end_states():
    x0, xf, T = [F(0), F(1), F(-2)], [F(3), F(1), F(2)], F(2)
    assert min_jerk(x0, xf, T, F(0)) == (x0, [0, 0, 0], [0, 0, 0])
    assert min_jerk(x0, xf, T, T) == (xf, [0, 0, 0], [0, 0, 0])
    x, v, _ = min_jerk(x0, xf, T, T / 2)
    assert x == [F(3, 2), F(1), F(0)]
    # Peak speed 1.875 D / T at the middle, along the straight line.
    assert v == [F(15, 8) * 3 / 2, 0, F(15, 8) * 4 / 2]


def test_cost_formula():
    for D, T in ((F(1), F(1)), (F(3), F(2)), (F(-2), F(1, 2))):
        a = min_jerk_boundary(F(0), F(0), F(0), D, F(0), F(0), T)
        assert jerk_cost(a, T) == 720 * D * D / T ** 5


def test_general_end_states():
    rng = random.Random(31)
    for _ in range(100):
        vals = [F(rng.randint(-9, 9), rng.randint(1, 5)) for _ in range(6)]
        T = F(rng.randint(1, 9), rng.randint(1, 3))
        a = min_jerk_boundary(*vals, T)
        assert [poly_eval(a, F(0), d) for d in range(3)] == vals[:3]
        assert [poly_eval(a, T, d) for d in range(3)] == vals[3:]


def test_perturbations_cost_more():
    # Every other smooth motion with the same end states is a + eta, with
    # eta = t^3 (T - t)^3 r(t). The cross term vanishes, so the cost grows by the cost of eta.
    rng = random.Random(32)
    for _ in range(30):
        T = F(rng.randint(1, 4))
        vals = [F(rng.randint(-5, 5)) for _ in range(6)]
        a = list(min_jerk_boundary(*vals, T))
        base = [F(0), F(0), F(0), T ** 3, -3 * T ** 2, 3 * T, F(-1)]  # t^3 (T - t)^3
        r = [F(rng.randint(-3, 3)) for _ in range(3)]
        if not any(r):
            continue
        eta = [F(0)] * (len(base) + len(r) - 1)
        for i, x in enumerate(base):
            for j, y in enumerate(r):
                eta[i + j] += x * y
        other = [x + y for x, y in zip(a + [F(0)] * (len(eta) - len(a)), eta)]
        assert jerk_cost(other, T) == jerk_cost(a, T) + jerk_cost(eta, T)
        assert jerk_cost(other, T) > jerk_cost(a, T)


def test_direct_minimization_degree_nine():
    # Minimize the jerk cost over all polynomials of degree <= 9 with the six
    # end conditions, by the KKT system of the quadratic program. The answer is the quintic.
    deg = 9
    rng = random.Random(33)
    for _ in range(3):
        T = F(rng.randint(1, 3))
        vals = [F(rng.randint(-4, 4)) for _ in range(6)]
        n = deg + 1
        Q = [[F(0)] * n for _ in range(n)]
        for i in range(3, n):
            for j in range(3, n):
                ci = math.perm(i, 3)
                cj = math.perm(j, 3)
                Q[i][j] = F(ci * cj) * T ** (i + j - 5) / (i + j - 5)
        rows = [deriv_row(0, d, deg) for d in range(3)] + [deriv_row(T, d, deg) for d in range(3)]
        kkt = [[2 * Q[i][j] for j in range(n)] + [rows[k][i] for k in range(6)] for i in range(n)]
        kkt += [rows[k] + [F(0)] * 6 for k in range(6)]
        sol = solve(kkt, [F(0)] * n + vals)
        quintic = list(min_jerk_boundary(*vals, T))
        assert sol[:n] == quintic + [F(0)] * (n - 6)


def test_float_and_bad_input():
    x, v, c = min_jerk([0.0], [0.3], 0.8, 0.4)
    assert abs(x[0] - 0.15) < 1e-15 and abs(c[0]) < 1e-12
    try:
        min_jerk([0.0], [1.0], 0.0, 0.0)
    except ValueError:
        pass
    else:
        raise AssertionError("T = 0 must fail")

History

Hogan (1984) proposed that single-joint arm movements minimize the integrated squared jerk. Flash and Hogan (1985) extended the model to planar multi-joint reaching, solved it in closed form, and compared the predicted paths and speed profiles with measured movements, including movements through a via point. The model became a standard reference in motor control and a common way to generate human-like robot motion. In cam design, the same polynomial was already in use as the 3-4-5 law.

References

  1. Tamar Flash and Neville Hogan, The coordination of arm movements, an experimentally confirmed mathematical model, Journal of Neuroscience 5(7), 1985, 1688-1703, the minimum-jerk cost, its fifth-order polynomial solution for a rest-to-rest move, and the comparison with measured planar arm movements
  2. Neville Hogan, An organizing principle for a class of voluntary movements, Journal of Neuroscience 4(11), 1984, 2745-2754, the jerk criterion for single-joint movements
  3. Luigi Biagiotti and Claudio Melchiorri, Trajectory Planning for Automatic Machines and Robots, Springer, 2008, Chapter 2 (polynomial trajectories)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example