Algorithm Search⌘K

Algorithmcore

Double-S velocity profile

Also called S-curve velocity profile, seven-segment jerk-limited profile.

A point-to-point motion with bounded jerk, acceleration and velocity, made of up to seven segments of constant jerk.

Time
Θ(n) worst
Space
Θ(n) extra
Where
n = the number of axes
Properties
deterministicexactofflinenot randomized

A double-S velocity profile moves one axis over a distance DD from rest to rest with the velocity at most VV, the acceleration at most AA and the jerk, the rate of change of the acceleration, at most JJ in size. The jerk is piecewise constant, taking the values +J+J, 00 and −J-J, so the acceleration is piecewise linear and continuous, and the velocity plotted against time has two smooth S-shaped bends, one when speeding up and one when slowing down. This is the trapezoidal velocity profile with each jump of the acceleration replaced by a ramp of slope JJ. Seven segments result: three to accelerate, one to cruise, three to decelerate. Some segments have zero length when a limit is not reached. The profile is the standard motion of servo drives and CNC machines, where feedrate scheduling uses it along the tool path, because the bounded jerk avoids the vibration that the trapezoid causes.

In plain words

The trapezoid profile switches the motor force on and off at once. A machine is a little elastic, so each sudden switch makes it ring like a struck bell. The double S profile turns the force up and down gradually, at a fixed maximum rate. So a move has seven parts: force rising, force held, force falling to zero, cruising, and the same three in reverse to stop. If the move is short, some parts vanish: the force may never reach its maximum, or the speed may never reach its maximum. The price is a little time. When the speed and force limits are both reached, the move is longer than the trapezoid by exactly the time it takes to ramp the force up once.

The problem

Input: a distance D>0D > 0 and limits V,A,J>0V, A, J > 0. Output: a motion s(t)s(t) on [0,T][0, T] with s(0)=0s(0) = 0, s(T)=Ds(T) = D, zero velocity and acceleration at both ends, ∣s′∣≤V|s'| \le V, ∣s′′∣≤A|s''| \le A and ∣s′′′∣≤J|s'''| \le J, whose jerk is piecewise constant with values in {−J,0,J}\{-J, 0, J\}. The deceleration phase is the mirror image of the acceleration phase. The general form, with nonzero end velocities and different limits for speeding up and slowing down, is in Biagiotti and Melchiorri, Section 3.4; this page covers the rest-to-rest case of their Section 3.4.3.

The algorithm

The acceleration phase has jerk +J+J for TjT_j, jerk 00 for Ta−2TjT_a - 2T_j and jerk −J-J for TjT_j. It ends at the peak velocity vpv_p and covers vpTa/2v_p T_a / 2. The cruise lasts TvT_v, and T=2Ta+TvT = 2T_a + T_v.

  1. DOUBLE-S(D, V, A, J) ▷ D, V, A, J > 0
  2. 1if V·J ≥ A² then Tj ← A/J; Ta ← Tj + V/A ▷ A is reached
  3. 2else Tj ← √(V/J); Ta ← 2 Tj ▷ A is not reached
  4. 3if V·Ta ≤ D then ▷ V is reached
  5. 4Tv ← D/V - Ta; vp ← V
  6. else
  7. 5Tv ← 0
  8. 6if D·J² ≥ 2A³ then Tj ← A/J; vp ← (-A²/J + √(A⁴/J² + 4AD))/2; Ta ← vp/A + Tj
  9. 7else vp ← (D² J / 4)^(1/3); Tj ← √(vp/J); Ta ← 2 Tj
  10. 8return (Tj, Ta, Tv, vp, 2 Ta + Tv)
  11. SAMPLE(pieces, t) ▷ pieces = the seven (duration, jerk) pairs
  12. 9for each piece (d, j): if t is inside it, integrate (s, v, a) over the rest of t exactly and return
  13. 10else integrate (s, v, a) over the whole piece: s += v d + a d²/2 + j d³/6, v += a d + j d²/2, a += j d

Lines L1 and L2 build the fastest acceleration phase that reaches VV: if VV is large compared with A2/JA^2/J, the acceleration ramps up to AA, holds it and ramps down; if not, it ramps up and immediately down, and peaks at VJ<A\sqrt{VJ} < A. Line L3 checks whether the two phases fit into DD. If they do, line L4 fills the rest with a cruise at VV. If not, lines L6 and L7 find the peak velocity vp<Vv_p < V for which the two phases cover exactly DD; line L6 is the case where the acceleration still reaches AA (a quadratic in vpv_p), line L7 the case where it does not (a cubic). Lines L9 and L10 integrate the piecewise constant jerk exactly, so sampling has no integration error.

Example

All limits reached. D=1D = 1 m, V=1V = 1 m/s, A=2A = 2 m/s², J=8J = 8 m/s³. Line L1: VJ=8≥4VJ = 8 \ge 4, so Tj=0.25T_j = 0.25 s and Ta=0.75T_a = 0.75 s. Line L3: VTa=0.75≤1V T_a = 0.75 \le 1, so line L4 gives Tv=0.25T_v = 0.25 s and T=1.75T = 1.75 s. The seven pieces last 0.250.25, 0.250.25, 0.250.25, 0.250.25, 0.250.25, 0.250.25, 0.250.25 s. The trapezoid with the same VV and AA takes 1.51.5 s; the difference is A/J=0.25A/J = 0.25 s.

Shorter moves. With the same limits:

DD (m) case TjT_j (s) TaT_a (s) vpv_p (m/s) TT (s) trapezoid TT (s)
1 L1, L4 0.25 0.75 1 1.75 1.5
0.3 L1, L6 0.25 0.53197 0.56394 1.06394 0.77460
0.2 L1, L7 0.23208 0.46416 0.43089 0.92832 0.63246

For D=0.2D = 0.2 the acceleration peaks at vpJ≈1.857<A\sqrt{v_p J} \approx 1.857 < A, and the double S is 0.2960.296 s slower than the triangle profile, more than A/JA/J.

Low speed limit. D=1D = 1, V=0.25V = 0.25, A=2A = 2, J=8J = 8. Line L2: VJ=2<4VJ = 2 < 4, so Tj=0.17678T_j = 0.17678 s and Ta=0.35355T_a = 0.35355 s, and the acceleration peaks at VJ=1.414\sqrt{VJ} = 1.414 m/s². Line L4 gives Tv=3.64645T_v = 3.64645 s and T=4.35355T = 4.35355 s, 0.2290.229 s more than the trapezoid.

Machine tool numbers. The example of feedrate scheduling, D=100D = 100 mm, V=50V = 50 mm/s, A=500A = 500 mm/s², J=104J = 10^4 mm/s³, gives Tj=0.05T_j = 0.05 s, Ta=0.15T_a = 0.15 s, Tv=1.85T_v = 1.85 s and T=2.15T = 2.15 s. The code reproduces these values.

Correctness

Theorem: the returned times give a profile that is admissible and covers exactly DD. The proof first computes one acceleration phase: started at rest, it ends at the velocity JTj(Ta−Tj)J T_j (T_a - T_j) and covers half of vpTav_p T_a. It then checks that lines L1 and L2 reach exactly VV within the limit AA, that line L4 covers DD, and, without a cruise, that the distance of two phases is a strictly increasing function gg of the peak velocity, so the equation g(vp)=Dg(v_p) = D has one root. The threshold 2A3/J22A^3/J^2 is the value of gg where the peak acceleration just reaches AA, which selects line L6 or line L7. The proof gives every step and shows that sampling is exact.

The rest-to-rest double S is often described as the minimum-time motion under the three limits. This page does not prove that claim.

Proof: The double-S profile covers the distance and respects the velocity, acceleration and jerk limitsfull

We use the notation of the page. One axis moves the distance D>0D > 0 from rest to rest with ∣v∣≤V|v| \le V, ∣a∣≤A|a| \le A and ∣j∣≤J|j| \le J. Lines L1 to L8 return the jerk time TjT_j, the acceleration time TaT_a, the cruise time TvT_v, the peak velocity vpv_p and T=2Ta+TvT = 2T_a + T_v. The seven pieces have jerk +J,0,−J,0,−J,0,+J+J, 0, -J, 0, -J, 0, +J and durations Tj,Ta−2Tj,Tj,Tv,Tj,Ta−2Tj,TjT_j, T_a - 2T_j, T_j, T_v, T_j, T_a - 2T_j, T_j. This file proves that the profile is admissible and covers DD. It does not prove that the profile is the fastest one.

One acceleration phase

Lemma 1. Let 0<Tj0 < T_j and 2Tj≤Ta2T_j \le T_a. The phase with jerk +J+J for TjT_j, jerk 00 for Ta−2TjT_a - 2T_j and jerk −J-J for TjT_j, started at rest, has:

  1. acceleration between 00 and JTjJ T_j,
  2. a velocity that does not decrease, from 00 to JTj(Ta−Tj)J T_j (T_a - T_j),
  3. the distance 12vpTa\frac12 v_p T_a, where vpv_p is the final velocity, and a final acceleration of 00.

Proof. The acceleration is a trapezoid in time: it rises to JTjJ T_j, stays there and falls back to 0. This gives 1, the final acceleration 0, and, as it is not negative, the monotone velocity. The final velocity is the area of the acceleration trapezoid, JTj⋅(Ta−Tj)J T_j \cdot (T_a - T_j), which is 2. The acceleration is symmetric about Ta/2T_a / 2, so the velocity satisfies v(Ta−t)=vp−v(t)v(T_a - t) = v_p - v(t). Then ∫0Tav=∫0Ta(vp−v)\int_0^{T_a} v = \int_0^{T_a} (v_p - v), which gives ∫0Tav=12vpTa\int_0^{T_a} v = \frac12 v_p T_a. □\square

The deceleration phase is the same phase with the opposite signs, run from vpv_p down to 0, and it covers 12vpTa\frac12 v_p T_a too. With a cruise of TvT_v at vpv_p in between, the whole move covers

vpTa+vpTv=vp(Ta+Tv),(1)v_p T_a + v_p T_v = v_p (T_a + T_v), \tag{1}

it ends at rest with zero acceleration, its jerk is in {−J,0,J}\{-J, 0, J\}, its acceleration is at most JTjJ T_j in size, and its speed is at most vpv_p. So it remains to show, for each branch, that 2Tj≤Ta2T_j \le T_a, JTj≤AJ T_j \le A, vp≤Vv_p \le V, Tv≥0T_v \ge 0 and vp(Ta+Tv)=Dv_p (T_a + T_v) = D, with vp=JTj(Ta−Tj)v_p = J T_j (T_a - T_j) as in Lemma 1.

The phase that reaches V

Lemma 2. After line L1 or line L2, the phase of Lemma 1 reaches exactly VV and its acceleration stays within AA.

Proof. If VJ≥A2VJ \ge A^2: Tj=A/JT_j = A/J and Ta=Tj+V/AT_a = T_j + V/A, so Ta−2Tj=V/A−A/J≥0T_a - 2T_j = V/A - A/J \ge 0, the peak acceleration is JTj=AJ T_j = A, and the final velocity is A⋅V/A=VA \cdot V/A = V. If VJ<A2VJ < A^2: Tj=V/JT_j = \sqrt{V/J} and Ta=2TjT_a = 2T_j, so the peak acceleration is VJ<A\sqrt{VJ} < A, and the final velocity is JTj2=VJ T_j^2 = V. □\square

With a cruise

If VTa≤DV T_a \le D (line L3), line L4 sets Tv=D/V−Ta≥0T_v = D/V - T_a \ge 0 and vp=Vv_p = V. By (1) the move covers V(Ta+Tv)=DV(T_a + T_v) = D. If also VJ≥A2VJ \ge A^2, the total time is T=Ta+(Ta+Tv)=A/J+V/A+D/VT = T_a + (T_a + T_v) = A/J + V/A + D/V.

Without a cruise

Otherwise VTa>DV T_a > D for the times of Lemma 2, and line L5 sets Tv=0T_v = 0. The move must cover D=vpTaD = v_p T_a with a peak vpv_p below VV. For a peak uu, let g(u)=u⋅Ta(u)g(u) = u \cdot T_a(u), where Ta(u)=u/A+A/JT_a(u) = u/A + A/J if uJ≥A2uJ \ge A^2 and Ta(u)=2u/JT_a(u) = 2\sqrt{u/J} otherwise. These are the times of Lemma 2 with uu in place of VV. Both pieces of gg are increasing, they agree at u=A2/Ju = A^2/J where g=2A3/J2g = 2A^3/J^2, so gg is continuous and strictly increasing, and g(V)=VTa>Dg(V) = V T_a > D.

Line L6, DJ2≥2A3DJ^2 \ge 2A^3. Then the solution of g(u)=Dg(u) = D has u≥A2/Ju \ge A^2/J, and solves u2/A+uA/J=Du^2/A + uA/J = D, that is u2+(A2/J)u−AD=0u^2 + (A^2/J)u - AD = 0. Its positive root is the vpv_p of line L6, and line L6 sets Tj=A/JT_j = A/J and Ta=vp/A+A/JT_a = v_p/A + A/J, so Ta−2Tj=vp/A−A/J≥0T_a - 2T_j = v_p/A - A/J \ge 0 and the peak acceleration is AA.

Line L7, DJ2<2A3DJ^2 < 2A^3. Then the solution has u<A2/Ju < A^2/J and solves 2uu/J=D2u\sqrt{u/J} = D, that is u3=D2J/4u^3 = D^2 J / 4, which is line L7. Line L7 sets Tj=vp/JT_j = \sqrt{v_p/J} and Ta=2TjT_a = 2T_j, and the peak acceleration is vpJ<A\sqrt{v_p J} < A.

In both lines, vp<Vv_p < V because gg is increasing and g(vp)=D<g(V)g(v_p) = D < g(V), and the move covers vpTa=Dv_p T_a = D by (1). In both lines Lemma 1 gives the final velocity JTj(Ta−Tj)=vpJ T_j (T_a - T_j) = v_p, as a direct check shows: A(vp/A)=vpA (v_p / A) = v_p for line L6 and JTj2=vpJ T_j^2 = v_p for line L7. □\square

Sampling

Lines L9 and L10 integrate the pieces with the exact formulas for constant jerk jj over a time hh: s←s+vh+12ah2+16jh3s \leftarrow s + vh + \frac12 a h^2 + \frac16 j h^3, v←v+ah+12jh2v \leftarrow v + ah + \frac12 j h^2, a←a+jha \leftarrow a + jh. These are the Taylor expansions of a cubic, which have no remainder, so the samples are exact in exact arithmetic.

What is not proved here

The profile is the natural extension of the trapezoid. When VV and AA are both reached, its time exceeds the time D/V+V/AD/V + V/A of the trapezoid by exactly A/JA/J. In the other cases the difference can be smaller or larger than A/JA/J. For example, with D=0.2D = 0.2, V=1V = 1, A=2A = 2 and J=8J = 8, the trapezoid is a triangle with time 20.1≈0.63252\sqrt{0.1} \approx 0.6325, and the double S needs 0.92830.9283, which is 0.2960.296 more, while A/J=0.25A/J = 0.25. This file does not prove that no other jerk-limited motion is faster, so the page does not claim that as a theorem.

Complexity

In the real RAM with square and cube roots, lines L1 to L8 take Θ(1)\Theta(1) time and space. Sampling takes Θ(1)\Theta(1) per sample, since there are seven pieces. Synchronizing nn axes to the slowest one, as for the trapezoid, takes Θ(n)\Theta(n) plus the cost of stretching each axis to the common time. That stretching has no simple closed form in general; Biagiotti and Melchiorri scale the limits instead.

Properties

  • Bounded jerk. The jerk takes only the values −J-J, 00 and +J+J. The acceleration is continuous, which the trapezoid does not give.
  • Extra time over the trapezoid. A theorem: when both VV and AA are reached, T=D/V+V/A+A/JT = D/V + V/A + A/J, exactly A/JA/J more than the trapezoid. In the case VJ<A2VJ < A^2 with a cruise, the extra time is at most A/JA/J. Without a cruise it can be larger, as the example with D=0.2D = 0.2 shows.
  • Seven segments at most. Pieces of zero duration appear when AA, VV or both are not reached, so a profile can have three, five or seven pieces of nonzero length.
  • Symmetric. The rest-to-rest profile with equal limits for speeding up and slowing down is symmetric in time.
  • Exact sampling. The position is a piecewise cubic in time, so exact integration of the pieces gives exact samples.

Variants and improvements

  • Nonzero end velocities. Biagiotti and Melchiorri (Section 3.4) handle given start and end velocities, with checks for feasibility.
  • Online computation. Starting from an arbitrary state with nonzero acceleration, the minimum-time jerk-limited motion needs many more cases; Kroger and Wahl solve it with decision trees (their Type IV). See online trajectory generation.
  • Fifteen segments. A bound on the snap, the derivative of the jerk, gives a profile of up to fifteen pieces (Biagiotti and Melchiorri, Section 3.5).
  • Smooth polynomial laws. A quintic or minimum-jerk profile is also smooth, but it reaches its limits only at single instants, so it is slower for the same limits.
  • Along a path. Feedrate scheduling applies the double S to the arc length of a tool path, with extra limits from the curvature.

When to use it

Use the double S when the jumps of the acceleration of the trapezoid cause vibration, noise or wear: CNC machining, pick and place at high speed, precise positioning stages, elevators and any servo drive that offers an "S-curve" setting. It costs a few percent more time on long moves. Use the plain trapezoid if the drive is stiff and the cycle time matters most, and online trajectory generation if the target can change during the motion.

Pitfalls

  • Missing cases. There are four cases (with or without AA, with or without cruise), and code that only handles the case where everything is reached gives wrong times for short moves.
  • Wrong case test. The test of line L6 uses DD and only applies without a cruise; deciding from VJVJ alone is wrong for short moves.
  • Cube roots. Line L7 needs a real cube root of a positive number; in floating point, use a function that is accurate there, and check the result by the distance formula, as the tests do.
  • Rounding near switch times. Accumulated sums of piece durations differ from TT by rounding; clamp the final sample to (D,0,0)(D, 0, 0).
  • Jerk limit too low. If JJ is very small, the profile spends most of its time ramping the acceleration, and it can be much slower than the trapezoid.

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.

double_s_velocity_profile.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/double-s-velocity-profile/. The authors are listed in prov/07FRKR.jsonl.
"""Double-S velocity profile: rest-to-rest motion of one axis with bounded jerk.

double_s(D, V, A, J) returns (Tj, Ta, Tv, vp, T) for the distance D > 0
with |velocity| <= V, |acceleration| <= A and |jerk| <= J. Tj is the time
of one jerk ramp, Ta the time of the whole acceleration phase, Tv the time
of the cruise, vp the peak velocity and T = 2 Ta + Tv the total time. The
deceleration phase is the mirror image of the acceleration phase.

jerk_segments(...) lists the seven (duration, jerk) pieces, and sample()
integrates them exactly, piece by piece.
"""

import math


def double_s(D, V, A, J):
    """Times of the seven-segment rest-to-rest profile."""
    if min(D, V, A, J) <= 0:
        raise ValueError("D, V, A and J must be positive")
    if V * J >= A * A:  # @line L1
        Tj = A / J
        Ta = Tj + V / A
    else:
        Tj = math.sqrt(V / J)  # @line L2
        Ta = 2 * Tj
    if V * Ta <= D:  # @line L3
        Tv = D / V - Ta  # @line L4
        vp = V
    else:
        Tv = 0 * D  # @line L5
        if D * J * J >= 2 * A ** 3:  # @line L6
            Tj = A / J
            vp = (-A * A / J + math.sqrt(A ** 4 / J ** 2 + 4 * A * D)) / 2
            Ta = vp / A + Tj
        else:
            vp = (D * D * J / 4) ** (1 / 3)  # @line L7
            Tj = math.sqrt(vp / J)
            Ta = 2 * Tj
    return Tj, Ta, Tv, vp, 2 * Ta + Tv  # @line L8


def jerk_segments(Tj, Ta, Tv, J):
    """The seven pieces (duration, jerk); some durations can be zero."""
    Tc = Ta - 2 * Tj  # time at constant acceleration
    return [(Tj, J), (Tc, 0), (Tj, -J), (Tv, 0), (Tj, -J), (Tc, 0), (Tj, J)]


def _step(state, dt, j):
    s, v, a = state
    return (s + v * dt + a * dt * dt / 2 + j * dt ** 3 / 6, v + a * dt + j * dt * dt / 2, a + j * dt)


def sample(segments, t):
    """Return (s, v, a, j) at time t by exact integration of the pieces."""
    state = (0 * t, 0 * t, 0 * t)
    t0 = 0 * t
    for dur, j in segments:  # @line L9
        if t <= t0 + dur:
            s, v, a = _step(state, t - t0, j)
            return s, v, a, j
        state = _step(state, dur, j)  # @line L10
        t0 += dur
    s, v, a = state
    return s, v, a, 0


def peak_velocity_distance(vp, A, J):
    """Distance of a symmetric rest-to-rest profile with no cruise and peak velocity vp.

    Used by the tests as an independent check of the closed forms of line L6
    and line L7: the acceleration phase covers vp Ta / 2, so the move covers vp Ta.
    """
    if vp * J >= A * A:
        Ta = vp / A + A / J
    else:
        Ta = 2 * math.sqrt(vp / J)
    return vp * Ta
test_double_s_velocity_profile.py 98 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/double-s-velocity-profile/. The authors are listed in prov/07FRKR.jsonl.
"""Tests: closed form times, exact end state, limits on a grid, and the peak velocity by bisection."""

import random
from fractions import Fraction as F

from double_s_velocity_profile import double_s, jerk_segments, peak_velocity_distance, sample


def end_state(D, V, A, J):
    Tj, Ta, Tv, vp, T = double_s(D, V, A, J)
    seg = jerk_segments(Tj, Ta, Tv, J)
    return sample(seg, T), seg, (Tj, Ta, Tv, vp, T)


def test_long_move_exact():
    # D = 1 m, V = 1 m/s, A = 2 m/s^2, J = 8 m/s^3: every phase is present.
    (s, v, a, _), _, (Tj, Ta, Tv, vp, T) = end_state(F(1), F(1), F(2), F(8))
    assert (Tj, Ta, Tv, vp, T) == (F(1, 4), F(3, 4), F(1, 4), 1, F(7, 4))
    assert (s, v, a) == (1, 0, 0)
    assert T == F(1) / 1 + F(1) / 2 + F(2) / 8  # D/V + V/A + A/J


def test_feedrate_example():
    # 100 mm at 50 mm/s, 500 mm/s^2 and 10000 mm/s^3 takes 2.15 s.
    T = double_s(F(100), F(50), F(500), F(10000))[4]
    assert T == F(215, 100)


def test_branches():
    # No cruise, A reached: D = 0.3 > 2 A^3 / J^2 = 0.25.
    Tj, Ta, Tv, vp, T = double_s(0.3, 1.0, 2.0, 8.0)
    assert Tv == 0 and abs(Tj - 0.25) < 1e-12 and vp < 1.0
    # No cruise, A not reached: D = 0.2 < 0.25.
    Tj, Ta, Tv, vp, T = double_s(0.2, 1.0, 2.0, 8.0)
    assert Tv == 0 and abs(Ta - 2 * Tj) < 1e-12 and 8.0 * Tj < 2.0
    assert abs(vp - 0.08 ** (1 / 3)) < 1e-12
    # V reached but not A: V J < A^2.
    Tj, Ta, Tv, vp, T = double_s(1.0, 0.25, 2.0, 8.0)
    assert vp == 0.25 and abs(Tj - (0.25 / 8) ** 0.5) < 1e-12 and Tv > 0


def test_peak_velocity_by_bisection():
    rng = random.Random(21)
    for _ in range(300):
        D, V, A, J = rng.uniform(0.01, 2), rng.uniform(0.1, 2), rng.uniform(0.1, 4), rng.uniform(0.5, 50)
        Tj, Ta, Tv, vp, T = double_s(D, V, A, J)
        if Tv > 0:
            assert vp == V and abs(peak_velocity_distance(V, A, J) + V * Tv - D) < 1e-9
            continue
        lo, hi = 0.0, V
        for _ in range(200):
            mid = (lo + hi) / 2
            if peak_velocity_distance(mid, A, J) < D:
                lo = mid
            else:
                hi = mid
        assert abs(vp - lo) < 1e-9


def test_limits_and_end_state():
    rng = random.Random(22)
    for _ in range(150):
        D, V, A, J = rng.uniform(0.01, 2), rng.uniform(0.1, 2), rng.uniform(0.1, 4), rng.uniform(0.5, 50)
        (s, v, a, _), seg, (Tj, Ta, Tv, vp, T) = end_state(D, V, A, J)
        assert abs(s - D) < 1e-9 and abs(v) < 1e-9 and abs(a) < 1e-9
        assert min(d for d, _ in seg) >= -1e-12
        prev = 0.0
        for k in range(301):
            s, v, a, j = sample(seg, T * k / 300)
            assert -1e-9 <= v <= V + 1e-9 and abs(a) <= A + 1e-9 and abs(j) <= J
            assert s >= prev - 1e-12
            prev = s


def test_compared_with_trapezoid():
    # The jerk bound never makes the move faster. When V and A are both
    # reached, it costs exactly A / J; it costs nothing in the limit J -> infinity.
    rng = random.Random(23)
    for _ in range(200):
        D, V, A, J = rng.uniform(0.01, 2), rng.uniform(0.1, 2), rng.uniform(0.1, 4), rng.uniform(0.5, 50)
        Tj, Ta, Tv, vp, T = double_s(D, V, A, J)
        T_trap = D / V + V / A if D * A >= V * V else 2 * (D / A) ** 0.5
        assert T >= T_trap - 1e-12
        if Tv > 0 and V * J >= A * A:
            assert abs(T - (T_trap + A / J)) < 1e-12
    T = double_s(1.0, 1.0, 2.0, 1e9)[4]
    assert abs(T - 1.5) < 1e-6


def test_bad_input():
    try:
        double_s(1, 1, 0, 1)
    except ValueError:
        pass
    else:
        raise AssertionError("A = 0 must fail")

History

Profiles with bounded jerk replaced the trapezoid in motion controllers when machines became faster and lighter and vibration started to limit their accuracy. Biagiotti and Melchiorri (2008) give the double S in a general form, with nonzero end velocities, the rest-to-rest case and an online version. Kroger and Wahl (2010) made the jerk-limited case work from arbitrary current states for several synchronized axes, the basis of online trajectory generation.

References

  1. Luigi Biagiotti and Claudio Melchiorri, Trajectory Planning for Automatic Machines and Robots, Springer, 2008, Section 3.4 (trajectory with double S velocity profile), in particular Section 3.4.3 for null initial and final velocities and Section 3.4.4 for online computation; Section 3.5 for the fifteen segments variant
  2. Torsten Kroger and Friedrich M. Wahl, Online trajectory generation, basic concepts for instantaneous reactions to unforeseen events, IEEE Transactions on Robotics 26(1), 2010, 94-111, the whole paper (jerk-limited motions from arbitrary states, Type IV)

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
  • History with a source
  • at least three sources
  • a scene preset for the example