You're reading the documentation for a development version. For the latest released version, please have a look at Jazzy.
Example 1: RRBot
RRBot, or ‘’Revolute-Revolute Manipulator Robot’’, is a simple 3-linkage, 2-joint arm that we will use to demonstrate various features.
It is essentially a double inverted pendulum and demonstrates some fun control concepts within a simulator and was originally introduced for Gazebo tutorials.
For example_1, the hardware interface plugin is implemented having only one interface.
The communication is done using proprietary API to communicate with the robot control box.
Data for all joints is exchanged at once.
Examples: KUKA RSI
The RRBot URDF files can be found in the description/urdf
folder.
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.
Tutorial steps
(Optional) To check that RRBot descriptions are working properly use following launch commands
ros2 launch ros2_control_demo_example_1 view_robot.launch.py
Let’s start with the docker container by running the following command:
docker run -it --rm --name ros2_control_demos --net host ros2_control_demos ros2 launch ros2_control_demo_example_1 view_robot.launch.py gui:=false
Now, we need to start
joint_state_publisher_gui
as well asrviz2
to view the robot, each in their own terminals after sourcing our ROS 2 installation.source /opt/ros/${ROS_DISTRO}/setup.bash ros2 run joint_state_publisher_gui joint_state_publisher_gui
The RViz setup can be recreated following these steps:
The robot models can be visualized using
RobotModel
display using/robot_description
topic.Or you can simply open the configuration from
ros2_control_demo_description/rrbot/rviz
folder manually or directly by executing from another terminal
source /opt/ros/${ROS_DISTRO}/setup.bash rviz2 -d src/ros2_control_demos/ros2_control_demo_description/rrbot/rviz/rrbot.rviz
Note
Getting the following output in terminal is OK:
Warning: Invalid frame ID "odom" passed to canTransform argument target_frame - frame does not exist
. This happens becausejoint_state_publisher_gui
node need some time to start.The
joint_state_publisher_gui
provides a GUI to change the configuration for RRbot. It is immediately displayed in RViz.Once it is working you can stop rviz using CTRL+C as the next launch file is starting RViz.
To start RRBot example open a terminal, source your ROS2-workspace and execute its launch file with
ros2 launch ros2_control_demo_example_1 rrbot.launch.py
The launch file loads and starts the robot hardware, controllers and opens RViz.
docker run -it --rm --name ros2_control_demos --net host ros2_control_demos ros2 launch ros2_control_demo_example_1 rrbot.launch.py gui:=false
The launch file loads and starts the robot hardware and controllers. Open RViz in a new terminal as described above.
In starting terminal you will see a lot of output from the hardware implementation showing its internal states. This is only of exemplary purposes and should be avoided as much as possible in a hardware interface implementation.
If you can see two orange and one yellow rectangle in RViz everything has started properly. Still, to be sure, let’s introspect the control system before moving RRBot.
Check if the hardware interface loaded properly, by opening another terminal and executing
ros2 control list_hardware_interfaces
Open a bash terminal inside the already running docker container by
docker exec -it ros2_control_demos ./entrypoint.sh bash
and run the command
ros2 control list_hardware_interfaces
If everything started nominally, you should see the output
command interfaces joint1/position [available] [claimed] joint2/position [available] [claimed] state interfaces joint1/position joint2/position
Marker
[claimed]
by command interfaces means that a controller has access to command RRBot.Check if controllers are running by
ros2 control list_controllers
(from the docker terminal, see above)
ros2 control list_controllers
You will see the two controllers in active state
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active forward_position_controller[forward_command_controller/ForwardCommandController] active
If you get output from above you can send commands to Forward Command Controller, either:
Manually using ROS 2 CLI interface:
ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray "data: - 0.5 - 0.5"
Inside the docker terminal from above, run the command
ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray "data: - 0.5 - 0.5"
Or you can start a demo node which sends two goals every 5 seconds in a loop:
ros2 launch ros2_control_demo_example_1 test_forward_position_controller.launch.py
Inside the docker terminal from above, run the command
ros2 launch ros2_control_demo_example_1 test_forward_position_controller.launch.py
You should now see orange and yellow blocks moving in RViz. Also, you should see changing states in the terminal where launch file is started, e.g.
[ros2_control_node-1] [INFO] [1721763082.437870177] [controller_manager.resource_manager.hardware_component.system.RRBot]: Writing commands: [ros2_control_node-1] 0.50 for joint 'joint2/position' [ros2_control_node-1] 0.50 for joint 'joint1/position'
If you echo the
/joint_states
or/dynamic_joint_states
topics you should now get similar values, namely the simulated states of the robotros2 topic echo /joint_states ros2 topic echo /dynamic_joint_states
Inside the docker terminal from above, run the command
ros2 topic echo /joint_states ros2 topic echo /dynamic_joint_states
Let’s switch to a different controller, the
Joint Trajectory Controller
. Load the controller manually byros2 control load_controller joint_trajectory_position_controller $(ros2 pkg prefix ros2_control_demo_example_1 --share)/config/rrbot_jtc.yaml
(from the docker terminal, see above)
ros2 control load_controller joint_trajectory_position_controller $(ros2 pkg prefix ros2_control_demo_example_1 --share)/config/rrbot_jtc.yaml
what should return
Successfully loaded controller joint_trajectory_position_controller
. Check the status withros2 control list_controllers
(from the docker terminal, see above)
ros2 control list_controllers
what shows you that the controller is loaded but unconfigured.
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active forward_position_controller[forward_command_controller/ForwardCommandController] active joint_trajectory_position_controller[joint_trajectory_controller/JointTrajectoryController] unconfigured
Configure the controller by setting it
inactive
byros2 control set_controller_state joint_trajectory_position_controller inactive
(from the docker terminal, see above)
ros2 control set_controller_state joint_trajectory_position_controller inactive
what should give
Successfully configured joint_trajectory_position_controller
.As an alternative, you can load the controller directly in
inactive
-state by means of the option forload_controller
withros2 control load_controller --set-state inactive joint_trajectory_position_controller $(ros2 pkg prefix ros2_control_demo_example_1 --share)/config/rrbot_jtc.yaml
(from the docker terminal, see above)
ros2 control load_controller --set-state inactive joint_trajectory_position_controller $(ros2 pkg prefix ros2_control_demo_example_1 --share)/config/rrbot_jtc.yaml
You should get the result
Successfully loaded controller joint_trajectory_position_controller into state inactive
.See if it loaded properly with
ros2 control list_controllers
(from the docker terminal, see above)
ros2 control list_controllers
what should now return
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active forward_position_controller[forward_command_controller/ForwardCommandController] active joint_trajectory_position_controller[joint_trajectory_controller/JointTrajectoryController] inactive
Note that the controller is loaded but still
inactive
. Now you can switch the controller byros2 control set_controller_state forward_position_controller inactive ros2 control set_controller_state joint_trajectory_position_controller active
(from the docker terminal, see above)
ros2 control set_controller_state forward_position_controller inactive ros2 control set_controller_state joint_trajectory_position_controller active
or simply via this one-line command
ros2 control switch_controllers --activate joint_trajectory_position_controller --deactivate forward_position_controller
(from the docker terminal, see above)
ros2 control switch_controllers --activate joint_trajectory_position_controller --deactivate forward_position_controller
Again, check via
ros2 control list_controllers
(from the docker terminal, see above)
ros2 control list_controllers
what should now return
joint_state_broadcaster[joint_state_broadcaster/JointStateBroadcaster] active forward_position_controller[forward_command_controller/ForwardCommandController] inactive joint_trajectory_position_controller[joint_trajectory_controller/JointTrajectoryController] active
Send a command to the controller using demo node, which sends four goals every 6 seconds in a loop with
ros2 launch ros2_control_demo_example_1 test_joint_trajectory_controller.launch.py
(from the docker terminal, see above)
ros2 launch ros2_control_demo_example_1 test_joint_trajectory_controller.launch.py
You can adjust the goals in rrbot_joint_trajectory_publisher.
Files used for this demos
Launch file: rrbot.launch.py
Controllers yaml:
URDF file: rrbot.urdf.xacro
Description: rrbot_description.urdf.xacro
ros2_control
tag: 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