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

[ROS2] How to pass a launch argument into if

asked 2022-09-15 21:37:39 -0500

yyf202xz gravatar image

I made a launch file like this:

def generate_launch_description():
    set_flag = launch.substitutions.LaunchConfiguration('set', default='False')
    a = IncludeLaunchDescription(
        os.path.join( '')))
    b = IncludeLaunchDescription(
        os.path.join( '')))
    if set_flag == True:
        launch_ = launch.LaunchDescription([a,b])
        launch_ = launch.LaunchDescription([a])

return launch.LaunchDescription([
    launch.actions.DeclareLaunchArgument(name='set', default_value = set_flag,
                                        description='launch or not'),

The if section always lead it to else phase whatever I put in command line. Seems I passed argument in a wrong way. How to do it properly?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-09-16 09:12:27 -0500

LiquidTurtle1 gravatar image

See this answer:

Try using IfCondition instead.

from launch.conditions import IfCondition

condition=IfCondition(PythonExpression([LaunchConfiguration('set'), "' == 'false'"]

Further documentation:

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2022-09-15 21:37:39 -0500

Seen: 49 times

Last updated: Sep 16 '22