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 File | Class Name | Description |
trajectory.h | Trajectory | Trajectory class that provides interfaces for managing trajectories and trajectory points. |
trajectory_planner.h | TrajectoryPlanner | Defines the generic interface for trajectory planners, supporting different planning algorithms. |
CollisionChecker | Interface for collision-avoidance constraints. | |
poly5_planner.h | Poly5Planner | Trajectory planner based on fifth-order polynomials, providing smooth acceleration and deceleration. Inherits from TrajectoryPlanner class. |
Trajectory
Section titled “Trajectory”Add a Trajectory Point
Section titled “Add a Trajectory Point”-
Method:
void addPoint(const TrajectoryPoint& point) -
Parameter:
ParameterTypeDescription pointInput Trajectory point. For details, please refer to TrajectoryPoint. -
Return Value:
None (void).
Get a Trajectory Point
Section titled “Get a Trajectory Point”-
Method:
const TrajectoryPoint& getPoint(size_t index) const -
Parameter:
ParameterTypeDescription indexInput Index 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:
ParameterTypeDescription timeInput Timestamp. For details, please refer to AbcType. interpolateInput (optional) Whether to perform interpolation. -
Return Value:
Trajectory point. For details, please refer to TrajectoryPoint.
Get the Number of Trajectory Points
Section titled “Get the Number of Trajectory Points”-
Method:
size_t size() const -
Return Value:
Number of trajectory points.
Get Total Trajectory Duration
Section titled “Get Total Trajectory Duration”-
Method:
AbcType getDuration() const -
Return Value:
Total trajectory duration. For details, please refer to AbcType.
Get Joint Count
Section titled “Get Joint Count”-
Method:
size_t getJointCount() const -
Return Value:
Number of joints.
Check if Trajectory is Empty
Section titled “Check if Trajectory is Empty”-
Method:
bool empty() const -
Return Value:
trueif empty,falseotherwise.
Clear Trajectory
Section titled “Clear Trajectory”-
Method:
void clear() -
Return Value:
None (void).
Set Trajectory Name
Section titled “Set Trajectory Name”-
Method:
void setName(const std::string& name) -
Parameter:
ParameterTypeDescription nameInput Trajectory name. -
Return Value:
None (void).
Get Trajectory Name
Section titled “Get Trajectory Name”-
Method:
const std::string& getName() const -
Return Value:
The trajectory name.
Save Trajectory to a File
Section titled “Save Trajectory to a File”-
Method:
bool saveToFile(const std::string& filename) const -
Parameter:
ParameterTypeDescription filenameInput File path and name. -
Return Value:
trueif saved successfully,falseotherwise.
Load Trajectory from a File
Section titled “Load Trajectory from a File”-
Method:
bool loadFromFile(const std::string& filename) -
Parameter:
ParameterTypeDescription filenameInput File path and name. -
Return Value:
trueif loaded successfully,falseotherwise.
Get All Trajectory Points
Section titled “Get All Trajectory Points”-
Method:
const std::vector<TrajectoryPoint>& getPoints() const -
Return Value:
The container of all trajectory points. For details, please refer to TrajectoryPoint.
Trim Trajectory
Section titled “Trim Trajectory”-
Method:
Trajectory trim(AbcType start_time, AbcType end_time) const -
Parameters:
ParameterTypeDescription start_timeInput Start time. For details, please refer to AbcType. end_timeInput End time. For details, please refer to AbcType. -
Return Value:
The trimmed trajectory.
Append Trajectory
Section titled “Append Trajectory”-
Method:
Trajectory append(const Trajectory& other, AbcType blend_time = 0.0) const -
Parameters:
ParameterTypeDescription otherInput Trajectory to be appended. blend_timeInput (optional) Blend time. -
Return Value:
The appended trajectory.
Trajectory Planner
Section titled “Trajectory Planner”Initialize Trajectory Planner
Section titled “Initialize Trajectory Planner”The trajectory planner can be initialized in two ways, as described below.
-
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:
ParameterTypeDescription start_positionsInput Start positions. end_positionsInput End 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:
trueif initialization succeeds,falseotherwise.
-
-
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:
ParameterTypeDescription start_positionsInput Start positions. start_velocitiesInput Start velocities. start_accelerationsInput Start accelerations. end_positionsInput End positions. end_velocitiesInput End velocities. end_accelerationsInput End 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:
trueif initialization succeeds,falseotherwise.
-
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:
ParameterTypeDescription timeInput Time relative to the start time. For details, please refer to AbcType. pointOutput Trajectory point corresponding to the specified time. For details, please refer to TrajectoryPoint. -
Return Value:
trueif computation succeeds,falseotherwise.
Generate Trajectory
Section titled “Generate Trajectory”-
Method:
Trajectory generateTrajectory(int sample_rate = 100) -
Parameter:
ParameterTypeDescription sample_rateInput (optional) Sampling frequency, in Hz. -
Return Value:
The generated trajectory.
Evaluate Trajectory
Section titled “Evaluate Trajectory”-
Method:
TrajectoryEvaluation evaluateTrajectory(const Trajectory& trajectory) -
Parameter:
ParameterTypeDescription trajectoryInput The trajectory to be evaluated. -
Return Value:
Evaluation results. For details, please refer to TrajectoryEvaluation.
Set Collision Checker
Section titled “Set Collision Checker”-
Method:
void setCollisionChecker(std::shared_ptr<CollisionChecker> checker) -
Parameter:
ParameterTypeDescription checkerInput Collision checker. A shared pointer to a CollisionCheckerobject. -
Return Value:
None (void).
Get Total Planned Duration
Section titled “Get Total Planned Duration”-
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:
ParameterTypeDescription callbackInput TrajectoryStatusCallbackis 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:
ParameterTypeDescription max_velocitiesInput Maximum velocities. max_accelerationsInput Maximum accelerations. -
Return Value:
None (void).
Check a Trajectory Point for Collision
Section titled “Check a Trajectory Point for Collision”-
Method:
bool checkCollision(const TrajectoryPoint& point) -
Parameter:
ParameterTypeDescription pointInput Trajectory point. For details, please refer to TrajectoryPoint. -
Return Value:
trueif a collision is detected,falseotherwise.
Get Minimum Distance
Section titled “Get Minimum Distance”-
Method:
double getMinDistance(const TrajectoryPoint& point) -
Parameter:
ParameterTypeDescription pointInput Trajectory 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.
Initialize Trajectory Planner
Section titled “Initialize Trajectory Planner”-
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:
ParameterTypeDescription start_positionsInput Start positions. start_velocitiesInput Start velocities. start_accelerationsInput Start accelerations. end_positionsInput End positions. end_velocitiesInput End velocities. end_accelerationsInput End 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:
trueif initialization succeeds,falseotherwise.
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:
ParameterTypeDescription timeInput Time relative to the start. For details, please refer to AbcType. pointOutput Trajectory point corresponding to the specified time. For details, please refer to TrajectoryPoint. -
Return Value:
trueif computation succeeds,falseotherwise.
Get Total Planned Duration
Section titled “Get Total Planned Duration”-
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:
ParameterTypeDescription max_velocitiesInput Maximum velocities. max_accelerationsInput Maximum accelerations. -
Return Value:
None (void).