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 Iron.

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.

Note

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

    gzclient
    

    and/or rviz2 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.

Tutorial steps

  1. 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.

  2. 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.

  3. To start RRBot in the simulators, open a terminal, source your ROS2-workspace and Gazebo Classic installation first, i.e., by

source /usr/share/gazebo/setup.sh

Then, execute the launch file with

ros2 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.

Revolute-Revolute Manipulator Robot in Gazebo Classic
  1. 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.

  2. 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
    
  3. If you get output from above you can send commands to Forward Command Controller, either:

    1. Manually using ROS 2 CLI interface:

    ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray "data:
    - 0.5
    - 0.5"
    
    1. 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 /joint_states or /dynamic_joint_states topics 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 from this demo