Equivalents of "if" and "unless" ROS1 XML for ROS2 python launch files
Hi,
I migrate some packages to ROS2 (humble) and I don't find an equivalent of the if
and unless
arguments I had in ROS1 (noetic) XML launch files for python ROS2 launchers.
I know I could achieve that with XML in ROS2 too, but I was curious to make it in python since it seems to be a more "ROSish" way to do it, nowadays.
A very simple example ROS1 snippet XML
<launch>
<arg name="viz" default="false"/>
<node if="$(arg viz)" pkg="rviz" name="rviz" type="rviz"/>
</launch>
Now In ROS2, I have the following python file, but the rviz node run is not conditioned to the value of viz
anymore.
from launch import LaunchDescription
from launch.actions import DeclareLaunchArgument
from launch.substitutions import TextSubstitution
from launch_ros.actions import Node
def generate_launch_description():
launch_description = LaunchDescription()
viz_arg = DeclareLaunchArgument("viz", default_value=TextSubstitution(text="false"))
launch_description.add_action(viz_arg)
rviz_node = Node(
package='rviz2',
executable='rviz2',
name='rviz2',
)
# I'd like condition the following line with an if, I guess
launch_description.add_action(rviz_node)
return launch_description
Thanks for your help.