You're reading the documentation for a development version. For the latest released version, please have a look at Jazzy.
Example 9: Simulation with RRBot
With example_9, we demonstrate the interaction of simulators with ros2_control. More specifically, gazebo is used for this purpose.
Note
Follow the installation instructions on Installation how to install all dependencies,
gazebo should be automatically installed. For details on the gz_ros2_control
plugin, see gz_ros2_control.
Tutorial steps
To check that RRBot descriptions are working properly use following launch commands
ros2 launch ros2_control_demo_example_9 view_robot.launch.py
The
joint_state_publisher_gui
provides a GUI to change the configuration for RRbot. It is immediately displayed in RViz.To start RRBot with the hardware interface instead of the simulators, open a terminal, source your ROS2-workspace and execute its launch file with
ros2 launch ros2_control_demo_example_9 rrbot.launch.py
It uses an identical hardware interface as already discussed with example_1, see its docs on details on the hardware interface.
To start RRBot in the simulators, open a terminal, source your ROS2-workspace first. Then, execute the launch file with
Check if the hardware interface loaded properly, by opening another terminal and executing
ros2 control list_hardware_interfaces
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
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"
Or you can start a demo node which sends two goals every 5 seconds in a loop
ros2 launch ros2_control_demo_example_9 test_forward_position_controller.launch.py
You should now see the robot moving in gazebo.
If you echo the
/joint_states
or/dynamic_joint_states
topics you should see the changing values, namely the simulated states of the robotros2 topic echo /joint_states ros2 topic echo /dynamic_joint_states
Files used for this demos
Launch files:
Hardware: rrbot.launch.py
gazebo: rrbot_gazebo.launch.py
Controllers yaml: rrbot_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): docForward Command Controller
(ros2_controllers repository): doc