From ament_index_python.packages, instead of using get_package_share_directory, we use get_package_share_path which returns a pathlib.Path object, allowing more succinct path joins.
IncludeLaunchDescription now wraps input paths with AnyLaunchDescriptionSource (or did it always do so and I only thought I tried?), however it still needs to be cast to str unless this is solved: https://github.com/ros2/launch/issues/805
Also lets to try to standardize some other things optionally:
# Any hardcoded values up here, in caps, C++ define style.
WORLD_SDF = "pool_world.sdf"
# Any externally available arguments.
def declare_launch_arguments():
"""Documentation of available arguments go here."""
world_sdf = DeclareLaunchArgument("world_sdf", default_value=WORLD_SDF)
return [world_sdf]
def generate_launch_description():
# Prefix with pkg_ for package path.
pkg_ros_gz_sim = get_package_share_path("ros_gz_sim")
# Prefix with arg_ for launch argument substitution.
arg_world_sdf = LaunchConfiguration("world_sdf")
# Optionally can do launch_gazebo if want to indication its an action
# to launch another launch file.
gazebo = IncludeLaunchDescription(
str(pkg_ros_gz_sim / "launch" / "gz_sim.launch.py"),
launch_arguments={"gz_args": [arg_world_sdf, " -v 0"]}.items(),
)
# Likewise for nodes, node_smth is optional, but in both cases, the name
# itself should make it clear what launch action it is and what it does.
# Write as multiline list to make it easy to comment out specific actions.
return LaunchDescription([
*declare_launch_arguments(),
gazebo,
])
Due to an update in ros2launch, its now possible to write
IncludeLaunchDescription
in a more succinct manner:Note in the above:
ament_index_python.packages
, instead of usingget_package_share_directory
, we useget_package_share_path
which returns apathlib.Path
object, allowing more succinct path joins.IncludeLaunchDescription
now wraps input paths withAnyLaunchDescriptionSource
(or did it always do so and I only thought I tried?), however it still needs to be cast tostr
unless this is solved: https://github.com/ros2/launch/issues/805Also lets to try to standardize some other things optionally: