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

Revision history [back]

This is answered is previous questions. See: https://answers.ros.org/question/382000/ros2-makes-launch-files-crazy-too-soon-to-be-migrating/?answer=382141#post-id-382141

In short, you should be able to do:

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',
    condition=IfCondition(LaunchConfiguration('viz')),
  )
  launch_description.add_action(rviz_node)

  return launch_description

This is answered is previous questions. See: For instance, see: https://answers.ros.org/question/382000/ros2-makes-launch-files-crazy-too-soon-to-be-migrating/?answer=382141#post-id-382141

In short, you should be able to do:

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',
    condition=IfCondition(LaunchConfiguration('viz')),
  )
  launch_description.add_action(rviz_node)

  return launch_description