From 47c9731caa83f911d44e9df6e1f4dc0d59f295ca Mon Sep 17 00:00:00 2001 From: "David V. Lu" Date: Wed, 23 Aug 2023 11:17:35 -0400 Subject: [PATCH] Use PathJoinSubstitution --- README.md | 5 +++-- launch/description.launch.py | 8 +++----- launch/display.launch.py | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7cfcf34..80845c7 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ The result is that you can perform the above actions with just 5 lines (not incl ```python from launch import LaunchDescription from launch.actions import IncludeLaunchDescription +from launch.substitutions import PathJoinSubstitution from launch_ros.substitutions import FindPackageShare @@ -21,10 +22,10 @@ def generate_launch_description(): ld = LaunchDescription() ld.add_action(IncludeLaunchDescription( - [FindPackageShare('urdf_launch'), '/launch/description.launch.py'], + PathJoinSubstitution([FindPackageShare('urdf_launch'), 'launch', 'display.launch.py']), launch_arguments={ 'urdf_package': 'turtlebot3_description', - 'urdf_package_path': 'urdf/turtlebot3_burger.urdf'}.items() + 'urdf_package_path': PathJoinSubstitution(['urdf', 'turtlebot3_burger.urdf'])}.items() )) return ld diff --git a/launch/description.launch.py b/launch/description.launch.py index da2242a..2604360 100644 --- a/launch/description.launch.py +++ b/launch/description.launch.py @@ -1,7 +1,7 @@ from launch import LaunchDescription from launch.actions import DeclareLaunchArgument from launch.substitutions import Command -from launch.substitutions import LaunchConfiguration +from launch.substitutions import LaunchConfiguration, PathJoinSubstitution from launch_ros.actions import Node @@ -17,11 +17,9 @@ def generate_launch_description(): description='The path to the robot description relative to the package root')) package_dir = FindPackageShare(LaunchConfiguration('urdf_package')) + urdf_path = PathJoinSubstitution([package_dir, LaunchConfiguration('urdf_package_path')]) - robot_description_content = ParameterValue( - Command(['xacro ', package_dir, '/', LaunchConfiguration('urdf_package_path')]), - value_type=str, - ) + robot_description_content = ParameterValue(Command(['xacro ', urdf_path]), value_type=str) robot_state_publisher_node = Node(package='robot_state_publisher', executable='robot_state_publisher', diff --git a/launch/display.launch.py b/launch/display.launch.py index b8187cc..5046064 100644 --- a/launch/display.launch.py +++ b/launch/display.launch.py @@ -2,7 +2,7 @@ from launch.actions import DeclareLaunchArgument from launch.actions import IncludeLaunchDescription from launch.conditions import IfCondition, UnlessCondition -from launch.substitutions import LaunchConfiguration +from launch.substitutions import LaunchConfiguration, PathJoinSubstitution from launch_ros.actions import Node from launch_ros.substitutions import FindPackageShare @@ -16,13 +16,13 @@ def generate_launch_description(): ld.add_action(DeclareLaunchArgument(name='jsp_gui', default_value='true', choices=['true', 'false'], description='Flag to enable joint_state_publisher_gui')) - default_rviz_config_path = [urdf_launch_package, '/config/urdf.rviz'] + default_rviz_config_path = PathJoinSubstitution([urdf_launch_package, 'config', 'urdf.rviz']) ld.add_action(DeclareLaunchArgument(name='rviz_config', default_value=default_rviz_config_path, description='Absolute path to rviz config file')) # need to manually pass configuration in because of https://github.com/ros2/launch/issues/313 ld.add_action(IncludeLaunchDescription( - [urdf_launch_package, '/launch/description.launch.py'], + PathJoinSubstitution([urdf_launch_package, 'launch', 'description.launch.py']), launch_arguments={ 'urdf_package': LaunchConfiguration('urdf_package'), 'urdf_package_path': LaunchConfiguration('urdf_package_path')}.items()