[ROS2 foxy] Python launch argument scope when nesting launch files
The tldr is can you scope launch arguments in the python launch system when using IncludeLaunchDescription
?
Assume we have a base python launch file (base_launch.py
, referred to as base) that includes another python launch file (ext_launch.py
, referred to as ext). The base has an argument arg1
that it may use and pass on to one or more included launch files. Ext also has an argument of the same name. I print the base argument, include ext which also print its argument, and then again print the argument in base. The output from this shows that changes to the arguments value in ext also changes the arguments value in base.
Is there any way to not overwrite arguments of the same name (i.e. assign arguments with scope)? Or is there a different design pattern that should be followed?
base_launch.py
#!/usr/bin/env python3
from launch import LaunchDescription
from launch.launch_description_sources import PythonLaunchDescriptionSource
from launch.actions import DeclareLaunchArgument, LogInfo, IncludeLaunchDescription
from launch.substitutions import LaunchConfiguration, ThisLaunchFileDir
def generate_launch_description():
arg1 = LaunchConfiguration('arg1')
return LaunchDescription([
DeclareLaunchArgument(
'arg1',
default_value='Internal_Arg',
description='Argument'
),
LogInfo(msg=['Internal Arg (before): ', arg1]),
IncludeLaunchDescription(
PythonLaunchDescriptionSource([ThisLaunchFileDir(),'/ext_launch.py']),
launch_arguments={
'arg1': 'External_Arg_Mod'
}.items()
),
LogInfo(msg=['Internal Arg (after): ', arg1]),
])
ext_launch.py
#!/usr/bin/env python3
from launch import LaunchDescription
from launch.actions import LogInfo, DeclareLaunchArgument
from launch.substitutions import LaunchConfiguration
def generate_launch_description():
arg1 = LaunchConfiguration('arg1')
return LaunchDescription([
DeclareLaunchArgument(
'arg1',
default_value='External_Arg',
description='Argument'
),
LogInfo(msg=['External Arg: ', arg1])
])
Output:
[INFO] [launch.user]: Internal Arg (before): Internal_Arg
[INFO] [launch.user]: External Arg: External_Arg_Mod
[INFO] [launch.user]: Internal Arg (after): External_Arg_Mod