This project is based on the joint_trajectory_controller. It provides a ros2_control ControllerInterface used as a simplified joint_forward_trajectory_controller for trajectory interpolation. It is designed as a controller for executing joint-space trajectories on a group of joints.
The controller accepts trajectory goals and interpolates them using selected methods to provide smooth commands to the hardware.
Command interfaces provided by the hardware interface can include position, velocity and effort. Controller requires them to be in the following combinations:
-
position -
position,velocity -
position,effort -
position,velocity,effort
-
Action server execution via
control_msgs/action/FollowJointTrajectory -
Working independently via topic subscriber using
trajectory_msgs/msg/JointTrajectory -
Querying state via
control_msgs/srv/QueryTrajectoryState(Note: currently it returns onlypositionandvelocity)
The controller supports configuring the interpolation method via the interpolation_method parameter. The allowed methods are splines and none.
No interpolation is applied between trajectory points. The controller executes points strictly as they are received.
Polynomial splines are used to compute smooth intermediate state based on boundary conditions given by the trajectory points. Depending on the provided fields in the trajectory msg, a different interpolation order is applied:
Position Linear Interpolation
Used when only positions are provided in the trajectory message. It computes intermediate positions linearly and provides a constant velocity:
Position Cubic Spline Interpolation
Used specifically when both positions and velocities are provided in the trajectory message. A third-degree polynomial ensures smooth position and continuous velocity between trajectory waypoints:
Effort Linear Interpolation
Used when effort is provided in trajectory message. It computes intermediate effort linearly:
Where:
-
$\boldsymbol{p}(t)$ ,$\boldsymbol{v}(t)$ and$\boldsymbol{\tau}(t)$ are position, velocity and effort at time$t$ . -
$\boldsymbol{a}_n$ are the polynomial coefficients derived from the start and end points of the trajectory segment.
- Humble (supports
ros2_controlfor Rolling)
- Clone repo to your workspace:
git clone https://github.com/KNR-PW/LRT_forward_trajectory_controller.git
- Install dependencies in workspace:
rosdep install --ignore-src --from-paths . -y -r
- Build (in
Releasemode)
colcon build --packages-select joint_forward_trajectory_controller --cmake-args -DCMAKE_BUILD_TYPE=Release
...
joint_forward_trajectory_controller:
type:
joint_forward_trajectory_controller/JointForwardTrajectoryController
...
joint_forward_trajectory_controller:
ros__parameters:
joints:
- joint_1
- joint_2
command_interfaces:
- position
- velocity
- effort
allow_partial_joints_goal: false
allow_integration_in_goal_trajectories: false
action_monitor_rate: 20.0
interpolation_method: "splines"
allow_nonzero_velocity_at_trajectory_end: true
cmd_timeout: 0.0
...command_interfaces - command interfaces provided by the hardware interface for all joints. Supported combinations are:
-
["position"] -
["position","velocity"] -
["position","effort"] -
["position","velocity","effort"]
allow_integration_in_goal_trajectories - allow integration in goal trajectories to accept goals without position or velocity specified.
action_monitor_rate - rate to monitor status changes when controller is executing an action (control_msgs::action::FollowJointTrajectory).
allow_nonzero_velocity_at_trajectory_end - if false, the last velocity point has to be zero or the goal will be rejected.
cmd_timeout - timeout after which the input command is considered stale. Timeout is counted from the end of the trajectory. If 0 , timeout is deactivated.
To help you understand and verify how the controller interpolates trajectories you can use the visualization tools provided in the debugScripts directory.
- Make sure you have the necessary Python plotting libraries installed.
- Build package and run the
test_forward_trajectorytest usingcolcon. This will automatically generate log files containing the trajectory data:
colcon test --packages-select joint_forward_trajectory_controller --ctest-args -R "test_forward_trajectory"- Run the visualizer script using the generated log file (typically located in the
logdirectory).
Usage examples:
python3 debugScripts/trajectoryVisualizer.py -save ../../log/latest_test/joint_forward_trajectory_controller/stdout.log
