toppra

raw JSON →
0.6.8 verified Sat May 09 auth: no python

toppra (Time-Optimal Path Parameterization via Reachability Analysis) is a Python library for computing time-optimal parametrizations of robot trajectories subject to constraints such as joint velocity, acceleration, and torque limits. It implements the TOPP-RA algorithm. Current version is 0.6.8. Release cadence is irregular, with occasional minor updates.

pip install toppra
error AttributeError: module 'toppra' has no attribute 'TOPPRA'
cause Attempting to use the old top-level TOPPRA class after version 0.3.0.
fix
Replace toppra.TOPPRA with algorithm.TOPPRA: from toppra import algorithm; solver = algorithm.TOPPRA(...)
error TypeError: 'NoneType' object is not iterable
cause The compute_trajectory() method returns None when the problem is infeasible. Code expects a trajectory object.
fix
Check the return value: traj = solver.compute_trajectory(); if traj is not None: ... else: handle infeasibility.
error ValueError: Path must be callable and return a matrix of shape (N, dof)
cause Passing raw waypoints array directly to algorithm.TOPPRA instead of a Path object.
fix
Wrap waypoints in a Path object, e.g., path = toppra.SplineInterpolator(ss, waypoints).
breaking Version 0.3.0 introduced a new C++ backend and significant API changes. Old code using TOPPRA class directly from earlier versions may break.
fix Update code to use algorithm.TOPPRA class and new constraint interfaces as shown in the quickstart.
gotcha The path (first argument to algorithm.TOPPRA) must be an instance of toppra.Path or SplineInterpolator. Passing raw waypoints without constructing a Path object causes cryptic errors.
fix Wrap waypoints in toppra.SplineInterpolator or use a custom Path subclass.
gotcha The gridpoints parameter in algorithm.TOPPRA must be an integer (number of grid points). Setting it too low (e.g., <10) may cause infeasibility, too high (>1000) may cause performance issues.
fix Use gridpoints=100 as a reasonable default; adjust based on path complexity.
deprecated The old toppra.TOPPRA class (without algorithm submodule) was deprecated in 0.3.0 and may be removed in future versions.
fix Use from toppra import algorithm; solver = algorithm.TOPPRA(...)

Creates a time-optimal trajectory for a 3-DOF robot with joint velocity and acceleration limits.

import numpy as np
import toppra
from toppra import constraint, algorithm

# Define a simple joint-space trajectory (position waypoints)
waypoints = np.array([
    [0, 0, 0],
    [0.5, 0.5, 0.5],
    [1, 1, 1],
])
# Create a piecewise linear path
path = toppra.SplineInterpolator(np.linspace(0, 1, waypoints.shape[0]), waypoints)

# Define constraints
vel_limits = np.array([2.0, 2.0, 2.0])
acc_limits = np.array([1.0, 1.0, 1.0])
pc_vel = constraint.JointVelocityConstraint(vel_limits)
pc_acc = constraint.JointAccelerationConstraint(acc_limits)

# Create TOPPRA instance
solver = algorithm.TOPPRA([pc_vel, pc_acc], path, gridpoints=100)
jnt_traj = solver.compute_trajectory()
if jnt_traj is not None:
    print("Time-optimal trajectory computed.")
else:
    print("Infeasible.")