Algorithmintro
Quintic polynomial trajectory
Also called fifth-order polynomial time scaling.
Fits a quintic in time to given positions, velocities and accelerations at both ends, so acceleration is continuous.
- Solves
- Trajectory generation
- Time
- Θ(n m) worst
- Space
- Θ(n m) extra
- Where
- m = the number of segments between via points; n = the number of joints
- Model
- Real RAM
- Properties
- deterministicexactofflinenot randomized
- Evidence
- Proof sketchCode in 1 languages
- Origin
- Tamar Flash, Neville Hogan, 1985
A quintic polynomial trajectory moves one coordinate, such as a robot joint angle, from a start state to an end state in a given time along a polynomial of degree 5 in time. A state here is a position, a velocity and an acceleration, so there are six end conditions, and a quintic has exactly six coefficients. This is the cubic polynomial trajectory with two more conditions: because the end accelerations can be set, the motion can start and stop with zero acceleration, and the acceleration is continuous when several moves are joined. The jerk, the derivative of the acceleration, is then finite everywhere. The rest-to-rest quintic is also the minimum-jerk trajectory, and in cam design it is the 3-4-5 polynomial law of the cam follower motion laws.
In plain words
A cubic move sets where to start and end and how fast, but the push of the motor still jumps at the start and at the end. That jump shakes a robot arm and the load it carries. A quintic adds two more numbers to the curve, so it can also say how hard to push at both ends. Set those to zero and the motor starts pushing gently, pushes harder, then eases off, and the arm arrives with no push left. Six wishes, six numbers, so again there is exactly one curve and a short formula for it. The price is a higher peak speed than the cubic for the same move and time.
The problem
Input: a start state and an end state of position, velocity and acceleration, and a duration . Output: the coefficients of
with , , , , and . For an arm with joints, each joint gets its own quintic with the same . With , and all other end values zero, the result is a time scaling for a move along a fixed path.
The algorithm
Let .
QUINTIC(q0, v0, c0, q1, v1, c1, T) ▷ T > 0, h = q1 - q0- 1
a0 ← q0; a1 ← v0; a2 ← c0 / 2 - 2
a3 ← (20h - (8 v1 + 12 v0) T - (3 c0 - c1) T²) / (2T³) - 3
a4 ← (-30h + (14 v1 + 16 v0) T + (3 c0 - 2 c1) T²) / (2T⁴) - 4
a5 ← (12h - 6 (v1 + v0) T + (c1 - c0) T²) / (2T⁵) - 5
return (a0, ..., a5) QUINTIC-EVAL(a, t, k)- 6
for each derivative order 0, 1, ..., k, evaluate it by Horner's rule REST-TO-REST(q0, q1, T, t)- 7
τ ← t / T; return q0 + (q1 - q0)(10τ³ - 15τ⁴ + 6τ⁵)
Line L1 reads the start state off the polynomial at . Lines L2 to L4 are the solution of the remaining linear system for the end state at , written out in closed form. Line L7 is the special case with zero end velocities and accelerations.
Example
The rest-to-rest profile. With and a unit move, lines L2 to L4 give , , :
The peak velocity is . The peak acceleration is at . The jerk is at both ends. Compare the cubic : its peak velocity is and its acceleration is at the ends, so the quintic is faster in the middle but starts with zero acceleration.
Nonzero start velocity. Take m, m/s, m, the other end values zero, and s, so .
- L1: , , .
- L2: .
- L3: .
- L4: .
So . Check: . The acceleration is zero at both ends, as required, and also at s, where the velocity has its peak m/s. The cubic with the same positions and velocities has the acceleration m/s² at the start and m/s² at the end.
Correctness
Putting and into , and with the coefficients of lines L1 to L4 gives back the six end conditions, which is a direct check. No other polynomial of degree at most 5 meets them: the difference of two would have triple roots at and , so , of degree 6, would divide it, and it would be zero. The proof gives the coefficient check and derives the values of the rest-to-rest example. The same uniqueness argument with the cost shows that the quintic is the motion of least integrated squared jerk for its six end conditions; that is the theorem of the minimum-jerk trajectory page.
Proof: The quintic meets the six end conditions and is the only quintic that doesfull
We use the notation of the page. The input is the start state , the end state of position, velocity and acceleration, and a duration . Let . Line L1 sets , and , and lines L2 to L4 set
The trajectory is on . The proof is in exact arithmetic.
The start conditions
, and , directly.
The end conditions
Let , and . Then
Each of is half of a combination of , , , and . The table gives the coefficients of these five terms in , , and in the three sums.
| 20 | 1 | ||||
| 14 | 16 | 3 | |||
| 12 | 1 | ||||
| 2 | 0 | 0 | |||
| 0 | 2 | 0 | |||
| 0 | 0 | 0 | 2 |
So , , and . Putting these into the three lines above gives , and . Since , and .
Uniqueness
Let be the difference of two polynomials of degree at most 5 that meet the six conditions. Then , and vanish at and at , so and are roots of multiplicity at least 3, and divides . That product has degree 6, so . So the linear system of the six conditions is nonsingular for , and the formulas above are its solution.
The rest-to-rest profile
With , and zero end velocities and accelerations, the formulas give , , , so , which is line L7. Its derivatives are
The velocity is not negative on , so rises from 0 to 1 without overshoot. Its largest value is at , where . The acceleration has its extremes where , at . There and , so . The jerk at both ends is . For a move of length in time the values scale by , and .
Complexity
In the real RAM, one call of QUINTIC costs a fixed number of operations, about 40, so time and space. Evaluating all derivatives up to order 3 costs about 20 multiplications. An arm with joints and segments needs time and stores coefficients.
Properties
- Acceleration continuous. Joined quintics are at via points when each via point gets one velocity and one acceleration. The jerk is finite but jumps, from 0 to 60 at the start of a rest-to-rest move.
- Minimum integrated squared jerk. A theorem (Flash and Hogan 1985): for its six end conditions, the quintic is the unique minimizer of .
- Peaks of the rest-to-rest move. For a distance in time : velocity , acceleration , jerk . These are exact values (theorems), from the example.
- Linear in the data. For a fixed , the coefficients are linear in the six end values.
- Overshoot. Large end velocities or accelerations compared with make the motion leave the interval between and .
Variants and improvements
- Higher degree. A polynomial of degree 7 also sets the end jerks; it is the single-segment minimum-snap trajectory. Each step up raises the peak velocity: , and times for degrees 3, 5 and 7.
- Via points. One quintic per segment with given velocities and accelerations at the via points. Choosing them to minimize a cost over all segments gives smoothing splines such as the minimum-snap method.
- Jerk-limited profiles. If the move must be as fast as possible under limits on the velocity, the acceleration and the jerk, the double-S velocity profile is faster, because it can spend most of the time at the limits.
- Choosing T. For a rest-to-rest move under and , the smallest feasible time is .
When to use it
Use a quintic for point-to-point moves of a joint or as the time scaling of a path when the acceleration must be continuous, for example with an elastic arm, a heavy load, or liquid in a container. It is also the standard model of a human-like reaching motion, and a common choice for a short motion primitive that must join another motion at a given state. If the motion must be as fast as possible under fixed limits, use a trapezoidal or a double-S profile instead; a quintic reaches its limits only at one instant.
Pitfalls
- Same T for all joints. If each joint gets its own duration, the joints do not arrive together, and the path is not the intended one.
- Check the limits after choosing T. The formulas accept any ; the peaks grow as , and .
- Typing the closed form. The coefficients of lines L2 to L4 are easy to mistype. Test them with exact fractions against the six end conditions, as the tests of this page do.
- Local time. Each segment uses its own local time ; evaluate it there.
- Floating point for small T. The divisions by amplify rounding when is small and the end values are large. Scale time to in that case.
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.
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/quintic-polynomial-trajectory/. The authors are listed in prov/JZFXGC.jsonl.
"""Quintic polynomial trajectory of one joint.
quintic_coeffs(q0, v0, c0, q1, v1, c1, T) returns (a0, ..., a5) of
q(t) = a0 + a1 t + ... + a5 t^5 on [0, T], with position q, velocity v
and acceleration c given at t = 0 and t = T. The arithmetic is exact
when the inputs are fractions.Fraction values.
"""
def quintic_coeffs(q0, v0, c0, q1, v1, c1, T):
"""Coefficients of the quintic that meets the six end conditions."""
if T <= 0:
raise ValueError("T must be positive")
h = q1 - q0
a0 = q0 # @line L1
a1 = v0
a2 = c0 / 2
a3 = (20 * h - (8 * v1 + 12 * v0) * T - (3 * c0 - c1) * T ** 2) / (2 * T ** 3) # @line L2
a4 = (-30 * h + (14 * v1 + 16 * v0) * T + (3 * c0 - 2 * c1) * T ** 2) / (2 * T ** 4) # @line L3
a5 = (12 * h - 6 * (v1 + v0) * T + (c1 - c0) * T ** 2) / (2 * T ** 5) # @line L4
return (a0, a1, a2, a3, a4, a5) # @line L5
def quintic_eval(a, t, order=3):
"""Return the list [q, q', q'', ...] of the first `order` + 1 derivatives at t."""
out = []
coeffs = list(a)
for _ in range(order + 1): # @line L6
val = 0
for c in reversed(coeffs): # Horner's rule
val = val * t + c
out.append(val)
coeffs = [i * coeffs[i] for i in range(1, len(coeffs))] or [0]
return out
def rest_to_rest(q0, q1, T, t):
"""The quintic with zero end velocities and accelerations: q0 + (q1 - q0) s(t / T)."""
tau = t / T
s = tau ** 3 * (10 - 15 * tau + 6 * tau ** 2) # @line L7
return q0 + (q1 - q0) * s
test_quintic_polynomial_trajectory.py 97 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/quintic-polynomial-trajectory/. The authors are listed in prov/JZFXGC.jsonl.
"""Tests: exact end conditions, a second method (linear solve), and the check values."""
import math
import random
from fractions import Fraction as F
from quintic_polynomial_trajectory import quintic_coeffs, quintic_eval, rest_to_rest
def solve(m, b):
"""Gauss-Jordan elimination in exact arithmetic (the second method)."""
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 row(t, d):
"""Row of the d-th derivative of (1, t, ..., t^5) at t."""
out = []
for k in range(6):
if k < d:
out.append(F(0))
else:
out.append(F(math.perm(k, d)) * F(t) ** (k - d))
return out
def rand_frac(rng):
return F(rng.randint(-30, 30), rng.randint(1, 7))
def test_end_conditions_exact():
rng = random.Random(11)
for _ in range(200):
q0, v0, c0, q1, v1, c1 = (rand_frac(rng) for _ in range(6))
T = F(rng.randint(1, 30), rng.randint(1, 7))
a = quintic_coeffs(q0, v0, c0, q1, v1, c1, T)
assert quintic_eval(a, F(0), 2) == [q0, v0, c0]
assert quintic_eval(a, T, 2) == [q1, v1, c1]
def test_against_linear_solve():
rng = random.Random(12)
for _ in range(60):
vals = [rand_frac(rng) for _ in range(6)]
T = F(rng.randint(1, 9), rng.randint(1, 3))
m = [row(0, 0), row(0, 1), row(0, 2), row(T, 0), row(T, 1), row(T, 2)]
assert list(quintic_coeffs(*vals, T)) == solve(m, vals)
def test_check_values():
a = quintic_coeffs(F(0), F(0), F(0), F(1), F(0), F(0), F(1))
assert a == (0, 0, 0, 10, -15, 6)
assert quintic_eval(a, F(1, 2), 1)[1] == F(15, 8)
assert quintic_eval(a, F(0), 3)[3] == 60
assert quintic_eval(a, F(1), 3)[3] == 60
t_star = (3 - math.sqrt(3)) / 6
af = tuple(float(x) for x in a)
assert abs(t_star - 0.2113) < 1e-4
assert abs(quintic_eval(af, t_star, 2)[2] - 10 / math.sqrt(3)) < 1e-12
assert abs(10 / math.sqrt(3) - 5.7735) < 1e-4
grid = [quintic_eval(af, k / 10000, 2) for k in range(10001)]
assert max(g[1] for g in grid) <= 1.875 + 1e-12
assert max(g[2] for g in grid) <= 10 / math.sqrt(3) + 1e-12
assert min(g[2] for g in grid) >= -10 / math.sqrt(3) - 1e-12
def test_rest_to_rest_matches():
q0, q1, T = F(2), F(-3), F(5, 2)
a = quintic_coeffs(q0, F(0), F(0), q1, F(0), F(0), T)
for k in range(11):
t = T * k / 10
assert quintic_eval(a, t, 0)[0] == rest_to_rest(q0, q1, T, t)
def test_float_inputs():
a = quintic_coeffs(0.5, 1.0, -2.0, 1.5, 0.0, 0.0, 1.5)
got = quintic_eval(a, 1.5, 2)
assert max(abs(x - y) for x, y in zip(got, [1.5, 0.0, 0.0])) < 1e-12
def test_bad_input():
try:
quintic_coeffs(0, 0, 0, 1, 0, 0, 0)
except ValueError:
pass
else:
raise AssertionError("T = 0 must fail")
History
Polynomials in time were the standard way to plan joint trajectories in the first robot controllers, and the quintic was used where the cubic gave unacceptable acceleration jumps; its first use is not traced here. Flash and Hogan (1985) proposed that human arm movements minimize the integrated squared jerk, showed that for a rest-to-rest move the optimum is the quintic , and compared it with measured planar arm movements. Lynch and Park (2017) present the quintic as the fifth-order polynomial time scaling.
References
- Kevin M. Lynch and Frank C. Park, Modern Robotics, Mechanics, Planning, and Control, Cambridge University Press, 2017, Chapter 9, Section 9.2.2 (time scaling a straight-line path)
- Luigi Biagiotti and Claudio Melchiorri, Trajectory Planning for Automatic Machines and Robots, Springer, 2008, Chapter 2 (analytic expressions of elementary trajectories, polynomial trajectories)
- Tamar Flash and Neville Hogan, The coordination of arm movements, an experimentally confirmed mathematical model, Journal of Neuroscience 5(7), 1985, 1688-1703, the whole paper (the minimum-jerk model and its fifth-order polynomial solution)
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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H1 sketch |
|
| Lean | L0 no Lean part |
|
| Code (python) | I0 not checked yet |
|
| Visual | V0 none |
|
| Writing | W2 basic |
|
Tag JZFXGC Edit this page History Report an error Markdown