Skip to content

Trajectory

Polynomial Trajectory

BoundaryConditionsDescription

Bases: Protocol

__call__(q)

Return the boundary conditions for a given trajectory.

Parameters:

Name Type Description Default
q BoundaryConditions

An object with which to set the boundary conditions.

required

Returns:

Type Description
BoundaryConditions

The object with the boundary conditions set.

Example

See the for_boundary_conditions function for examples.

for_boundary_conditions(description)

Create a polynomial trajectory with the specified boundary conditions.

Parameters:

Name Type Description Default
description BoundaryConditionsDescription

A function that sets the boundary conditions for the trajectory.

required

Returns:

Type Description
Trajectory

A polynomial trajectory with the specified boundary conditions.

Example

You can use a lambda function to set the boundary conditions:

from core import trajectory
q = trajectory.polynomial.for_boundary_conditions(lambda q: q(0) == 0)
q.render()
# $0.0$

One boundary condition is not very useful, so you can set multiple like this:

from core import trajectory
q = trajectory.polynomial.for_boundary_conditions(
    lambda q: q(0) == 0 and q(1) == 1 and q(2) == 0
)
q.render()
# $-1.0t^2 + 2.0t$

It is also possible to set the boundary conditions on higher order derivatives:

from core import trajectory
q = trajectory.polynomial.for_boundary_conditions(
    lambda q: q(0) == 0 and q.dot(0) == 1 and q.dot.dot(2) == 2
)
q.render()
# $1.0t^2 + 1.0t$

Trapezoidal Trajectory

TimeOptimalConstraints dataclass

The constraints for creating a time-optimal trapezoidal trajectory.

Parameters:

Name Type Description Default
q tuple[Numeric, Numeric]

The position range in the form (start, end).

required
v Numeric

The maximum velocity.

required
a Numeric

The maximum acceleration.

required

time_optimal

This is a namespace for creating time-optimal trapezoidal trajectories.

__new__(*, t_0, q, v, a)

Create a time-optimal trapezoidal trajectory.

Parameters:

Name Type Description Default
t_0 Numeric

The initial time.

required
q tuple[Numeric, Numeric]

The position range in the form (start, end).

required
v Numeric

The maximum velocity.

required
a Numeric

The maximum acceleration.

required

Returns:

Type Description
Trapezoidal

The time-optimal trapezoidal trajectory.

Example
from core import trajectory
q = trajectory.trapezoidal.time_optimal(t_0=1, q=(1.5, 4.5), v=2, a=4)
q.render()
# Some latex equation like:
#
# ⎧ 2(t - 1.0)² + 3/2,  if t ∈ [1, 1.5]
#
# ⎨ 2t - 1,             if t ∈ (1.5, 2.5)
# ⎪
# ⎩ 9/2 - 18(t/3 - 1)², if t ∈ [2.5, 3]

group(*, t_0, constraints) staticmethod

Create a group of time-optimal trapezoidal trajectories.

Parameters:

Name Type Description Default
t_0 Numeric

The initial time.

required
constraints list[TimeOptimalConstraints]

The list of time-optimal trajectory constraints.

required

Returns:

Type Description
Trajectories

The group of time-optimal trapezoidal trajectories.

Example
from core import trajectory, TimeOptimalConstraints
q = trajectory.trapezoidal.time_optimal.group(
    t_0=0,
    constraints=[
        TimeOptimalConstraints(q=(0, 4), v=1, a=2),
        TimeOptimalConstraints(q=(0, 4), v=2, a=3),
    ],
)
q.render()
# Some latex equations like:
#
# ⎧ t²,                  if t ∈ [0, 0.5]
#
# ⎨ t - 1/4,             if t ∈ (0.5, 4)
# ⎪
# ⎩ 4 - 81(t/9 - 1)²/4,  if t ∈ [4, 4.5]
#
# ⎧ 3t²/2,               if t ∈ [0, 2/3]
#
# ⎨ 2t - 2/3,            if t ∈ (2/3, 2)
# ⎪
# ⎩ 4 - 32(3t/8 - 1)²/3, if t ∈ [2, 8/3]

fixed(*, t, q, t_a)

Create a trapezoidal trajectory with a fixed time frame and acceleration period.

Parameters:

Name Type Description Default
t tuple[Numeric, Numeric]

The time range for the trajectory in the form (start, end).

required
q tuple[Numeric, Numeric]

The position range for the trajectory in the form (start, end).

required
t_a Numeric

The acceleration period.

required

Returns:

Type Description
Trapezoidal

The trapezoidal trajectory.

Example
from core import trajectory
q = trajectory.trapezoidal.fixed(t=(1, 3), q=(1.5, 4.5), t_a=0.5)
q.render()
# Some latex equation like:
#
# ⎧ 2(t - 1.0)² + 3/2,  if t ∈ [1, 1.5]
#
# ⎨ 2t - 1,             if t ∈ (1.5, 2.5)
# ⎪
# ⎩ 9/2 - 18(t/3 - 1)², if t ∈ [2.5, 3]

Triangular Trajectory

for_boundary_conditions(t, q, q_dot)

Create a triangular trajectory from the boundary conditions.

Parameters:

Name Type Description Default
t tuple[Numeric, Numeric]

The time range for the trajectory in the form (start, end).

required
q tuple[Numeric, Numeric]

The position range for the trajectory in the form (start, end).

required
q_dot tuple[Numeric, Numeric]

The boundary conditions on the velocity at the start and end of the trajectory, in the form (start, end).

required

Returns:

Type Description
Trajectory

A triangular trajectory that satisfies the boundary conditions.

Example
from core import trajectory
q = trajectory.triangular.for_boundary_conditions(
    t=(0, 1), q=(0, 1), q_dot=(0, 2)
)
q.render()
# Some latex equation like:
#
# ⎧ 2(t - 1)² + 3/2,    if t ∈ [1, 1.5]
#
# ⎨ 2t - 1,             if t ∈ (1.5, 2.5)
# ⎪
# ⎩ 9/2 - 18(t/3 - 1)², if t ∈ [2.5, 3]