-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: David Dorf <[email protected]>
- Loading branch information
1 parent
e9f3504
commit ccfda52
Showing
1 changed file
with
25 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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/[email protected]',], | ||
remappings=[('/remapped_imu_topic'),], | ||
output='screen' | ||
), | ||
]) | ||
``` | ||
|
||
|