diff --git a/README.md b/README.md index 0498731d5..83b6ff9da 100644 --- a/README.md +++ b/README.md @@ -78,34 +78,6 @@ The important files to check in each example are: The concepts in this package are demonstrated on the examples of *RRBot* and *DiffBot*. Those two world-known imaginary robots are trivial simulations to demonstrate and test `ros2_control` concepts. -## Usage -### Using Docker -**Building your own** - -```bash -mkdir -p ~/ros2_ws/src -cd ~/ros2_ws/src -git clone https://github.com/ros-controls/ros2_control_demos -cd ros2_control_demos -docker build . -t ros2_control_demos -f Dockerfile/Dockerfile -``` - -**To run the demo** - -Docker allows us to run the demo without the GUI if configured properly. The following command runs the demo without the GUI: -```bash -docker run -it --rm ros2_control_demos -``` - -Then on your local machine, you can run rviz with the config file specified: - -```bash -cd ~/ros2_ws -source /opt/ros/rolling/setup.sh -rviz2 -d src/ros2_control_demos/example_2/description/rviz/diffbot.rviz -``` - - ## Build status ROS 2 Distro | Branch | Build status | Documentation @@ -129,27 +101,3 @@ ROS 2 Distro | Branch | Build status | Documentation Uses repos file: `src/$NAME$/$NAME$.repos` 1. Source build - also core ROS packages are build from source. It shows potential issues in the mid future. - - -# Build from source -``` -git clone https://github.com/ros-controls/ros2_control -git clone https://github.com/ros-controls/ros2_controllers -git clone https://github.com/ros-controls/ros2_control_demos -``` - -**NOTE**: `ros2_control` and `ros2_controllers` packages are released and can be installed using a package manager. -We provide officially released and maintained debian packages, which can easily be installed via aptitude. -However, there might be cases in which not-yet released demos or features are only available through a source build in your own workspace. - -* Install dependencies: - ``` - rosdep install --from-paths src --ignore-src -r -y - ``` - -* Build everything, e.g. with: - ``` - colcon build --symlink-install - ``` - -* Do not forget to source `setup.bash` from the `install` folder! diff --git a/doc/index.rst b/doc/index.rst index 42d794409..1d8122187 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -70,6 +70,160 @@ Example 8: "Using transmissions" Example 9: "Gazebo Classic" Demonstrates how to switch between simulation and hardware. + +.. _ros2_control_demos_install: + +===================== +Installation +===================== + +You can install the demos manually or use the provided docker file. + +Manual Install +--------------- + +First, you have to install `ROS 2 on your computer `__. + +.. note:: + + ``ros2_control`` and ``ros2_controllers`` packages are released and can be installed using a package manager. + We provide officially released and maintained debian packages, which can easily be installed via aptitude. + However, there might be cases in which not-yet released demos or features are only available through a source build in your own workspace. + +Build from debian packages +^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Download the ``ros2_control_demos`` repository and install its dependencies with + +.. code-block:: shell + + mkdir -p ~/ros2_ws/src + cd ~/ros2_ws/src + git clone https://github.com/ros-controls/ros2_control_demos + cd ~/ros2_ws/ + rosdep update --rosdistro=$ROS_DISTRO + sudo apt-get update + sudo rosdep install --from-paths ./ -i -y --rosdistro ${ROS_DISTRO} + +Now you can build the repository (source your ROS 2 installation first) + +.. code-block:: shell + + cd ~/ros2_ws/ + . /opt/ros/${ROS_DISTRO}/setup.sh + colcon build --merge-install + + +Build from source +^^^^^^^^^^^^^^^^^ + +* Download all repositories + + .. code-block:: shell + + mkdir -p ~/ros2_ws/src + cd ~/ros2_ws/src + git clone https://github.com/ros-controls/ros2_control_demos + cd ~/ros2_ws/ + vcs import src < src/ros2_control_demos/ros2_control_demos.$ROS_DISTRO.repos + rosdep update --rosdistro=$ROS_DISTRO + sudo apt-get update + +* Install dependencies: + + .. code-block:: shell + + rosdep install --from-paths src --ignore-src -r -y + +* Build everything, e.g. with: + + .. code-block:: shell + + . /opt/ros/${ROS_DISTRO}/setup.sh + colcon build --symlink-install + +* Do not forget to source ``setup.bash`` from the ``install`` folder! + +Using Docker +--------------- + +First, build the dockerfile with + +.. code-block:: shell + + mkdir -p ~/ros2_ws/src + cd ~/ros2_ws/src + git clone https://github.com/ros-controls/ros2_control_demos + cd ros2_control_demos + docker build . -t ros2_control_demos -f Dockerfile/Dockerfile + +To view the robot +^^^^^^^^^^^^^^^^^ + +Docker now allows us to run the demo without the GUI if configured properly. Now we can view the robot by the following procedure: + +After having `ROS 2 installed `__ on your local system (not inside the docker), we can use ``rviz2`` to visualize the robot state and ``joint_state_publisher_gui`` package to give manual joint values to the robot. To install the package you can run: + +.. code-block:: shell + + sudo apt-get install -y ros-${ROS_DISTRO}-joint-state-publisher-gui ros-${ROS_DISTRO}-rviz2 + +Then we are ready to bring up all the components to view the robot. 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_demos_example_1 view_robot.launch.py gui:=false + +.. note:: + + Depending on your machine settings, it might be possible that you have to omit ``--net host``. + +Now, we need to start ``rviz2`` to view the robot as well as ``joint_state_publisher_gui``, each in their own terminals after sourcing our ROS 2 installation. + +Terminal 1: + +.. code-block:: shell + + source /opt/ros/${ROS_DISTRO}/setup.bash + ros2 run joint_state_publisher_gui joint_state_publisher_gui + +Terminal 2: + +.. code-block:: shell + + source /opt/ros/${ROS_DISTRO}/setup.bash + cd ~/ros2_ws + rviz2 -d src/ros2_control_demos/example_1/description/rviz/rrbot.rviz + +Now, you can see the robot moving by changing the values of the joints by moving the sliders around in the ``joint_state_publisher_gui``. + +To run the ros2_control demos +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The following command runs the demo without the GUI: + +.. code-block:: shell + + docker run -it --rm --name ros2_control_demos --net host ros2_control_demos + +.. note:: + + Depending on your machine settings, it might be possible that you have to omit ``--net host``. + +Then on your local machine, you can run rviz2 with the config file specified: + +.. code-block:: shell + + cd ~/ros2_ws + source /opt/ros/${ROS_DISTRO}/setup.sh + rviz2 -d src/ros2_control_demos/example_1/description/rviz/rrbot.rviz + +You can also run other commands or launch files from the docker, e.g. + +.. code-block:: shell + + docker run -it --rm --name ros2_control_demos --net host ros2_control_demos ros2 launch ros2_control_demo_example_2 diffbot.launch.py + ===================== Quick Hints ===================== diff --git a/doc/run_from_docker.rst b/doc/run_from_docker.rst new file mode 100644 index 000000000..f4339e857 --- /dev/null +++ b/doc/run_from_docker.rst @@ -0,0 +1,9 @@ +.. 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`. diff --git a/example_1/bringup/launch/rrbot.launch.py b/example_1/bringup/launch/rrbot.launch.py index 7323474df..6eab86b32 100644 --- a/example_1/bringup/launch/rrbot.launch.py +++ b/example_1/bringup/launch/rrbot.launch.py @@ -28,14 +28,14 @@ def generate_launch_description(): declared_arguments = [] declared_arguments.append( DeclareLaunchArgument( - "start_rviz", + "gui", default_value="true", description="Start RViz2 automatically with this launch file.", ) ) # Initialize Arguments - start_rviz = LaunchConfiguration("start_rviz") + gui = LaunchConfiguration("gui") # Get URDF via xacro robot_description_content = Command( @@ -82,7 +82,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], - condition=IfCondition(start_rviz), + condition=IfCondition(gui), ) joint_state_broadcaster_spawner = Node( diff --git a/example_1/description/launch/view_robot.launch.py b/example_1/description/launch/view_robot.launch.py index 5295d4531..110a2e45c 100644 --- a/example_1/description/launch/view_robot.launch.py +++ b/example_1/description/launch/view_robot.launch.py @@ -14,6 +14,7 @@ from launch import LaunchDescription from launch.actions import DeclareLaunchArgument +from launch.conditions import IfCondition from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution from launch_ros.actions import Node @@ -38,6 +39,14 @@ def generate_launch_description(): description="URDF/XACRO description file with the robot.", ) ) + declared_arguments.append( + DeclareLaunchArgument( + "gui", + default_value="true", + description="Start Rviz2 and Joint State Publisher gui automatically \ + with this launch file.", + ) + ) declared_arguments.append( DeclareLaunchArgument( "prefix", @@ -51,6 +60,7 @@ def generate_launch_description(): # Initialize Arguments description_package = LaunchConfiguration("description_package") description_file = LaunchConfiguration("description_file") + gui = LaunchConfiguration("gui") prefix = LaunchConfiguration("prefix") # Get URDF via xacro @@ -75,6 +85,7 @@ def generate_launch_description(): joint_state_publisher_node = Node( package="joint_state_publisher_gui", executable="joint_state_publisher_gui", + condition=IfCondition(gui), ) robot_state_publisher_node = Node( package="robot_state_publisher", @@ -88,6 +99,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], + condition=IfCondition(gui), ) nodes = [ diff --git a/example_1/doc/userdoc.rst b/example_1/doc/userdoc.rst index a3bb5e50e..ed825a431 100644 --- a/example_1/doc/userdoc.rst +++ b/example_1/doc/userdoc.rst @@ -19,6 +19,8 @@ For *example_1*, the hardware interface plugin is implemented having only one in The *RRBot* URDF files can be found in the ``description/urdf`` folder. +.. include:: ../../doc/run_from_docker.rst + Tutorial steps -------------------------- diff --git a/example_2/bringup/launch/diffbot.launch.py b/example_2/bringup/launch/diffbot.launch.py index c9cba5f10..b07d4e448 100644 --- a/example_2/bringup/launch/diffbot.launch.py +++ b/example_2/bringup/launch/diffbot.launch.py @@ -27,14 +27,14 @@ def generate_launch_description(): declared_arguments = [] declared_arguments.append( DeclareLaunchArgument( - "start_rviz", + "gui", default_value="true", description="Start RViz2 automatically with this launch file.", ) ) # Initialize Arguments - start_rviz = LaunchConfiguration("start_rviz") + gui = LaunchConfiguration("gui") # Get URDF via xacro robot_description_content = Command( @@ -80,7 +80,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], - condition=IfCondition(start_rviz), + condition=IfCondition(gui), ) joint_state_broadcaster_spawner = Node( diff --git a/example_2/description/launch/view_robot.launch.py b/example_2/description/launch/view_robot.launch.py index badd807c2..650994e76 100644 --- a/example_2/description/launch/view_robot.launch.py +++ b/example_2/description/launch/view_robot.launch.py @@ -14,6 +14,7 @@ from launch import LaunchDescription from launch.actions import DeclareLaunchArgument +from launch.conditions import IfCondition from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution from launch_ros.actions import Node @@ -38,6 +39,14 @@ def generate_launch_description(): description="URDF/XACRO description file with the robot.", ) ) + declared_arguments.append( + DeclareLaunchArgument( + "gui", + default_value="true", + description="Start Rviz2 and Joint State Publisher gui automatically \ + with this launch file.", + ) + ) declared_arguments.append( DeclareLaunchArgument( "prefix", @@ -51,6 +60,7 @@ def generate_launch_description(): # Initialize Arguments description_package = LaunchConfiguration("description_package") description_file = LaunchConfiguration("description_file") + gui = LaunchConfiguration("gui") prefix = LaunchConfiguration("prefix") # Get URDF via xacro @@ -75,6 +85,7 @@ def generate_launch_description(): joint_state_publisher_node = Node( package="joint_state_publisher_gui", executable="joint_state_publisher_gui", + condition=IfCondition(gui), ) robot_state_publisher_node = Node( package="robot_state_publisher", @@ -88,6 +99,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], + condition=IfCondition(gui), ) nodes = [ diff --git a/example_2/doc/userdoc.rst b/example_2/doc/userdoc.rst index 56cd21b3f..4754aade0 100644 --- a/example_2/doc/userdoc.rst +++ b/example_2/doc/userdoc.rst @@ -16,6 +16,8 @@ For *example_2*, the hardware interface plugin is implemented having only one in The *DiffBot* URDF files can be found in ``description/urdf`` folder. +.. include:: ../../doc/run_from_docker.rst + Tutorial steps -------------------------- diff --git a/example_3/bringup/launch/rrbot_system_multi_interface.launch.py b/example_3/bringup/launch/rrbot_system_multi_interface.launch.py index 4ae3d116d..980d363f9 100644 --- a/example_3/bringup/launch/rrbot_system_multi_interface.launch.py +++ b/example_3/bringup/launch/rrbot_system_multi_interface.launch.py @@ -63,7 +63,7 @@ def generate_launch_description(): ) declared_arguments.append( DeclareLaunchArgument( - "start_rviz", + "gui", default_value="true", description="Start RViz2 automatically with this launch file.", ) @@ -75,7 +75,7 @@ def generate_launch_description(): mock_sensor_commands = LaunchConfiguration("mock_sensor_commands") slowdown = LaunchConfiguration("slowdown") robot_controller = LaunchConfiguration("robot_controller") - start_rviz = LaunchConfiguration("start_rviz") + gui = LaunchConfiguration("gui") # Get URDF via xacro robot_description_content = Command( @@ -134,7 +134,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], - condition=IfCondition(start_rviz), + condition=IfCondition(gui), ) joint_state_broadcaster_spawner = Node( diff --git a/example_3/description/launch/view_robot.launch.py b/example_3/description/launch/view_robot.launch.py index aa56706f4..53e4dc03f 100644 --- a/example_3/description/launch/view_robot.launch.py +++ b/example_3/description/launch/view_robot.launch.py @@ -14,6 +14,7 @@ from launch import LaunchDescription from launch.actions import DeclareLaunchArgument +from launch.conditions import IfCondition from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution from launch_ros.actions import Node @@ -38,6 +39,14 @@ def generate_launch_description(): description="URDF/XACRO description file with the robot.", ) ) + declared_arguments.append( + DeclareLaunchArgument( + "gui", + default_value="true", + description="Start Rviz2 and Joint State Publisher gui automatically \ + with this launch file.", + ) + ) declared_arguments.append( DeclareLaunchArgument( "prefix", @@ -51,6 +60,7 @@ def generate_launch_description(): # Initialize Arguments description_package = LaunchConfiguration("description_package") description_file = LaunchConfiguration("description_file") + gui = LaunchConfiguration("gui") prefix = LaunchConfiguration("prefix") # Get URDF via xacro @@ -75,6 +85,7 @@ def generate_launch_description(): joint_state_publisher_node = Node( package="joint_state_publisher_gui", executable="joint_state_publisher_gui", + condition=IfCondition(gui), ) robot_state_publisher_node = Node( package="robot_state_publisher", @@ -88,6 +99,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], + condition=IfCondition(gui), ) nodes = [ diff --git a/example_3/doc/userdoc.rst b/example_3/doc/userdoc.rst index 09c54362b..4481d854b 100644 --- a/example_3/doc/userdoc.rst +++ b/example_3/doc/userdoc.rst @@ -16,6 +16,8 @@ For *example_3*, the hardware interface plugin is implemented having multiple in Two illegal controllers demonstrate how hardware interface declines faulty claims to access joint command interfaces. +.. include:: ../../doc/run_from_docker.rst + Tutorial steps -------------------------- diff --git a/example_4/bringup/launch/rrbot_system_with_sensor.launch.py b/example_4/bringup/launch/rrbot_system_with_sensor.launch.py index 80db70574..7e78ff092 100644 --- a/example_4/bringup/launch/rrbot_system_with_sensor.launch.py +++ b/example_4/bringup/launch/rrbot_system_with_sensor.launch.py @@ -56,7 +56,7 @@ def generate_launch_description(): ) declared_arguments.append( DeclareLaunchArgument( - "start_rviz", + "gui", default_value="true", description="Start RViz2 automatically with this launch file.", ) @@ -67,7 +67,7 @@ def generate_launch_description(): use_mock_hardware = LaunchConfiguration("use_mock_hardware") mock_sensor_commands = LaunchConfiguration("mock_sensor_commands") slowdown = LaunchConfiguration("slowdown") - start_rviz = LaunchConfiguration("start_rviz") + gui = LaunchConfiguration("gui") # Get URDF via xacro robot_description_content = Command( @@ -126,7 +126,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], - condition=IfCondition(start_rviz), + condition=IfCondition(gui), ) joint_state_broadcaster_spawner = Node( diff --git a/example_4/description/launch/view_robot.launch.py b/example_4/description/launch/view_robot.launch.py index b8084832a..c72b1579b 100644 --- a/example_4/description/launch/view_robot.launch.py +++ b/example_4/description/launch/view_robot.launch.py @@ -14,6 +14,7 @@ from launch import LaunchDescription from launch.actions import DeclareLaunchArgument +from launch.conditions import IfCondition from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution from launch_ros.actions import Node @@ -38,6 +39,14 @@ def generate_launch_description(): description="URDF/XACRO description file with the robot.", ) ) + declared_arguments.append( + DeclareLaunchArgument( + "gui", + default_value="true", + description="Start Rviz2 and Joint State Publisher gui automatically \ + with this launch file.", + ) + ) declared_arguments.append( DeclareLaunchArgument( "prefix", @@ -51,6 +60,7 @@ def generate_launch_description(): # Initialize Arguments description_package = LaunchConfiguration("description_package") description_file = LaunchConfiguration("description_file") + gui = LaunchConfiguration("gui") prefix = LaunchConfiguration("prefix") # Get URDF via xacro @@ -75,6 +85,7 @@ def generate_launch_description(): joint_state_publisher_node = Node( package="joint_state_publisher_gui", executable="joint_state_publisher_gui", + condition=IfCondition(gui), ) robot_state_publisher_node = Node( package="robot_state_publisher", @@ -88,6 +99,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], + condition=IfCondition(gui), ) nodes = [ diff --git a/example_4/doc/userdoc.rst b/example_4/doc/userdoc.rst index 1f9d72e47..6c70870f5 100644 --- a/example_4/doc/userdoc.rst +++ b/example_4/doc/userdoc.rst @@ -16,6 +16,7 @@ This example shows how a sensor can be integrated in a hardware interface: A 2D Force-Torque Sensor (FTS) is simulated by generating random sensor readings via a hardware interface of type ``hardware_interface::SystemInterface``. +.. include:: ../../doc/run_from_docker.rst Tutorial steps -------------------------- diff --git a/example_5/bringup/launch/rrbot_system_with_external_sensor.launch.py b/example_5/bringup/launch/rrbot_system_with_external_sensor.launch.py index 4c963ee8e..1811949c5 100755 --- a/example_5/bringup/launch/rrbot_system_with_external_sensor.launch.py +++ b/example_5/bringup/launch/rrbot_system_with_external_sensor.launch.py @@ -56,7 +56,7 @@ def generate_launch_description(): ) declared_arguments.append( DeclareLaunchArgument( - "start_rviz", + "gui", default_value="true", description="Start RViz2 automatically with this launch file.", ) @@ -67,7 +67,7 @@ def generate_launch_description(): use_mock_hardware = LaunchConfiguration("use_mock_hardware") mock_sensor_commands = LaunchConfiguration("mock_sensor_commands") slowdown = LaunchConfiguration("slowdown") - start_rviz = LaunchConfiguration("start_rviz") + gui = LaunchConfiguration("gui") # Get URDF via xacro robot_description_content = Command( @@ -126,7 +126,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], - condition=IfCondition(start_rviz), + condition=IfCondition(gui), ) joint_state_broadcaster_spawner = Node( diff --git a/example_5/description/launch/view_robot.launch.py b/example_5/description/launch/view_robot.launch.py index fc954989a..df4cef17b 100644 --- a/example_5/description/launch/view_robot.launch.py +++ b/example_5/description/launch/view_robot.launch.py @@ -14,6 +14,7 @@ from launch import LaunchDescription from launch.actions import DeclareLaunchArgument +from launch.conditions import IfCondition from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution from launch_ros.actions import Node @@ -38,6 +39,14 @@ def generate_launch_description(): description="URDF/XACRO description file with the robot.", ) ) + declared_arguments.append( + DeclareLaunchArgument( + "gui", + default_value="true", + description="Start Rviz2 and Joint State Publisher gui automatically \ + with this launch file.", + ) + ) declared_arguments.append( DeclareLaunchArgument( "prefix", @@ -51,6 +60,7 @@ def generate_launch_description(): # Initialize Arguments description_package = LaunchConfiguration("description_package") description_file = LaunchConfiguration("description_file") + gui = LaunchConfiguration("gui") prefix = LaunchConfiguration("prefix") # Get URDF via xacro @@ -75,6 +85,7 @@ def generate_launch_description(): joint_state_publisher_node = Node( package="joint_state_publisher_gui", executable="joint_state_publisher_gui", + condition=IfCondition(gui), ) robot_state_publisher_node = Node( package="robot_state_publisher", @@ -88,6 +99,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], + condition=IfCondition(gui), ) nodes = [ diff --git a/example_5/doc/userdoc.rst b/example_5/doc/userdoc.rst index 24bed872a..2e6266f86 100644 --- a/example_5/doc/userdoc.rst +++ b/example_5/doc/userdoc.rst @@ -16,6 +16,8 @@ This example shows how an externally connected sensor can be accessed: A 3D Force-Torque Sensor (FTS) is simulated by generating random sensor readings via a hardware interface of type ``hardware_interface::SensorInterface``. +.. include:: ../../doc/run_from_docker.rst + Tutorial steps -------------------------- diff --git a/example_6/bringup/launch/rrbot_modular_actuators.launch.py b/example_6/bringup/launch/rrbot_modular_actuators.launch.py index 384df6230..c327b19af 100644 --- a/example_6/bringup/launch/rrbot_modular_actuators.launch.py +++ b/example_6/bringup/launch/rrbot_modular_actuators.launch.py @@ -63,7 +63,7 @@ def generate_launch_description(): ) declared_arguments.append( DeclareLaunchArgument( - "start_rviz", + "gui", default_value="true", description="Start RViz2 automatically with this launch file.", ) @@ -75,7 +75,7 @@ def generate_launch_description(): mock_sensor_commands = LaunchConfiguration("mock_sensor_commands") slowdown = LaunchConfiguration("slowdown") robot_controller = LaunchConfiguration("robot_controller") - start_rviz = LaunchConfiguration("start_rviz") + gui = LaunchConfiguration("gui") # Get URDF via xacro robot_description_content = Command( @@ -134,7 +134,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], - condition=IfCondition(start_rviz), + condition=IfCondition(gui), ) joint_state_broadcaster_spawner = Node( diff --git a/example_6/description/launch/view_robot.launch.py b/example_6/description/launch/view_robot.launch.py index dc6fc976a..1d671d762 100644 --- a/example_6/description/launch/view_robot.launch.py +++ b/example_6/description/launch/view_robot.launch.py @@ -14,6 +14,7 @@ from launch import LaunchDescription from launch.actions import DeclareLaunchArgument +from launch.conditions import IfCondition from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution from launch_ros.actions import Node @@ -38,6 +39,14 @@ def generate_launch_description(): description="URDF/XACRO description file with the robot.", ) ) + declared_arguments.append( + DeclareLaunchArgument( + "gui", + default_value="true", + description="Start Rviz2 and Joint State Publisher gui automatically \ + with this launch file.", + ) + ) declared_arguments.append( DeclareLaunchArgument( "prefix", @@ -51,6 +60,7 @@ def generate_launch_description(): # Initialize Arguments description_package = LaunchConfiguration("description_package") description_file = LaunchConfiguration("description_file") + gui = LaunchConfiguration("gui") prefix = LaunchConfiguration("prefix") # Get URDF via xacro @@ -75,6 +85,7 @@ def generate_launch_description(): joint_state_publisher_node = Node( package="joint_state_publisher_gui", executable="joint_state_publisher_gui", + condition=IfCondition(gui), ) robot_state_publisher_node = Node( package="robot_state_publisher", @@ -88,6 +99,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], + condition=IfCondition(gui), ) nodes = [ diff --git a/example_6/doc/userdoc.rst b/example_6/doc/userdoc.rst index eb68c85ac..9f6de521d 100644 --- a/example_6/doc/userdoc.rst +++ b/example_6/doc/userdoc.rst @@ -14,6 +14,8 @@ The example shows how to implement robot hardware with separate communication to This is implemented with a hardware interface of type ``hardware_interface::ActuatorInterface``. +.. include:: ../../doc/run_from_docker.rst + Tutorial steps -------------------------- diff --git a/example_8/bringup/launch/rrbot_transmissions_system_position_only.launch.py b/example_8/bringup/launch/rrbot_transmissions_system_position_only.launch.py index 6209560bf..d5c00e9d5 100644 --- a/example_8/bringup/launch/rrbot_transmissions_system_position_only.launch.py +++ b/example_8/bringup/launch/rrbot_transmissions_system_position_only.launch.py @@ -48,7 +48,7 @@ def generate_launch_description(): ) declared_arguments.append( DeclareLaunchArgument( - "start_rviz", + "gui", default_value="true", description="Start RViz2 automatically with this launch file.", ) @@ -58,7 +58,7 @@ def generate_launch_description(): prefix = LaunchConfiguration("prefix") slowdown = LaunchConfiguration("slowdown") robot_controller = LaunchConfiguration("robot_controller") - start_rviz = LaunchConfiguration("start_rviz") + gui = LaunchConfiguration("gui") # Get URDF via xacro robot_description_content = Command( @@ -111,7 +111,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], - condition=IfCondition(start_rviz), + condition=IfCondition(gui), ) joint_state_broadcaster_spawner = Node( diff --git a/example_8/description/launch/view_robot.launch.py b/example_8/description/launch/view_robot.launch.py index bfe1aeaf5..7bac36d9c 100644 --- a/example_8/description/launch/view_robot.launch.py +++ b/example_8/description/launch/view_robot.launch.py @@ -14,6 +14,7 @@ from launch import LaunchDescription from launch.actions import DeclareLaunchArgument +from launch.conditions import IfCondition from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution from launch_ros.actions import Node @@ -38,6 +39,14 @@ def generate_launch_description(): description="URDF/XACRO description file with the robot.", ) ) + declared_arguments.append( + DeclareLaunchArgument( + "gui", + default_value="true", + description="Start Rviz2 and Joint State Publisher gui automatically \ + with this launch file.", + ) + ) declared_arguments.append( DeclareLaunchArgument( "prefix", @@ -51,6 +60,7 @@ def generate_launch_description(): # Initialize Arguments description_package = LaunchConfiguration("description_package") description_file = LaunchConfiguration("description_file") + gui = LaunchConfiguration("gui") prefix = LaunchConfiguration("prefix") # Get URDF via xacro @@ -75,6 +85,7 @@ def generate_launch_description(): joint_state_publisher_node = Node( package="joint_state_publisher_gui", executable="joint_state_publisher_gui", + condition=IfCondition(gui), ) robot_state_publisher_node = Node( package="robot_state_publisher", @@ -88,6 +99,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], + condition=IfCondition(gui), ) nodes = [ diff --git a/example_8/doc/userdoc.rst b/example_8/doc/userdoc.rst index 1ee54668e..e417a2dca 100644 --- a/example_8/doc/userdoc.rst +++ b/example_8/doc/userdoc.rst @@ -13,6 +13,8 @@ In this example, both joints use an exposed transmission interface: * The communication is done using proprietary API to communicate with the robot control box. * Data for all joints is exchanged at once. +.. include:: ../../doc/run_from_docker.rst + Tutorial steps -------------------------- diff --git a/example_9/bringup/launch/rrbot.launch.py b/example_9/bringup/launch/rrbot.launch.py index bf70947c6..aa8ca9134 100644 --- a/example_9/bringup/launch/rrbot.launch.py +++ b/example_9/bringup/launch/rrbot.launch.py @@ -14,15 +14,30 @@ from launch import LaunchDescription -from launch.actions import RegisterEventHandler +from launch.actions import DeclareLaunchArgument, RegisterEventHandler +from launch.conditions import IfCondition from launch.event_handlers import OnProcessExit -from launch.substitutions import Command, FindExecutable, PathJoinSubstitution +from launch.substitutions import Command, FindExecutable, PathJoinSubstitution, LaunchConfiguration from launch_ros.actions import Node from launch_ros.substitutions import FindPackageShare def generate_launch_description(): + + # Declare arguments + declared_arguments = [] + declared_arguments.append( + DeclareLaunchArgument( + "gui", + default_value="true", + description="Start RViz2 automatically with this launch file.", + ) + ) + + # Initialize Arguments + gui = LaunchConfiguration("gui") + # Get URDF via xacro robot_description_content = Command( [ @@ -68,6 +83,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], + condition=IfCondition(gui), ) joint_state_broadcaster_spawner = Node( @@ -106,4 +122,4 @@ def generate_launch_description(): delay_robot_controller_spawner_after_joint_state_broadcaster_spawner, ] - return LaunchDescription(nodes) + return LaunchDescription(declared_arguments + nodes) diff --git a/example_9/bringup/launch/rrbot_gazebo_classic.launch.py b/example_9/bringup/launch/rrbot_gazebo_classic.launch.py index dd18a3e5f..4b9362154 100644 --- a/example_9/bringup/launch/rrbot_gazebo_classic.launch.py +++ b/example_9/bringup/launch/rrbot_gazebo_classic.launch.py @@ -13,14 +13,29 @@ # limitations under the License. from launch import LaunchDescription -from launch.actions import IncludeLaunchDescription +from launch.actions import DeclareLaunchArgument, IncludeLaunchDescription +from launch.conditions import IfCondition from launch.launch_description_sources import PythonLaunchDescriptionSource -from launch.substitutions import Command, FindExecutable, PathJoinSubstitution +from launch.substitutions import Command, FindExecutable, PathJoinSubstitution, LaunchConfiguration from launch_ros.actions import Node from launch_ros.substitutions import FindPackageShare def generate_launch_description(): + + # Declare arguments + declared_arguments = [] + declared_arguments.append( + DeclareLaunchArgument( + "gui", + default_value="false", + description="Start RViz2 automatically with this launch file.", + ) + ) + + # Initialize Arguments + gui = LaunchConfiguration("gui") + gazebo = IncludeLaunchDescription( PythonLaunchDescriptionSource( [PathJoinSubstitution([FindPackageShare("gazebo_ros"), "launch", "gazebo.launch.py"])] @@ -41,6 +56,9 @@ def generate_launch_description(): ] ) robot_description = {"robot_description": robot_description_content} + rviz_config_file = PathJoinSubstitution( + [FindPackageShare("ros2_control_demo_example_9"), "rviz", "rrbot.rviz"] + ) node_robot_state_publisher = Node( package="robot_state_publisher", @@ -67,13 +85,22 @@ def generate_launch_description(): executable="spawner", arguments=["forward_position_controller", "--controller-manager", "/controller_manager"], ) - - return LaunchDescription( - [ - gazebo, - node_robot_state_publisher, - spawn_entity, - joint_state_broadcaster_spawner, - robot_controller_spawner, - ] + rviz_node = Node( + package="rviz2", + executable="rviz2", + name="rviz2", + output="log", + arguments=["-d", rviz_config_file], + condition=IfCondition(gui), ) + + nodes = [ + gazebo, + node_robot_state_publisher, + spawn_entity, + joint_state_broadcaster_spawner, + robot_controller_spawner, + rviz_node, + ] + + return LaunchDescription(declared_arguments + nodes) diff --git a/example_9/description/launch/view_robot.launch.py b/example_9/description/launch/view_robot.launch.py index 14cd2edab..00e6ff0c4 100644 --- a/example_9/description/launch/view_robot.launch.py +++ b/example_9/description/launch/view_robot.launch.py @@ -14,6 +14,7 @@ from launch import LaunchDescription from launch.actions import DeclareLaunchArgument +from launch.conditions import IfCondition from launch.substitutions import Command, FindExecutable, LaunchConfiguration, PathJoinSubstitution from launch_ros.actions import Node @@ -38,6 +39,14 @@ def generate_launch_description(): description="URDF/XACRO description file with the robot.", ) ) + declared_arguments.append( + DeclareLaunchArgument( + "gui", + default_value="true", + description="Start Rviz2 and Joint State Publisher gui automatically \ + with this launch file.", + ) + ) declared_arguments.append( DeclareLaunchArgument( "prefix", @@ -51,6 +60,7 @@ def generate_launch_description(): # Initialize Arguments description_package = LaunchConfiguration("description_package") description_file = LaunchConfiguration("description_file") + gui = LaunchConfiguration("gui") prefix = LaunchConfiguration("prefix") # Get URDF via xacro @@ -75,6 +85,7 @@ def generate_launch_description(): joint_state_publisher_node = Node( package="joint_state_publisher_gui", executable="joint_state_publisher_gui", + condition=IfCondition(gui), ) robot_state_publisher_node = Node( package="robot_state_publisher", @@ -88,6 +99,7 @@ def generate_launch_description(): name="rviz2", output="log", arguments=["-d", rviz_config_file], + condition=IfCondition(gui), ) nodes = [ diff --git a/example_9/doc/userdoc.rst b/example_9/doc/userdoc.rst index d8dfc24f9..915067350 100644 --- a/example_9/doc/userdoc.rst +++ b/example_9/doc/userdoc.rst @@ -6,7 +6,34 @@ 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. For details on the ``gazebo_ros2_control`` plugin, see :ref:`gazebo_ros2_control`. +Gazebo Classic is used for this purpose. + +.. note:: + + Follow the installation instructions on :ref:`ros2_control_demos_install` 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 :ref:`ros2_control_demos_install`. To run the later steps using Gazebo Classic, execute + + .. code:: + + 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 + + .. code-block:: shell + + gzclient + + and/or ``rviz2`` with + + .. code-block:: shell + + rviz2 -d src/ros2_control_demos/example_9/description/rviz/rrbot.rviz + + + For details on the ``gazebo_ros2_control`` plugin, see :ref:`gazebo_ros2_control`. Tutorial steps --------------------------