This works but I don't see a way to get arguments in:
from ament_index_python.packages import get_package_share_directory
...
foo_dir = get_package_share_directory('foo')
included_launch = launch.actions.IncludeLaunchDescription(
launch.launch_description_sources.PythonLaunchDescriptionSource(
foo_dir + '/launch/my_launch.py'))
...
return launch.LaunchDescription([
included_launch,
regular_node,
])
Crystal updates
launch file arguments
I found an example in https://github.com/ros2/launch of including a launch file and passing in arguments https://github.com/ros2/launch/tree/m...
Here is getting a launch file argument from https://github.com/lucasw/ros2_cpp_py which is adapted from the launch
example:
print("{}".format(launch.substitutions.LaunchConfiguration('test')))
return LaunchDescription([
launch.actions.DeclareLaunchArgument(
'test',
default_value='default_value',
description='test'),
launch_ros.actions.Node(
package='ros2_cpp_py', node_executable='cpp_test', output='screen',
node_name=launch.substitutions.LaunchConfiguration('test'),
),
])
Then this results in a node named 'default_value':
ros2 launch ros2_cpp_py example.launch.py
And this names the node 'foo':
ros2 launch ros2_cpp_py example.launch.py test:=foo
What I need to be able to do is get the value of the argument during the execution of the launch file, but it comes out as:
print("{}".format(launch.substitutions.LaunchConfiguration('test')))
Results in:
<launch.substitutions.launch_configuration.LaunchConfiguration object at 0x7f0db4b44a58>
Maybe it has a method that returns the value- the perform() method wants a LaunchContext
but I'm not sure where to get it.
including another launch file
def generate_launch_description():
"""Launch the example.launch.py launch file."""
return LaunchDescription([
launch.actions.DeclareLaunchArgument(
'test',
default_value='different_default_value',
description='test arg that overlaps arg in included file',
),
LogInfo(msg=[
'Including launch file located at: ', ThisLaunchFileDir(), '/example.launch.py'
]),
IncludeLaunchDescription(
PythonLaunchDescriptionSource([ThisLaunchFileDir(), '/example.launch.py']),
launch_arguments={'node_name': 'bar'}.items(),
),
])
I've made a new launch argument with the same name as in the included launch file, it appears the top level one supersedes it. It is also possible to set an arg in an included launch file regardless of whether the top level launch exposes it or not. Large hierarchies of of includes have to be careful not to have same named but different meaning arguments, they'll get overwritten.
ros2 launch ros2_cpp_py includes_example.launch.py
Yes, that should work.