Open VRichardJP opened 1 year ago
I have found a variation of this problem: if the included launch file specifies a default for the argument, it gets overwritten even if the argument is not being explicitly passed along. Building on the above example, if we had:
<!-- parent.launch.xml -->
<launch>
<arg name="foo" default="there!"/>
<include file="child.launch.xml"/>
</launch>
<!-- child.launch.xml -->
<launch>
<arg name="foo" default="elsewhere!"/>
<executable cmd="echo Hello $(var foo)" output="screen" shell="true" />
</launch>
The output would still be [echo-1] Hello there!
, even though you'd expect it to be [echo-1] Hello elsewhere!
.
I believe this is a subtle side-effect of <include>
being not-scoped, that is, it's expected to work as if the contents of the included file were copy-pasted into the including file. Apparently the first <arg>
tag in the file takes precedence over any subsequent re-definitions of a given argument, instead of being overwritten by them.
However, even fixing this precedence order still wouldn't fix the implicit argument passing issue — without scoping, the argument that was undefined in the included file will be defined by the time it's reached during the processing of the including file.
The ROS2 launch XML format documentation (http://design.ros2.org/articles/roslaunch_xml.html) states that:
If I understand the documentation correctly, if a launch file includes another with the
<include>
tag, the<arg>
parameters are not passed to the other launch file implicitly.So for example, with these 2 files:
We get an error if we try to launch the
parent.launch.xml
, becausefoo
is not set for the included file:So far so good.
However, if we change the child launch file to:
Then, not only no error occurs, but the argument is passed to the child launch file:
Is it a bug? an undocumented feature?
Bug report
Required Info:
Steps to reproduce issue
Run
ros2 launch parent.launch.xml
with:Expected behavior
Error because
foo
is undefined?Actual behavior
The command outputs
[echo-1] Hello there!
, so not onlyfoo
is defined, but it is also passed implicitely from the parent file.Additional information