0
$\begingroup$

Rosanswers logo

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.


Originally posted by Jeffrey Kane Johnson on ROS Answers with karma: 452 on 2021-01-19

Post score: 0

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by Jeffrey Kane Johnson with karma: 452 on 2021-01-19

This answer was ACCEPTED on the original site

Post score: 0


Original comments

Comment by morten on 2021-09-29:
how do you then parse the launch arguments in B.launch.py

Comment by swiz23 on 2021-10-04:
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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.