I followed ros2_control diff_drive_example https://github.com/ros-controls/ros2_control_demos/tree/master/example_2 to bring my ROS1 robot to ROS2.

I notice there is a PID controller (pid.cpp and pid.hpp files) in ros2_control and I wonder if I have to implement/use it in my hardware_interface by my own or if it will already be used by diff_drive_controller itself?

In my previous code for ROS1, there was a class PID which inherited from control_toolbox::PID https://github.com/hoverboard-robotics/hoverboard-driver/blob/master/include/hoverboard_driver/pid.h and which acts as an interface between dynamic reconfigure and control_toolbox::Pid. Inside the Hardware_interface itself, there was an instance of control_toolbox:Pid (actually of the new pid class which inherits from control_toolbox::Pid) for each wheel like this

    // Init PID controller
pids[0].init(nh_left, 1.0, 0.0, 0.0, 0.01, 1.5, -1.5, true, max_velocity, -max_velocity);
pids[0].setOutputLimits(-max_velocity, max_velocity);
pids[1].init(nh_right, 1.0, 0.0, 0.0, 0.01, 1.5, -1.5, true, max_velocity, -max_velocity);
pids[1].setOutputLimits(-max_velocity, max_velocity);

and this was just used before sending commands to Hardware by serial like this

    double pid_outputs[2];
pid_outputs[0] = pids[0](joints[0].vel.data, joints[0].cmd.data, period);
pid_outputs[1] = pids[1](joints[1].vel.data, joints[1].cmd.data, period);

// Convert PID outputs in RAD/S to RPM
double set_speed[2] = {
    pid_outputs[0] / 0.10472,
    pid_outputs[1] / 0.10472

Now I wonder if I still need to implement PID to Hardware_interface by myself or if the controller will already handle this for me.

I couldn't find an example for diff drive together with PID which makes me curious if it is needed or not



1 Answer 1


Unfortunately, we don't have a released PID controller yet. But there is one PR for it, I hope it gets attention again after ROSCon.

ros2_control supports controller chaining, but diff_drive_controller needs an update to support chaining with the PID controller above.

control_toolbox::PID is also released for ROS 2, I fear that you have to implement that in the hardware component as you are suggesting.

  • $\begingroup$ Thanks for your quick answer. In this case, I'll implement in the way it has been done before, no issue. I just wanted to ensure that I'm doing it the "right" way. $\endgroup$ Oct 11, 2023 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.