0
$\begingroup$

I have this seemingly simple launch file:

<launch>

  <arg name="launch_nav" default="false" />

  <include
      file="$(find-pkg-share turtlebot3_gazebo)/launch/turtlebot3_world.launch.py"
      unless="$(var launch_nav)"
      />

  <include
      file="$(find-pkg-share rtabmap_demos)/launch/turtlebot3_scan.launch.py"
      unless="$(var launch_nav)"
      />

  <include
      file="$(find-pkg-share nav2_bringup)/launch/navigation_launch.py"
      if="$(var launch_nav)"
      >
    <arg name="use_sim_time" value="true" />
  </include>

</launch>

For some reason I can't launch all of these at the same time. If I don't use the conditionals, the launch file will crash with an error (some windows will still open though, e.g., gzclient and rtabmap_viz):

[ERROR] [launch]: Caught exception in launch (see debug for traceback): [Errno 2] No such file or directory: ''

If I include the conditionals and run them in separate shells, like this, it works as expected:

$ ros2 launch test.launch.xml launch_nav:=false

and

$ ros2 launch test.launch.xml launch_nav:=true

What is going on? Can anyone reproduce this? Am I doing something wrong?

On another computer with Ubuntu 20.04 running foxy, this doesn't happen and it launches as expected.

$\endgroup$
2

1 Answer 1

0
$\begingroup$

Apparantly this has to do with ROS 2 launch arguments leaking into other included launch configurations. In contrast to ROS 1, here included launch files will not have their own scope by default. You have to wrap included launch files in a GroupAction / <group> to isolate them properly.

Related issue: https://github.com/ros2/launch/issues/620

For this specific case it seems both the gzserver.launch.py and the navigation_launch.py declare the launch argument params_file, which leads to the unexpected result. It worked with foxy, because there gazebo wasn't also setting this launch argument.

Something like this should also work:

<launch>

  <group>
    <include file="$(find-pkg-share turtlebot3_gazebo)/launch/turtlebot3_world.launch.py" />
  </group>

  <group>
    <include file="$(find-pkg-share rtabmap_demos)/launch/turtlebot3_scan.launch.py" />
  </group>

  <group>
    <include file="$(find-pkg-share nav2_bringup)/launch/navigation_launch.py">
      <arg name="use_sim_time" value="true" />
    </include>
  </group>

</launch>
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.