You're reading the documentation for an older, but still supported, version of ROS 2. For information on the latest version, please have a look at Kilted.
Example 15: Using multiple controller managers
This example shows how to integrate multiple robots under different controller manager instances.
Note
The commands below are given for a local installation of this repository and its dependencies as well as for running them from a docker container. For more information on the docker usage see Using Docker.
Scenario: Using ros2_control within a local namespace
Note
When running ros2 control CLI commands you have to use additional parameter with exact controller manager node name, i.e., -c /rrbot/controller_manager.
Launch the example with
ros2 launch ros2_control_demo_example_15 rrbot_namespace.launch.py
Command interfaces:
joint1/position
joint2/position
State interfaces:
joint1/position
joint2/position
Available controllers: (nodes under namespace “/rrbot”)
$ ros2 control list_controllers -c /rrbot/controller_manager
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
forward_position_controller[forward_command_controller/ForwardCommandController] active
position_trajectory_controller[joint_trajectory_controller/JointTrajectoryController] inactive
Commanding the robot using a ForwardCommandController (name: /rrbot/forward_position_controller)
ros2 launch ros2_control_demo_example_15 test_forward_position_controller.launch.py publisher_config:=rrbot_namespace_forward_position_publisher.yaml
Abort the command and switch controller to use JointTrajectoryController (name: /rrbot/position_trajectory_controller):
ros2 control switch_controllers -c /rrbot/controller_manager --deactivate forward_position_controller --activate position_trajectory_controller
Commanding the robot using JointTrajectoryController (name: /rrbot/position_trajectory_controller)
ros2 launch ros2_control_demo_example_15 test_joint_trajectory_controller.launch.py publisher_config:=rrbot_namespace_joint_trajectory_publisher.yaml
Files used for this demo:
Launch file: rrbot_namespace.launch.py
Controllers yaml: rrbot_namespace_controllers.yaml
URDF file: rrbot.urdf.xacro
Description: rrbot_description.urdf.xacro
ros2_controltag: rrbot.ros2_control.xacro
RViz configuration: rrbot.rviz
Test nodes goals configuration:
Hardware interface plugin: rrbot.cpp
Scenario: Using multiple controller managers on the same machine
Note
When running ros2 control CLI commands you have to use additional parameter with exact controller manager node name, e.g., -c /rrbot_1/controller_manager or -c /rrbot_2/controller_manager.
Launch the example with
ros2 launch ros2_control_demo_example_15 multi_controller_manager_example_two_rrbots.launch.py
You should see two robots in RViz:
rrbot_1 namespace:
Command interfaces:
rrbot_1_joint1/position
rrbot_1_joint2/position
State interfaces:
rrbot_1_joint1/position
rrbot_1_joint2/position
rrbot_2 namespace:
Command interfaces:
rrbot_2_joint1/position
rrbot_2_joint2/position
State interfaces:
rrbot_2_joint1/position
rrbot_2_joint2/position
Available controllers (nodes under namespace /rrbot_1 and /rrbot_2):
$ ros2 control list_controllers -c /rrbot_1/controller_manager
position_trajectory_controller[joint_trajectory_controller/JointTrajectoryController] inactive
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
forward_position_controller[forward_command_controller/ForwardCommandController] active
$ ros2 control list_controllers -c /rrbot_2/controller_manager
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active
position_trajectory_controller[joint_trajectory_controller/JointTrajectoryController] inactive
forward_position_controller[forward_command_controller/ForwardCommandController] active
Commanding the robots using the forward_position_controller (of type ForwardCommandController)
ros2 launch ros2_control_demo_example_15 test_multi_controller_manager_forward_position_controller.launch.py
Switch controller to use the position_trajectory_controller (of type JointTrajectoryController) - alternatively start main launch file with argument robot_controller:=position_trajectory_controller:
ros2 control switch_controllers -c /rrbot_1/controller_manager --deactivate forward_position_controller --activate position_trajectory_controller
ros2 control switch_controllers -c /rrbot_2/controller_manager --deactivate forward_position_controller --activate position_trajectory_controller
Commanding the robots using the now activated position_trajectory_controller:
ros2 launch ros2_control_demo_example_15 test_multi_controller_manager_joint_trajectory_controller.launch.py
Files used for this demo:
Launch file: multi_controller_manager_example_two_rrbots.launch.py
Controllers yaml: - multi_controller_manager_rrbot_generic_controllers.yaml
URDF file: rrbot.urdf.xacro
Description: rrbot_description.urdf.xacro
ros2_controltag: rrbot.ros2_control.xacro
RViz configuration: rrbot.rviz
Test nodes goals configuration:
Hardware interface plugin: rrbot.cpp
Controllers from this demo
Joint State Broadcaster(ros2_controllers repository): doc
Forward Command Controller(ros2_controllers repository): doc
Joint Trajectory Controller(ros2_controllers repository): doc
