Example 9: Simulation with RRBot
With example_9, we demonstrate the interaction of simulators with ros2_control. More specifically, Gazebo Classic is used for this purpose.
Follow the installation instructions on Installation how to install all dependencies, Gazebo Classic should be automatically installed.
If you have installed and compiled this repository locally, you can directly use the commands below.
If you have installed it via the provided docker image: To run the first two steps of this example (without Gazebo Classic), use the commands as described with Installation. To run the later steps using Gazebo Classic, execute
docker run -it --rm --name ros2_control_demos --net host ros2_control_demos ros2 launch ros2_control_demo_example_9 rrbot_gazebo_classic.launch.py gui:=false
first. Then on your local machine you can run the Gazebo Classic client with
rviz2 -d src/ros2_control_demos/example_9/description/rviz/rrbot.rviz
For details on the
gazebo_ros2_control plugin, see gazebo_ros2_control.
To check that RRBot descriptions are working properly use following launch commands
ros2 launch ros2_control_demo_example_9 view_robot.launch.py
joint_state_publisher_guiprovides 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 and Gazebo Classic installation first, i.e., by
Then, execute the launch file withros2 launch ros2_control_demo_example_9 rrbot_gazebo_classic.launch.py gui:=true
The launch file loads the robot description, starts Gazebo Classic, Joint State Broadcaster and Forward Command Controller. If you can see two orange and one yellow “box” in Gazebo Classic everything has started properly.
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
[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 Classic.
If you echo the
/dynamic_joint_statestopics you should see the changing values, namely the simulated states of the robot
ros2 topic echo /joint_states ros2 topic echo /dynamic_joint_states
Files used for this demos
Controllers yaml: rrbot_controllers.yaml
URDF file: rrbot.urdf.xacro
RViz configuration: rrbot.rviz
Test nodes goals configuration:
Hardware interface plugin: rrbot.cpp