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

How to get a command line value in the launch file

asked 2022-07-11 22:46:39 -0500

Barty gravatar image

I have a situation with several similar robots as well as the same robot with slightly different configurations. Right now, that means I have a bunch of almost identical launch files, and I'd like to reduce that for maintainability. The difficulty I'm having is figuring out how to get the info into my launch file. So far I've been able to group collections of nodes, but I'd like to be able to en/disable them from the command line. Here's what I'm talking about:

def generate_launch_description():
    node_list = []
    node_list += some_nodes()
    node_list += some_other_nodes()
    return launch.LaunchDescription(node_list)

What I'd like to do is get a command line option to enable or disable some other sets of things, so something like this:

def generate_launch_description():
    node_list = []
    node_list += some_nodes()
    node_list += some_other_nodes()
    if(foo):
        node_list += foo_nodes()
    if(bar):
        node_list += bar_nodes(bar)
    return launch.LaunchDescription(node_list)

How do I get foo and bar from the command line? So far LaunchConfigurations don't seem to be correct.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2022-07-12 04:20:11 -0500

Per Edwardsson gravatar image

Have a look at this launch file from the nav2 system. To get access to runtime arguments, you first provide a LaunchConfiguration (like for namespace, at line 34), and then DeclareLaunchArgument (like lines 46-49). At this point, if you launch this file, you can use the syntax ros2 launch nav2_bringup bringup_launch.py namespace:=mycustomnamespace to specify the input. I found it useful to read the design documentation to understand the system a little better. It can be a little verbose, but it makes sense when you squint your eyes a little. :)

edit flag offensive delete link more
-1

answered 2022-07-14 12:00:38 -0500

Maybe you can try using sys.argv() function in the launch file

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2022-07-11 22:46:39 -0500

Seen: 176 times

Last updated: Jul 14 '22