Skip to content

Latest commit

 

History

History
457 lines (252 loc) · 15.2 KB

userdoc.rst

File metadata and controls

457 lines (252 loc) · 15.2 KB
github_url:https://github.com/ros-controls/ros2_control_demos/blob/{REPOS_FILE_BRANCH}/example_1/doc/userdoc.rst

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.

Tutorial steps

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

    .. tabs::
    
       .. group-tab:: Local
    
          .. code-block:: shell
    
            ros2 launch ros2_control_demo_example_1 view_robot.launch.py
    
       .. group-tab:: Docker
    
         Let's start with the docker container by running the following command:
    
         .. code-block:: shell
    
           docker run -it --rm --name ros2_control_demos --net host ros2_control_demos ros2 launch ros2_control_demo_example_1 view_robot.launch.py gui:=false
    
         Now, we need to start ``joint_state_publisher_gui`` as well as ``rviz2`` to view the robot, each in their own terminals after sourcing our ROS 2 installation.
    
         .. code-block:: shell
    
           source /opt/ros/${ROS_DISTRO}/setup.bash
           ros2 run joint_state_publisher_gui joint_state_publisher_gui
    
         The *RViz* setup can be recreated following these steps:
    
         * The robot models can be visualized using ``RobotModel`` display using ``/robot_description`` topic.
         * Or you can simply open the configuration from ``ros2_control_demo_description/rrbot/rviz`` folder manually or directly by executing from another terminal
    
         .. code-block:: shell
    
           source /opt/ros/${ROS_DISTRO}/setup.bash
           rviz2 -d src/ros2_control_demos/ros2_control_demo_description/rrbot/rviz/rrbot.rviz
    
    

    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

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 launch ros2_control_demo_example_1 rrbot.launch.py
    
         The launch file loads and starts the robot hardware, controllers and opens *RViz*.
    
       .. group-tab:: Docker
    
         .. code-block:: shell
    
           docker run -it --rm --name ros2_control_demos --net host ros2_control_demos ros2 launch ros2_control_demo_example_1 rrbot.launch.py gui:=false
    
         The launch file loads and starts the robot hardware and controllers. Open *RViz* in a new terminal
         as described above.
    
    

    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

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 control list_hardware_interfaces
    
       .. group-tab:: Docker
    
         Open a bash terminal inside the already running docker container by
    
         .. code-block:: shell
    
           docker exec -it ros2_control_demos ./entrypoint.sh bash
    
         and run the command
    
         .. code-block:: shell
    
           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

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 control list_controllers
    
       .. group-tab:: Docker
    
         (from the docker terminal, see above)
    
         .. code-block:: shell
    
           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:
    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray "data:
           - 0.5
           - 0.5"
    
       .. group-tab:: Docker
    
         Inside the docker terminal from above, run the command
    
         .. code-block:: shell
    
           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:
    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 launch ros2_control_demo_example_1 test_forward_position_controller.launch.py
    
       .. group-tab:: Docker
    
         Inside the docker terminal from above, run the command
    
         .. code-block:: shell
    
           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

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 topic echo /joint_states
           ros2 topic echo /dynamic_joint_states
    
       .. group-tab:: Docker
    
         Inside the docker terminal from above, run the command
    
         .. code-block:: shell
    
           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

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 control load_controller joint_trajectory_position_controller $(ros2 pkg prefix ros2_control_demo_example_1 --share)/config/rrbot_jtc.yaml
    
       .. group-tab:: Docker
    
         (from the docker terminal, see above)
    
         .. code-block:: shell
    
           ros2 control load_controller joint_trajectory_position_controller $(ros2 pkg prefix ros2_control_demo_example_1 --share)/config/rrbot_jtc.yaml
    
    

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

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 control list_controllers
    
       .. group-tab:: Docker
    
         (from the docker terminal, see above)
    
         .. code-block:: shell
    
           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

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 control set_controller_state joint_trajectory_position_controller inactive
    
       .. group-tab:: Docker
    
         (from the docker terminal, see above)
    
         .. code-block:: shell
    
           ros2 control set_controller_state joint_trajectory_position_controller inactive
    
    

    what should give Successfully configured joint_trajectory_position_controller.

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

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 control load_controller --set-state inactive joint_trajectory_position_controller $(ros2 pkg prefix ros2_control_demo_example_1 --share)/config/rrbot_jtc.yaml
    
       .. group-tab:: Docker
    
         (from the docker terminal, see above)
    
         .. code-block:: shell
    
           ros2 control load_controller --set-state inactive joint_trajectory_position_controller $(ros2 pkg prefix ros2_control_demo_example_1 --share)/config/rrbot_jtc.yaml
    
    

    You should get the result Successfully loaded controller joint_trajectory_position_controller into state inactive.

    See if it loaded properly with

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 control list_controllers
    
       .. group-tab:: Docker
    
         (from the docker terminal, see above)
    
         .. code-block:: shell
    
           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

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 control set_controller_state forward_position_controller inactive
           ros2 control set_controller_state joint_trajectory_position_controller active
    
       .. group-tab:: Docker
    
         (from the docker terminal, see above)
    
         .. code-block:: shell
    
           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

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 control switch_controllers --activate joint_trajectory_position_controller --deactivate forward_position_controller
    
       .. group-tab:: Docker
    
         (from the docker terminal, see above)
    
         .. code-block:: shell
    
           ros2 control switch_controllers --activate joint_trajectory_position_controller --deactivate forward_position_controller
    
    

    Again, check via

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 control list_controllers
    
       .. group-tab:: Docker
    
         (from the docker terminal, see above)
    
         .. code-block:: shell
    
           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

    .. tabs::
    
       .. group-tab:: Local
    
         .. code-block:: shell
    
           ros2 launch ros2_control_demo_example_1 test_joint_trajectory_controller.launch.py
    
       .. group-tab:: Docker
    
         (from the docker terminal, see above)
    
         .. code-block:: shell
    
           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