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

ros2 include a launch file from a launch file

asked 2018-10-28 08:21:27 -0500

lucasw gravatar image

updated 2018-10-28 08:53:12 -0500

I see

:class:launch.actions.IncludeLaunchDescription This action will include another launch description as if it had been copy-pasted to the location of the include action.

Can this be used within a something like this:

def generate_launch_description():
    included_launch = launch_ros.actions.IncludeLaunchDescription(package='foo', launch='', arguments=[...])  
    regular_node = launch_ros.actions.Node( package='bar', node_executable='my_node', output='screen')

    return launch.LaunchDescription([
edit retag flag offensive close merge delete


Yes, that should work.

William gravatar image William  ( 2019-01-17 19:39:21 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-10-28 08:41:48 -0500

lucasw gravatar image

updated 2023-04-07 01:58:03 -0500

130s gravatar image

UPDATE by @130s: 4+ years later, there's an official tutorial ( made that lays out what this answer is explaining.

This works but I don't see a way to get arguments in:

from ament_index_python.packages import get_package_share_directory
foo_dir = get_package_share_directory('foo')
included_launch = launch.actions.IncludeLaunchDescription(
                foo_dir + '/launch/'))
return launch.LaunchDescription([

Crystal updates

launch file arguments

I found an example in of including a launch file and passing in arguments

Here is getting a launch file argument from which is adapted from the launch example:


return LaunchDescription([
        package='ros2_cpp_py', node_executable='cpp_test', output='screen',

Then this results in a node named 'default_value':

ros2 launch ros2_cpp_py

And this names the node 'foo':

ros2 launch ros2_cpp_py test:=foo

What I need to be able to do is get the value of the argument during the execution of the launch file, but it comes out as:


Results in:

<launch.substitutions.launch_configuration.LaunchConfiguration object at 0x7f0db4b44a58>

Maybe it has a method that returns the value- the perform() method wants a LaunchContext but I'm not sure where to get it.

including another launch file

def generate_launch_description():
    """Launch the launch file."""
    return LaunchDescription([
            description='test arg that overlaps arg in included file',
            'Including launch file located at: ', ThisLaunchFileDir(), '/'
            PythonLaunchDescriptionSource([ThisLaunchFileDir(), '/']),
            launch_arguments={'node_name': 'bar'}.items(),

I've made a new launch argument with the same name as in the included launch file, it appears the top level one supersedes it. It is also possible to set an arg in an included launch file regardless of whether the top level launch exposes it or not. Large hierarchies of of includes have to be careful not to have same named but different meaning arguments, they'll get overwritten.

ros2 launch ros2_cpp_py
edit flag offensive delete link more


@lucasw - did you get arguments to work? I can't seem to get them passed through to an included launch file either

mkhansen gravatar image mkhansen  ( 2018-11-27 08:22:22 -0500 )edit

I haven't tried it but sys.argv should still be valid in the included file, so argparse would work- so independent arguments could be passed in as long as the two launch files don't have same named args that need different values.

lucasw gravatar image lucasw  ( 2018-11-27 08:50:14 -0500 )edit

That method wouldn't allow the first launch script setting the args for the included files (except by modifying sys.argv, which is starting to get really hacky), which is something I did very frequently in ros1 launch files.

lucasw gravatar image lucasw  ( 2018-11-27 08:53:52 -0500 )edit

Updated answer with crystal specific launch file including and argument setting.

lucasw gravatar image lucasw  ( 2019-01-17 15:45:29 -0500 )edit

Let me see if I can put together a simple example. It's possible there's a feature missing somewhere that prevent this, though my recollection is that it should be possible.

William gravatar image William  ( 2019-01-17 19:42:18 -0500 )edit

I don't quite understand this example. What is ThisLaunchFileDir()?

M@t gravatar image M@t  ( 2021-04-28 16:45:04 -0500 )edit

Were you ever able to get the value of the argument during the execution of the launch file?

morten gravatar image morten  ( 2021-09-30 05:06:42 -0500 )edit

Marked as answer. Years later I found a tutorial that essentially explains the same as this answer. To honor the answer I added a link to the body of the answer instead of adding a new answer.

130s gravatar image 130s  ( 2023-04-07 01:59:48 -0500 )edit

Question Tools



Asked: 2018-10-28 08:21:27 -0500

Seen: 8,952 times

Last updated: Apr 07