ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To mimic a if and unless present into an <include> tag, you should use conditions such as pointed by Christophe in another answer.

Note that several types of conditions exists, such as IfCondition, UnlessCondition, LaunchConfigurationEquals and LaunchConfigurationNotEquals

For example, to migrate the following ROS1 XML code

<include file="$(find pkg_1)/launch/my_file.launch" if="$(eval points != '/points')">

In python ROS2

from ament_index_python import get_package_share_directory
from launch import LaunchDescription
from launch.actions.include_launch_description import IncludeLaunchDescription
from launch.conditions import LaunchConfigurationNotEquals
from launch.launch_description_sources
import PythonLaunchDescriptionSource
import os

launch_description = LaunchDescription() 

pkg_1_include = IncludeLaunchDescription(
  PythonLaunchDescriptionSource(
    os.path.join(get_package_share_directory('pkg_1'), 'launch/my_file.launch')),
  condition=LaunchConfigurationNotEquals('points', "/points"),
)
launch_description.add_action(pkg_1_include)