Skip to content

Commit ccfda52

Browse files
authored
Update ros2_launch_gazebo.md (#559)
Signed-off-by: David Dorf <[email protected]>
1 parent e9f3504 commit ccfda52

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

harmonic/ros2_launch_gazebo.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -54,45 +54,48 @@ an option but not strictly necessary as you could decide to hardcode some of the
5454
values or not even use all the parameters.
5555

5656
### Python
57-
Python launch files provide more low-level customization and logic compared to XML launch files.
58-
In the following example, the user can specify a world argument to launch an environment for
59-
the Moon, Mars, or Enceladus. It additionally sets the resource path environment variable and
60-
sets up empty arrays for topics to be bridged and remapped from Gazebo to ROS 2:
57+
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.
58+
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.
59+
6160
```python
62-
from ament_index_python.packages import get_package_share_directory
6361
from launch import LaunchDescription
64-
from launch.actions import (DeclareLaunchArgument, SetEnvironmentVariable,
65-
IncludeLaunchDescription, SetLaunchConfiguration)
66-
from launch.substitutions import PathJoinSubstitution, LaunchConfiguration, TextSubstitution
6762
from launch_ros.actions import Node
63+
from launch.actions import SetEnvironmentVariable, IncludeLaunchDescription
6864
from launch.launch_description_sources import PythonLaunchDescriptionSource
65+
from launch.substitutions import PathJoinSubstitution
66+
from launch_ros.substitutions import FindPackageShare
6967

7068

7169
def generate_launch_description():
72-
pkg_ros_gz_sim = get_package_share_directory('ros_gz_sim')
73-
pkg_spaceros_gz_sim = get_package_share_directory('spaceros_gz_sim')
70+
ros_gz_sim_pkg_path = get_package_share_directory('ros_gz_sim')
71+
example_pkg_path = FindPackageShare('example_package') # Replace with your own package name
7472
gz_launch_path = PathJoinSubstitution([pkg_ros_gz_sim, 'launch', 'gz_sim.launch.py'])
75-
gz_model_path = PathJoinSubstitution([pkg_spaceros_gz_sim, 'models'])
7673

7774
return LaunchDescription([
78-
DeclareLaunchArgument(
79-
'world',
80-
default_value='moon',
81-
choices=['moon', 'mars', 'enceladus'],
82-
description='World to load into Gazebo'
75+
SetEnvironmentVariable(
76+
'GZ_SIM_RESOURCE_PATH',
77+
PathJoinSubstitution([example_pkg_path, 'models'])
78+
),
79+
SetEnvironmentVariable(
80+
'GZ_SIM_PLUGIN_PATH',
81+
PathJoinSubstitution([example_pkg_path, 'plugins'])
8382
),
84-
SetLaunchConfiguration(name='world_file',
85-
value=[LaunchConfiguration('world'),
86-
TextSubstitution(text='.sdf')]),
87-
SetEnvironmentVariable('GZ_SIM_RESOURCE_PATH', gz_model_path),
8883
IncludeLaunchDescription(
8984
PythonLaunchDescriptionSource(gz_launch_path),
9085
launch_arguments={
91-
'gz_args': [PathJoinSubstitution([pkg_spaceros_gz_sim, 'worlds',
92-
LaunchConfiguration('world_file')])],
86+
'gz_args': [PathJoinSubstitution([example_pkg_path, 'worlds/example_world.sdf'])], # Replace with your own world file
9387
'on_exit_shutdown': 'True'
9488
}.items(),
9589
),
90+
91+
# Bridging and remapping Gazebo topics to ROS 2 (replace with your own topics)
92+
Node(
93+
package='ros_gz_bridge',
94+
executable='parameter_bridge',
95+
arguments=['/example_imu_topic@sensor_msgs/msg/[email protected]',],
96+
remappings=[('/remapped_imu_topic'),],
97+
output='screen'
98+
),
9699
])
97100
```
98101

0 commit comments

Comments
 (0)