ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

Embedding a launch file with a parameter

asked 2013-05-16 23:34:48 -0600

markkre gravatar image

updated 2013-11-14 11:33:03 -0600

tfoote gravatar image

I have two ros launch files, A.launch and B.launch.

I want B.launch to be included in A.launch like that:


    <node name="rosbridge" pkg="rosbridge" type="" />
    <include file="$(find some_package_name)/launch/B.launch">

Works pretty nice. However, it becomes a problem, as soon as there is a parameter necessary in B.launch:


    <node name="$(arg START_NODE_NAME)" pkg="some_package_name" type="some_type">

I tried to use the following tag in A.launch:

    <node name="rosbridge" pkg="rosbridge" type="" />
    <include file="$(find some_package_name)/launch/B.launch">
            <arg name="START_NODE_NAME" value="goal_server" />-->

but that didn't work out either.

Is that scenario just not possible?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-05-17 01:19:19 -0600

dornhege gravatar image

You're on the right track. You only need to define the arg in B.launch, i.e. add

<arg name="START_NODE_NAME" />

to the top of B.launch.

edit flag offensive delete link more


works, thanks!

markkre gravatar image markkre  ( 2013-05-23 02:06:55 -0600 )edit

answered 2013-05-17 08:01:00 -0600

Thomas D gravatar image

The answer from @dornhege will work with no problems.

To go a bit further, I tend to treat launch files like a separate language, where each individual launch file is a function and the <arg> tags at the top of the launch file are the function parameters that have default values. To accomplish that I would put the following line just below the <launch> tag in both launch files:

<arg name="START_NODE_NAME" default="goal_server"/>

There are two benefits to this approach:

  1. In A.launch you can simply have the following line:

    <include file="$(find some_package_name)/launch/B.launch"/>

    and you will have B.launch use goal_server as the node name.

  2. You can remap arguments for your launch files when starting A.launch from the command line:

    roslaunch your_package A.launch START_NODE_NAME:=new_goal_server

    This is helpful when you want to try changing a few things without necessarily going into the actual files to modify values.

More tips can be found here for using roslaunch with large projects.

edit flag offensive delete link more


Unfortunately this won't work. You still have to give the arg in 1., when you include B.launch and basically say: <arg name="START_NODE_NAME" value="$(arg START_NODE_NAME)"/>. If you don't, the default will always be used, even if you start as in 2! Changing this behavior is a proposed feature.

dornhege gravatar image dornhege  ( 2013-05-17 08:07:21 -0600 )edit

Thanks @dornhege. I thought this works for me, but I'll double-check it now. Do you know of an issue or ticket link for this where the discussion can continue?

Thomas D gravatar image Thomas D  ( 2013-05-17 08:48:24 -0600 )edit

Proposed in as "bubbling args".

dornhege gravatar image dornhege  ( 2013-05-17 09:36:44 -0600 )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


Asked: 2013-05-16 23:34:48 -0600

Seen: 940 times

Last updated: May 17 '13