From e2a30a796b7a2323ec46a14135cbadb0c11b6321 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Wed, 11 Sep 2024 21:20:11 +0200 Subject: [PATCH 1/4] Python example to launch gzserver. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- harmonic/ros2_launch_gazebo.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/harmonic/ros2_launch_gazebo.md b/harmonic/ros2_launch_gazebo.md index 6ed5e916d..6f5ca3b6d 100644 --- a/harmonic/ros2_launch_gazebo.md +++ b/harmonic/ros2_launch_gazebo.md @@ -100,3 +100,22 @@ def generate_launch_description(): ), ]) ``` + +Here's another example using a higher level action from Python to launch `gzserver`: +```python +from launch import LaunchDescription +from ros_gz_sim.actions import GzServer + + +def generate_launch_description(): + + # Create the launch description and populate + ld = LaunchDescription([ + GzServer( + world_sdf_file='shapes.sdf' + ), + ]) + + return ld + +``` From 48feb0327c13a21b942d8625f3668c5df385b827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Thu, 12 Sep 2024 16:23:53 +0200 Subject: [PATCH 2/4] Bridge example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- harmonic/ros2_integration.md | 48 +++++++++++++++++++++++++++++++++- harmonic/ros2_launch_gazebo.md | 12 +++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/harmonic/ros2_integration.md b/harmonic/ros2_integration.md index c45d03f6d..7d9d1393a 100644 --- a/harmonic/ros2_integration.md +++ b/harmonic/ros2_integration.md @@ -67,11 +67,18 @@ The package `ros_gz_bridge` contains a launch file named `ros_gz_bridge.launch.py`. You can use it to start a ROS 2 and Gazebo bridge. Here's an example: +Note: If you run the bridge as a standalone node with composition enabled (default configutation), +you'll need to create a container first. +```bash +ros2 run rclcpp_components component_container --ros-args -r __node:=ros_gz_container +``` + +And now, the container will load your bridge with: ```bash ros2 launch ros_gz_bridge ros_gz_bridge.launch.py name:=ros_gz_bridge config_file:= ``` -## Launching the bridge from a custom launch file. +## Launching the bridge from a custom launch file in XML. It's also possible to trigger the bridge from your custom launch file. For that purpose we have created the `` tag that can be used from you @@ -104,6 +111,45 @@ In this case the `` parameters are read from the command line. That's an option but not strictly necessary as you could decide to hardcode some of the values or not even use all the parameters. +## Launching the bridge from a custom launch file in Python. + +Here's a simplified example of a Python launch file used to load a bridge from +Python: +```python +from launch import LaunchDescription +from launch.actions import DeclareLaunchArgument +from launch.substitutions import LaunchConfiguration, TextSubstitution +from ros_gz_bridge.actions import RosGzBridge + + +def generate_launch_description(): + + bridge_name = LaunchConfiguration('bridge_name') + config_file = LaunchConfiguration('config_file') + + declare_bridge_name_cmd = DeclareLaunchArgument( + 'bridge_name', description='Name of ros_gz_bridge node' + ) + + declare_config_file_cmd = DeclareLaunchArgument( + 'config_file', description='YAML config file' + ) + + # Create the launch description and populate + ld = LaunchDescription([ + RosGzBridge( + bridge_name=LaunchConfiguration('bridge_name'), + config_file=LaunchConfiguration('config_file'), + ), + ]) + + # Declare the launch options + ld.add_action(declare_bridge_name_cmd) + ld.add_action(declare_config_file_cmd) + + return ld +``` + ## Publish key strokes to ROS Let's send messages to ROS using the `Key Publisher` an Gazebo plugin. diff --git a/harmonic/ros2_launch_gazebo.md b/harmonic/ros2_launch_gazebo.md index 6f5ca3b6d..2cbf10a2a 100644 --- a/harmonic/ros2_launch_gazebo.md +++ b/harmonic/ros2_launch_gazebo.md @@ -104,18 +104,26 @@ def generate_launch_description(): Here's another example using a higher level action from Python to launch `gzserver`: ```python from launch import LaunchDescription +from launch.actions import DeclareLaunchArgument +from launch.substitutions import LaunchConfiguration, TextSubstitution from ros_gz_sim.actions import GzServer def generate_launch_description(): + declare_world_sdf_file_cmd = DeclareLaunchArgument( + 'world_sdf_file', default_value=TextSubstitution(text=''), + description='Path to the SDF world file') + # Create the launch description and populate ld = LaunchDescription([ GzServer( - world_sdf_file='shapes.sdf' + world_sdf_file=LaunchConfiguration('world_sdf_file') ), ]) - return ld + # Declare the launch options + ld.add_action(declare_world_sdf_file_cmd) + return ld ``` From 24a8cf3d8af0043b810acfafd9588abfb8d0bf1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Fri, 13 Sep 2024 14:00:36 +0200 Subject: [PATCH 3/4] Do not use TextSubstitution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- harmonic/ros2_launch_gazebo.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/harmonic/ros2_launch_gazebo.md b/harmonic/ros2_launch_gazebo.md index 2cbf10a2a..a87c90a0e 100644 --- a/harmonic/ros2_launch_gazebo.md +++ b/harmonic/ros2_launch_gazebo.md @@ -105,14 +105,14 @@ Here's another example using a higher level action from Python to launch `gzserv ```python from launch import LaunchDescription from launch.actions import DeclareLaunchArgument -from launch.substitutions import LaunchConfiguration, TextSubstitution +from launch.substitutions import LaunchConfiguration from ros_gz_sim.actions import GzServer def generate_launch_description(): declare_world_sdf_file_cmd = DeclareLaunchArgument( - 'world_sdf_file', default_value=TextSubstitution(text=''), + 'world_sdf_file', default_value='', description='Path to the SDF world file') # Create the launch description and populate From a3c06d6db2579842ed3070b99699aca707388812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Ag=C3=BCero?= Date: Fri, 13 Sep 2024 22:04:46 +0200 Subject: [PATCH 4/4] Typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Carlos Agüero --- harmonic/ros2_integration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/harmonic/ros2_integration.md b/harmonic/ros2_integration.md index 7d9d1393a..ea5830785 100644 --- a/harmonic/ros2_integration.md +++ b/harmonic/ros2_integration.md @@ -67,7 +67,7 @@ The package `ros_gz_bridge` contains a launch file named `ros_gz_bridge.launch.py`. You can use it to start a ROS 2 and Gazebo bridge. Here's an example: -Note: If you run the bridge as a standalone node with composition enabled (default configutation), +Note: If you run the bridge as a standalone node with composition enabled (default configuration), you'll need to create a container first. ```bash ros2 run rclcpp_components component_container --ros-args -r __node:=ros_gz_container