You're reading the documentation for a development version. For the latest released version, please have a look at Iron.

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

  1. (Optional) To check that RRBot descriptions are working properly use following launch commands

    ros2 launch ros2_control_demo_example_1 view_robot.launch.py
    

    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 because joint_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.

    Revolute-Revolute Manipulator Robot

    Once it is working you can stop rviz using CTRL+C as the next launch file is starting RViz.

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

    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.

  3. Check if the hardware interface loaded properly, by opening another terminal and executing

    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.

  4. Check if controllers are running by

    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
    
  5. 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_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.

    [RRBotSystemPositionOnlyHardware]: Got command 0.50000 for joint 0!
    [RRBotSystemPositionOnlyHardware]: Got command 0.50000 for joint 1!
    

    If you echo the /joint_states or /dynamic_joint_states topics you should now get similar values, namely the simulated states of the robot

    ros2 topic echo /joint_states
    ros2 topic echo /dynamic_joint_states
    
  6. Let’s switch to a different controller, the Joint Trajectory Controller. Load the controller manually by

    ros2 control load_controller joint_trajectory_position_controller
    

    what should return Successfully loaded controller joint_trajectory_position_controller. Check the status with

    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 by

    ros2 control set_controller_state joint_trajectory_position_controller inactive
    

    what should give Successfully configured joint_trajectory_position_controller.

    Note

    The parameters are already set in rrbot_controllers.yaml but the controller was not loaded from the launch file rrbot.launch.py before.

    As an alternative, you can load the controller directly in inactive-state by means of the option for load_controller with

    ros2 control load_controller joint_trajectory_position_controller --set-state inactive
    

    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
    

    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 by

    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
    

    Again, check via

    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
    

    You can adjust the goals in rrbot_joint_trajectory_publisher.

Files used for this demos

Controllers from this demo