# Understanding the effort\_controller/JointTrajectoryController

**URL:** <https://get-help.theconstruct.ai/t/understanding-the-effort-controller-jointtrajectorycontroller/20787>\
**Category:** ROS Control 101\
**Tags:** ros\_controllers\
**Created:** [November 30, 2022, 3:50pm UTC](https://get-help.theconstruct.ai/t/understanding-the-effort-controller-jointtrajectorycontroller/20787 "2022-11-30T15:50:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![volvo2](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@volvo2](https://get-help.theconstruct.ai/u/volvo2)\
**Post date:** [November 30, 2022, 3:50pm UTC](https://get-help.theconstruct.ai/t/understanding-the-effort-controller-jointtrajectorycontroller/20787/1 "2022-11-30T15:50:10Z")

</div>

Hello,  
I am having trouble understanding how the effort\_controller/JointTrajectoryController works in control terms. I understand how to use it and what it does, however I am having trouble grasping how it performs its calculations. I understand that it takes a joint trajectory as input, and outputs effort with the effort interface.

1. However, how does it implement the PID controller? Does it implment a PID controller for both the desired position and velocity, or just for the desired position?
2. And does it use a feedforward controller for the desired velocity?
3. Also, how does it determine the desired velocity from the trajectory and how can this be specified?

I hope you can help me gain a better understanding. Thank you.

Kind regards,  
Anders

---

<div class="post-metadata">

**Author:** ![rzegers](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/rzegers/32/7010_2.png) [@rzegers](https://get-help.theconstruct.ai/u/rzegers)\
**Post date:** [December 1, 2022, 9:54am UTC](https://get-help.theconstruct.ai/t/understanding-the-effort-controller-jointtrajectorycontroller/20787/2 "2022-12-01T09:54:52Z")

</div>

Hello @volvo2,  
as you correctly said the effort\_controller/JointTrajectoryController executes joint trajectories on a set of joints and sends commands to an effort interface.

The nice thing about the JointTrajectoryController is that you can provide just a few waypoints and the controller will interpolate new points and will send smooth control command updates to the robot.

From the documentation the `trajectory_msgs/JointTrajectory` message is as follows:

```auto
std_msgs/Header header
  uint32 seq
  time stamp
  string frame_id
string[] joint_names
trajectory_msgs/JointTrajectoryPoint[] points
  float64[] positions
  float64[] velocities
  float64[] accelerations
  duration time_from_start

```

In this message you must provide at least positions and you can optionally also provide velocities. Internally, when the trajectory is sampled, the position+velocity trajectory following error is mapped to effort commands through a PID loop. I am not an expert of each controller internals, but this is what I noticed when examining the source code that is in the official [ros\_controllers](https://github.com/ros-controls/ros_controllers) repository.

For instance by inspecting this file here:

> <https://github.com/ros-controls/ros_controllers/blob/a075bc36ebf5b81a7dafe911907cc1b781dd0185/joint_trajectory_controller/include/joint_trajectory_controller/hardware_interface_adapter.h#L194-L213>

In fact as you can see the command is computed adding feedforward+feedback control:

- Feedforward term: Desired velocity, as computed by the joint trajectory controller.
- Feedback: PID that compensates drift from the desired position.

This was also taken form that source code file:

> The following is an example configuration of a controller that uses this adapter.  
> Notice the parameters **gains** and **velocity\_ff** :

```auto
  head_controller:
    type: "effort_controllers/JointTrajectoryController"
    joints:
      - head_1_joint
      - head_2_joint
    gains:
      head_1_joint: {p: 200, d: 1, i: 5, i_clamp: 1}
      head_2_joint: {p: 200, d: 1, i: 5, i_clamp: 1}
    velocity_ff:
      head_1_joint: 1.0
      head_2_joint: 1.0
    constraints:
      goal_time: 0.6
      stopped_velocity_tolerance: 0.02
      head_1_joint: {trajectory: 0.05, goal: 0.02}
      head_2_joint: {trajectory: 0.05, goal: 0.02}
    stop_trajectory_duration: 0.5
    state_publish_rate: 25

```

Hope I could help a little bit, I definitely recommend diving deeper into the source code of the controller to get all the details about its implementation.

Best,

Roberto

---

<div class="post-metadata">

**Author:** ![volvo2](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/v/b487fb/32.png) [@volvo2](https://get-help.theconstruct.ai/u/volvo2)\
**Post date:** [December 1, 2022, 10:06am UTC](https://get-help.theconstruct.ai/t/understanding-the-effort-controller-jointtrajectorycontroller/20787/3 "2022-12-01T10:06:06Z")

</div>

Hello Roberto @rzegers ,  
Thank you very much for the answer.  
Understanding the JointTrajectory message helped a lot.

Am I correct in understanding that Moveit uses this message with the follow\_joint\_trajectory action?  
So, in other words Moveit! plans a path using one of its planning algorithms, and then uses this for the follow\_joint\_trajectory action?  
Does Moveit! provide the planned path as a set of waypoints which the controller then interpolates between?

Thank you for the patience- I am trying to gain a greater understanding of how the different mechanisms work.

Kind regards,  
Anders

---

<div class="post-metadata">

**Author:** ![rzegers](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/rzegers/32/7010_2.png) [@rzegers](https://get-help.theconstruct.ai/u/rzegers)\
**Post date:** [December 2, 2022, 9:44am UTC](https://get-help.theconstruct.ai/t/understanding-the-effort-controller-jointtrajectorycontroller/20787/4 "2022-12-02T09:44:03Z")

</div>

Hello @volvo2,

your understanding is correct, that is how MoveIt send commands to robotic arm joints. It works as you have described it.

Regards,

Roberto
