From 55408d1689eff1264013c33788281f15a34f7781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20Fr=C3=B6hlich?= Date: Wed, 27 Sep 2023 06:46:57 +0200 Subject: [PATCH] Update docker instructions (#351) * Update docker instructions * Update userdoc.rst --------- Co-authored-by: Olivier Stasse (cherry picked from commit 07a897f2c123065f1b283966ef7b1b2e30704ded) --- Dockerfile/entrypoint.sh | 3 +- doc/run_from_docker.rst | 8 +- example_1/doc/userdoc.rst | 313 ++++++++++++++++++++++++++++++++------ 3 files changed, 268 insertions(+), 56 deletions(-) diff --git a/Dockerfile/entrypoint.sh b/Dockerfile/entrypoint.sh index 8516e83a7..336c4dfa5 100755 --- a/Dockerfile/entrypoint.sh +++ b/Dockerfile/entrypoint.sh @@ -1,5 +1,6 @@ #!/bin/sh . /opt/ros/"${ROS_DISTRO}"/setup.sh -. /home/ros2_ws/install/setup.sh +cd /home/ros2_ws +. install/setup.sh exec "$@" diff --git a/doc/run_from_docker.rst b/doc/run_from_docker.rst index f4339e857..007edc1d8 100644 --- a/doc/run_from_docker.rst +++ b/doc/run_from_docker.rst @@ -1,9 +1,3 @@ .. note:: - The commands below are given for a local installation of this repository and its dependencies. If you use the provided docker container, add the prefix - - .. code:: - - docker run -it --rm --name ros2_control_demos --net host ros2_control_demos - - to every command followed by a ``gui:=false``. For more information on the docker usage see :ref:`ros2_control_demos_install`. + 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 :ref:`doc/ros2_control_demos/doc/index:using docker`. diff --git a/example_1/doc/userdoc.rst b/example_1/doc/userdoc.rst index 48380024b..2fdb882ec 100644 --- a/example_1/doc/userdoc.rst +++ b/example_1/doc/userdoc.rst @@ -26,9 +26,38 @@ Tutorial steps 1. (Optional) To check that *RRBot* descriptions are working properly use following launch commands - .. code-block:: shell + .. 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 - ros2 launch ros2_control_demo_example_1 view_robot.launch.py + 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:: @@ -41,24 +70,29 @@ Tutorial steps :width: 400 :alt: Revolute-Revolute Manipulator Robot - The *RViz* setup can be recreated following these steps: + Once it is working you can stop rviz using CTRL+C as the next launch file is starting RViz. - * The robot models can be visualized using ``RobotModel`` display using ``/robot_description`` topic. - * Or you can simply open the configuration from ``description/rviz`` folder manually or directly by executing +2. To start *RRBot* example open a terminal, source your ROS2-workspace and execute its launch file with - .. code-block:: shell + .. tabs:: - rviz2 --display-config `ros2 pkg prefix ros2_control_demo_example_1`/share/ros2_control_demo_example_1/rviz/rrbot.rviz + .. group-tab:: Local - Once it is working you can stop rviz using CTRL+C as the next launch file is starting RViz. + .. code-block:: shell -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 - .. code-block:: shell + The launch file loads and starts the robot hardware, controllers and opens *RViz*. + + .. group-tab:: Docker + + .. code-block:: shell - ros2 launch ros2_control_demo_example_1 rrbot.launch.py + 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. - 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. @@ -67,9 +101,29 @@ Tutorial steps 3. Check if the hardware interface loaded properly, by opening another terminal and executing - .. code-block:: shell + .. 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 - ros2 control list_hardware_interfaces + If everything started nominally, you should see the output .. code-block:: shell @@ -84,9 +138,23 @@ Tutorial steps 4. Check if controllers are running by - .. code-block:: shell + .. 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 - ros2 control list_controllers + You will see the two controllers in active state .. code-block:: shell @@ -97,17 +165,43 @@ Tutorial steps a. Manually using ROS 2 CLI interface: - .. code-block:: shell + .. tabs:: - ros2 topic pub /forward_position_controller/commands std_msgs/msg/Float64MultiArray "data: - - 0.5 - - 0.5" + .. group-tab:: Local - B. Or you can start a demo node which sends two goals every 5 seconds in a loop + .. code-block:: shell - .. 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" + + B. Or you can start a demo node which sends two goals every 5 seconds in a loop: + + .. tabs:: - ros2 launch ros2_control_demo_example_1 test_forward_position_controller.launch.py + .. 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. @@ -119,23 +213,61 @@ Tutorial steps If you echo the ``/joint_states`` or ``/dynamic_joint_states`` topics you should now get similar values, namely the simulated states of the robot - .. code-block:: shell + .. 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 - 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 - .. code-block:: shell + .. tabs:: - ros2 control load_controller joint_trajectory_position_controller + .. group-tab:: Local - what should return ``Successfully loaded controller joint_trajectory_position_controller``. Check the status + .. code-block:: shell - .. code-block:: shell + ros2 control load_controller joint_trajectory_position_controller + + .. group-tab:: Docker + + (from the docker terminal, see above) + + .. code-block:: shell + + ros2 control load_controller joint_trajectory_position_controller + + what should return ``Successfully loaded controller joint_trajectory_position_controller``. Check the status with + + .. tabs:: + + .. group-tab:: Local - ros2 control list_controllers + .. 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. @@ -147,9 +279,21 @@ Tutorial steps Configure the controller by setting it ``inactive`` by - .. code-block:: shell + .. tabs:: + + .. group-tab:: Local + + .. code-block:: shell - ros2 control set_controller_state joint_trajectory_position_controller inactive + 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``. @@ -158,19 +302,43 @@ Tutorial steps 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`` + As an alternative, you can load the controller directly in ``inactive``-state by means of the option for ``load_controller`` with - .. code-block:: shell + .. tabs:: + + .. group-tab:: Local + + .. code-block:: shell + + ros2 control load_controller joint_trajectory_position_controller --set-state inactive - ros2 control load_controller joint_trajectory_position_controller --set-state inactive + .. group-tab:: Docker + + (from the docker terminal, see above) + + .. code-block:: shell + + 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 - .. code-block:: shell + .. tabs:: + + .. group-tab:: Local + + .. code-block:: shell + + ros2 control list_controllers - ros2 control list_controllers + .. group-tab:: Docker + + (from the docker terminal, see above) + + .. code-block:: shell + + ros2 control list_controllers what should now return @@ -182,22 +350,59 @@ Tutorial steps Note that the controller is loaded but still ``inactive``. Now you can switch the controller by - .. code-block:: shell + .. 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 - ros2 control set_controller_state forward_position_controller inactive - ros2 control set_controller_state joint_trajectory_position_controller active + (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 - .. code-block:: shell + .. 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) - ros2 control switch_controllers --activate joint_trajectory_position_controller --deactivate forward_position_controller + .. code-block:: shell + + ros2 control switch_controllers --activate joint_trajectory_position_controller --deactivate forward_position_controller Again, check via - .. code-block:: shell + .. 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 + ros2 control list_controllers what should now return @@ -207,11 +412,23 @@ Tutorial steps 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: + Send a command to the controller using demo node, which sends four goals every 6 seconds in a loop with - .. code-block:: shell + .. 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 + ros2 launch ros2_control_demo_example_1 test_joint_trajectory_controller.launch.py You can adjust the goals in `rrbot_joint_trajectory_publisher `__.