Ask Your Question
0

[ros2] Including a launch file in a launch file with parameter overrides

asked 2021-01-19 08:20:15 -0500

updated 2021-01-19 11:40:54 -0500

gvdhoorn gravatar image

I have two launch files A.launch.py and B.launch.py. The B launch file has a set of parameters with default values. I want to include the B launch file in A so that launching A also launches B.

So far this works fine and I have no problems.

However, now I want to specify some parameter values in A that override the default values specified in B. How do I do this? It was pretty straightforward to do this in ROS 1 with the XML syntax, but I can't find any straightforward way to do in ROS 2 with the python launch file syntax.

My question is basically this one, but for ROS 2: #q62949.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-01-19 12:41:18 -0500

I believe I've answered my own question. I got it to work by adding a launch_arguments argument to the IncludeLaunchDescription command:

Before:

ld = IncludeLaunchDescription(
    launch.launch_description_sources.PythonLaunchDescriptionSource(
        os.path.join(pkg_prefix, 'B.launch.py')))

After:

ld = IncludeLaunchDescription(
    launch.launch_description_sources.PythonLaunchDescriptionSource(
        os.path.join(pkg_prefix, 'B.launch.py')),
    launch_arguments={
        'parameter_name1': 'parameter_value1',
        'parameter_name2': 'parameter_value2'
    }.items()
)

Note that both parameter name and value are strings. The value can also be a launch.Substitution, but I don't know how those work. The string value works for my purposes.

edit flag offensive delete link more

Comments

how do you then parse the launch arguments in B.launch.py

morten gravatar image morten  ( 2021-09-29 07:09:25 -0500 )edit

Instead of calling them 'parameters', it would be better to call them launch file arguments. What I imagine the questioner is doing in B.launch.py is declaring some launch file arguments which are then being used to set parameters. So to answer your question @morten, you would just declare a launch file argument in B.launch.py.

swiz23 gravatar image swiz23  ( 2021-10-04 23:33:26 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2021-01-19 08:20:15 -0500

Seen: 292 times

Last updated: Jan 19 '21