You're reading the documentation for a development version. For the latest released 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 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

  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 first. Then, execute the launch file with

ros2 launch ros2_control_demo_example_9 rrbot_gazebo.launch.py gui:=true

The launch file loads the robot description, starts gazebo, Joint State Broadcaster and Forward Command Controller. If you can see two orange and one yellow “box” in gazebo everything has started properly.

Revolute-Revolute Manipulator Robot in gazebo
  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.

    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