Skip to the content.

ros2_control_explained

To ros2_control or NOT TO ros2_control?

LinkediN

The infamous ros2_control is a framework (real time robot control) in ROS2 that facilitates the management and control of a robot’s hardware in a standardized and modular way. The purpose is to simplify integrating new hardware into ROS2 applications by separating controllers (software side) from different systems, actuators and sensors (hardware side). We can think of it as a bridge that connects the software and hardware by translating high-level commands (like robot motion control commands) into low-level motor signals. It also reads feedback from the robot hardware and sends it back to the software. Diagram1 Suppose we have a robotic arm with 3 revolute joints. And we want to:

Each joint of the robot arm is driven by a motor, but different motors require different methods for communications. Example:

Also, motors can be controlled via serial or CAN bus for controlling speed, position, torque etc.

Without ros2_control

With ros2_control, we do not need to worry about most of the above.

Now for our 3 joint robot arm, we can update our Diagram 1 like below: Diagram3 The building blocks for controlling our robot arm are:

The diagram below shows how different components of ros2_control framework work together in to move our robotic arm Diagram4 Now let’s say we want to swap out the 3 joint robot arm with a two wheel differential drive robot. It means we want to change the hardware. Do we write whole new software from scratch to control our new hardware? NO.! HECK NO!

The ros2_control framework allows us to implement hardware abstraction through its hardware interface. This hardware_interface talks to the robot hardware (does not matter how the robot looks like) by representing the hardware through two interfaces.

The benefits of such abstraction are:

Two very important components for robot abstractions are:

Let’s see a more detailed diagram of this framework when we swap our robot arm with any other type of robot (both real and simulation). Diagram6 Diagram7 We should know that each hardware interface is created as a plugin. The plugins register themselves with the pluginlib. The controller manager uses pluginlib to find and load appropriate plugins. These plugins can be loaded dynamically meaning they can be loaded at runtime (while the program is running). The beauty of using pluginlib in ros2_control is that it makes the system incredibly flexible while maintaining robustness. We can add support for new robots by creating new plugins, we can easily update or debug features without rebuilding the entire system, we can switch between real and simulated hardware. All without changing the application code!

So, ros2_control is basically like using the same standard gamepad console to play all kinds of games! No need to change your console for different games!

–Written by Masum
Date: January 4, 2025

Click here to see an example of a custom hardware interface