From ccfda52b5427da1a08e037d7dc6248124b471c06 Mon Sep 17 00:00:00 2001 From: David Dorf <113081373+david-dorf@users.noreply.github.com> Date: Wed, 8 Jan 2025 15:10:00 -0500 Subject: [PATCH] Update ros2_launch_gazebo.md (#559) Signed-off-by: David Dorf <113081373+david-dorf@users.noreply.github.com> --- harmonic/ros2_launch_gazebo.md | 47 ++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/harmonic/ros2_launch_gazebo.md b/harmonic/ros2_launch_gazebo.md index 30d265323..7ad5fc97a 100644 --- a/harmonic/ros2_launch_gazebo.md +++ b/harmonic/ros2_launch_gazebo.md @@ -54,45 +54,48 @@ an option but not strictly necessary as you could decide to hardcode some of the values or not even use all the parameters. ### Python -Python launch files provide more low-level customization and logic compared to XML launch files. -In the following example, the user can specify a world argument to launch an environment for -the Moon, Mars, or Enceladus. It additionally sets the resource path environment variable and -sets up empty arrays for topics to be bridged and remapped from Gazebo to ROS 2: +Python launch files provide more low-level customization and logic compared to XML launch files. For example, you can set environment variables and include Python specific functions and logic. +In the following example, the user can replace the example package, world, and bridged topic with their own. This is intended as a scaffolding more than something that can be run on its own. + ```python -from ament_index_python.packages import get_package_share_directory from launch import LaunchDescription -from launch.actions import (DeclareLaunchArgument, SetEnvironmentVariable, - IncludeLaunchDescription, SetLaunchConfiguration) -from launch.substitutions import PathJoinSubstitution, LaunchConfiguration, TextSubstitution from launch_ros.actions import Node +from launch.actions import SetEnvironmentVariable, IncludeLaunchDescription from launch.launch_description_sources import PythonLaunchDescriptionSource +from launch.substitutions import PathJoinSubstitution +from launch_ros.substitutions import FindPackageShare def generate_launch_description(): - pkg_ros_gz_sim = get_package_share_directory('ros_gz_sim') - pkg_spaceros_gz_sim = get_package_share_directory('spaceros_gz_sim') + ros_gz_sim_pkg_path = get_package_share_directory('ros_gz_sim') + example_pkg_path = FindPackageShare('example_package') # Replace with your own package name gz_launch_path = PathJoinSubstitution([pkg_ros_gz_sim, 'launch', 'gz_sim.launch.py']) - gz_model_path = PathJoinSubstitution([pkg_spaceros_gz_sim, 'models']) return LaunchDescription([ - DeclareLaunchArgument( - 'world', - default_value='moon', - choices=['moon', 'mars', 'enceladus'], - description='World to load into Gazebo' + SetEnvironmentVariable( + 'GZ_SIM_RESOURCE_PATH', + PathJoinSubstitution([example_pkg_path, 'models']) + ), + SetEnvironmentVariable( + 'GZ_SIM_PLUGIN_PATH', + PathJoinSubstitution([example_pkg_path, 'plugins']) ), - SetLaunchConfiguration(name='world_file', - value=[LaunchConfiguration('world'), - TextSubstitution(text='.sdf')]), - SetEnvironmentVariable('GZ_SIM_RESOURCE_PATH', gz_model_path), IncludeLaunchDescription( PythonLaunchDescriptionSource(gz_launch_path), launch_arguments={ - 'gz_args': [PathJoinSubstitution([pkg_spaceros_gz_sim, 'worlds', - LaunchConfiguration('world_file')])], + 'gz_args': [PathJoinSubstitution([example_pkg_path, 'worlds/example_world.sdf'])], # Replace with your own world file 'on_exit_shutdown': 'True' }.items(), ), + + # Bridging and remapping Gazebo topics to ROS 2 (replace with your own topics) + Node( + package='ros_gz_bridge', + executable='parameter_bridge', + arguments=['/example_imu_topic@sensor_msgs/msg/Imu@gz.msgs.IMU',], + remappings=[('/remapped_imu_topic'),], + output='screen' + ), ]) ```