Skip to content

Trajectory Planner APIs

The trajectory planner APIs are implemented by the following classes. You can find the corresponding header files in the c++/include/drivers/traj directory to access the complete set of APIs.

Header FileClass NameDescription
trajectory.hTrajectoryTrajectory class that provides interfaces for managing trajectories and trajectory points.
trajectory_planner.hTrajectoryPlannerDefines the generic interface for trajectory planners, supporting different planning algorithms.
CollisionCheckerInterface for collision-avoidance constraints.
poly5_planner.hPoly5PlannerTrajectory planner based on fifth-order polynomials, providing smooth acceleration and deceleration. Inherits from TrajectoryPlanner class.
  • Method:

    void addPoint(const TrajectoryPoint& point)
  • Parameter:

    Parameter
    Type
    Description
    pointInputTrajectory point. For details, please refer to TrajectoryPoint.
  • Return Value:

    None (void).

  • Method:

    const TrajectoryPoint& getPoint(size_t index) const
  • Parameter:

    Parameter
    Type
    Description
    indexInputIndex of the trajectory point.
  • Return Value:

    Trajectory point. For details, please refer to TrajectoryPoint.

Get a Trajectory Point at a Specified Time

Section titled “Get a Trajectory Point at a Specified Time”
  • Method:

    TrajectoryPoint getPointAtTime(AbcType time, bool interpolate = true) const
  • Parameters:

    Parameter
    Type
    Description
    timeInputTimestamp. For details, please refer to AbcType.
    interpolateInput (optional)Whether to perform interpolation.
  • Return Value:

    Trajectory point. For details, please refer to TrajectoryPoint.

  • Method:

    size_t size() const
  • Return Value:

    Number of trajectory points.

  • Method:

    AbcType getDuration() const
  • Return Value:

    Total trajectory duration. For details, please refer to AbcType.

  • Method:

    size_t getJointCount() const
  • Return Value:

    Number of joints.

  • Method:

    bool empty() const
  • Return Value:

    true if empty, false otherwise.

  • Method:

    void clear()
  • Return Value:

    None (void).

  • Method:

    void setName(const std::string& name)
  • Parameter:

    Parameter
    Type
    Description
    nameInputTrajectory name.
  • Return Value:

    None (void).

  • Method:

    const std::string& getName() const
  • Return Value:

    The trajectory name.

  • Method:

    bool saveToFile(const std::string& filename) const
  • Parameter:

    Parameter
    Type
    Description
    filenameInputFile path and name.
  • Return Value:

    true if saved successfully, false otherwise.

  • Method:

    bool loadFromFile(const std::string& filename)
  • Parameter:

    Parameter
    Type
    Description
    filenameInputFile path and name.
  • Return Value:

    true if loaded successfully, false otherwise.

  • Method:

    const std::vector<TrajectoryPoint>& getPoints() const
  • Return Value:

    The container of all trajectory points. For details, please refer to TrajectoryPoint.

  • Method:

    Trajectory trim(AbcType start_time, AbcType end_time) const
  • Parameters:

    Parameter
    Type
    Description
    start_timeInputStart time. For details, please refer to AbcType.
    end_timeInputEnd time. For details, please refer to AbcType.
  • Return Value:

    The trimmed trajectory.

  • Method:

    Trajectory append(const Trajectory& other, AbcType blend_time = 0.0) const
  • Parameters:

    Parameter
    Type
    Description
    otherInputTrajectory to be appended.
    blend_timeInput (optional)Blend time.
  • Return Value:

    The appended trajectory.

The trajectory planner can be initialized in two ways, as described below.

  1. Initialize using start and end positions

    • Method:

      bool init(
      const std::vector<AbcType>& start_positions,
      const std::vector<AbcType>& end_positions,
      AbcType duration = 0,
      int velocity_scale = 100)
    • Parameters:

      Parameter
      Type
      Description
      start_positionsInputStart positions.
      end_positionsInputEnd positions.
      durationInput (optional)Planning duration. A value of 0 indicates that the duration is computed automatically.
      velocity_scaleInput (optional)Velocity scaling factor. Valid range: 0–100.
    • Return Value:

      true if initialization succeeds, false otherwise.

  2. Initialize using start/end positions, velocities, and accelerations

    • Method:

      bool initWithVelAcc(
      const std::vector<AbcType>& start_positions,
      const std::vector<AbcType>& start_velocities,
      const std::vector<AbcType>& start_accelerations,
      const std::vector<AbcType>& end_positions,
      const std::vector<AbcType>& end_velocities,
      const std::vector<AbcType>& end_accelerations,
      AbcType duration = 0,
      int velocity_scale = 100)
    • Parameters:

      Parameter
      Type
      Description
      start_positionsInputStart positions.
      start_velocitiesInputStart velocities.
      start_accelerationsInputStart accelerations.
      end_positionsInputEnd positions.
      end_velocitiesInputEnd velocities.
      end_accelerationsInputEnd accelerations.
      durationInput (optional)Planning duration. A value of 0 indicates that the duration is computed automatically.
      velocity_scaleInput (optional)Velocity scaling factor. Valid range: 0–100.
    • Return Value:

      true if initialization succeeds, false otherwise.

Compute a Trajectory Point at a Specified Time

Section titled “Compute a Trajectory Point at a Specified Time”
  • Method:

    bool computeTrajectoryPoint(AbcType time, TrajectoryPoint& point)
  • Parameters:

    Parameter
    Type
    Description
    timeInputTime relative to the start time. For details, please refer to AbcType.
    pointOutputTrajectory point corresponding to the specified time. For details, please refer to TrajectoryPoint.
  • Return Value:

    true if computation succeeds, false otherwise.

  • Method:

    Trajectory generateTrajectory(int sample_rate = 100)
  • Parameter:

    Parameter
    Type
    Description
    sample_rateInput (optional)Sampling frequency, in Hz.
  • Return Value:

    The generated trajectory.

  • Method:

    TrajectoryEvaluation evaluateTrajectory(const Trajectory& trajectory)
  • Parameter:

    Parameter
    Type
    Description
    trajectoryInputThe trajectory to be evaluated.
  • Return Value:

    Evaluation results. For details, please refer to TrajectoryEvaluation.

  • Method:

    void setCollisionChecker(std::shared_ptr<CollisionChecker> checker)
  • Parameter:

    Parameter
    Type
    Description
    checkerInputCollision checker. A shared pointer to a CollisionChecker object.
  • Return Value:

    None (void).

  • Method:

    AbcType getTotalDuration() const
  • Return Value:

    Total planned duration.

Register Trajectory Status Callback Function

Section titled “Register Trajectory Status Callback Function”
  • Method:

    void setStatusCallback(TrajectoryStatusCallback callback)
  • Parameter:

    Parameter
    Type
    Description
    callbackInputTrajectoryStatusCallback is a function pointer type. For details, please refer to TrajectoryStatusCallback. The callback function is called whenever a trajectory status update is received.
  • Return Value:

    None (void).

Set Maximum Velocity and Acceleration Constraints

Section titled “Set Maximum Velocity and Acceleration Constraints”
  • Method:

    void setConstraints(
    const std::vector<AbcType>& max_velocities,
    const std::vector<AbcType>& max_accelerations)
  • Parameters:

    Parameter
    Type
    Description
    max_velocitiesInputMaximum velocities.
    max_accelerationsInputMaximum accelerations.
  • Return Value:

    None (void).

  • Method:

    bool checkCollision(const TrajectoryPoint& point)
  • Parameter:

    Parameter
    Type
    Description
    pointInputTrajectory point. For details, please refer to TrajectoryPoint.
  • Return Value:

    true if a collision is detected, false otherwise.

  • Method:

    double getMinDistance(const TrajectoryPoint& point)
  • Parameter:

    Parameter
    Type
    Description
    pointInputTrajectory point. For details, please refer to TrajectoryPoint.
  • Return Value:

    Minimum distance.

Poly5 (Fifth-Order Polynomial) Trajectory Planner

Section titled “Poly5 (Fifth-Order Polynomial) Trajectory Planner”

The Poly5Planner class inherits from the TrajectoryPlanner class. The initWithVelAcc() method is newly added, while the other methods are overrides of those in the base TrajectoryPlanner class.

  • Method:

    bool initWithVelAcc(
    const std::vector<AbcType>& start_positions,
    const std::vector<AbcType>& start_velocities,
    const std::vector<AbcType>& start_accelerations,
    const std::vector<AbcType>& end_positions,
    const std::vector<AbcType>& end_velocities,
    const std::vector<AbcType>& end_accelerations,
    AbcType duration = 0,
    int velocity_scale = 100)
  • Parameters:

    Parameter
    Type
    Description
    start_positionsInputStart positions.
    start_velocitiesInputStart velocities.
    start_accelerationsInputStart accelerations.
    end_positionsInputEnd positions.
    end_velocitiesInputEnd velocities.
    end_accelerationsInputEnd accelerations.
    durationInput (optional)Planning duration. A value of 0 indicates that the duration is computed automatically.
    velocity_scaleInput (optional)Velocity scaling factor. Valid range: 0–100.
  • Return Value:

    true if initialization succeeds, false otherwise.

Compute a Trajectory Point at a Specified Time

Section titled “Compute a Trajectory Point at a Specified Time”
  • Method:

    bool computeTrajectoryPoint(AbcType time, TrajectoryPoint& point)
  • Parameters:

    Parameter
    Type
    Description
    timeInputTime relative to the start. For details, please refer to AbcType.
    pointOutputTrajectory point corresponding to the specified time. For details, please refer to TrajectoryPoint.
  • Return Value:

    true if computation succeeds, false otherwise.

  • Method:

    AbcType getTotalDuration() const
  • Return Value:

    Total planned duration.

Set Maximum Velocity and Acceleration Constraints

Section titled “Set Maximum Velocity and Acceleration Constraints”
  • Method:

    void setConstraints(
    const std::vector<AbcType>& max_velocities,
    const std::vector<AbcType>& max_accelerations)
  • Parameters:

    Parameter
    Type
    Description
    max_velocitiesInputMaximum velocities.
    max_accelerationsInputMaximum accelerations.
  • Return Value:

    None (void).