First time here? Check out the FAQ!


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

[ROS2] How to pass a launch argument into if

asked Sep 16 '22

yyf202xz gravatar image

I made a launch file like this:

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

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

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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered Sep 16 '22

LiquidTurtle1 gravatar image

See this answer: https://answers.ros.org/question/3941...

Try using IfCondition instead.

from launch.conditions import IfCondition

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

Further documentation: https://docs.ros.org/en/foxy/Tutorial... https://github.com/ros2/launch/blob/f...

Preview: (hide)

Question Tools

1 follower

Stats

Asked: Sep 16 '22

Seen: 149 times

Last updated: Sep 16 '22