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

ROS2: Including xml launch files in a python launch file

asked 2022-09-03 14:19:18 -0500

adityakamath gravatar image

Is there a way in ROS2 to launch an xml launch file from a python launch file?

I am currently making a python launch file for my application, which needs me to run rosbridge_server, which provides a .xml launch file. I would like to launch rosbridge_server from within the python launch file.

I couldn't find any relevant documentation regarding this.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-09-03 23:19:22 -0500

ravijoshi gravatar image

In order to include a python launch file, you need to use the following import statement:

from launch.launch_description_sources import PythonLaunchDescriptionSource

Similarly, in order to include an XML launch file, you should import the following statement:

from launch_xml.launch_description_sources import XMLLaunchDescriptionSource

Please see a working example below:

$ cat 
"""Invoke XML launch file from Python Launch file."""

import os

from ament_index_python import get_package_share_directory

from launch import LaunchDescription
from launch.actions import IncludeLaunchDescription
from launch_xml.launch_description_sources import XMLLaunchDescriptionSource

def generate_launch_description():
    # include xml launch file
    launch_include = IncludeLaunchDescription(

    return LaunchDescription([launch_include])

You can launch it simply by the following command:

$ ros2 launch demo_nodes_cpp 
[INFO] [launch]: All log files can be found below /home/ravi/.ros/log/2022-09-04-13-11-49-021399-dell-21519
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [talker-1]: process started with pid [21521]
[INFO] [listener-2]: process started with pid [21523]
[talker-1] [INFO] [1662264710.244856916] [talker]: Publishing: 'Hello World: 1'
[listener-2] [INFO] [1662264710.245174169] [listener]: I heard: [Hello World: 1]
[talker-1] [INFO] [1662264711.244494212] [talker]: Publishing: 'Hello World: 2'
[listener-2] [INFO] [1662264711.245017003] [listener]: I heard: [Hello World: 2]
^C[WARNING] [launch]: user interrupted with ctrl-c (SIGINT)
[listener-2] [INFO] [1662264711.556384949] [rclcpp]: signal_handler(signal_value=2)
[talker-1] [INFO] [1662264711.556404309] [rclcpp]: signal_handler(signal_value=2)
[INFO] [listener-2]: process has finished cleanly [pid 21523]
[INFO] [talker-1]: process has finished cleanly [pid 21521]

The package demo_nodes_cpp is available on GitHub.

edit flag offensive delete link more


Thanks for this detailed response! This certainly solved the issue for me. I had already re-written one of my XML launch files in python, and I was afraid I would have to do the same with the others..

adityakamath gravatar image adityakamath  ( 2022-09-04 03:10:40 -0500 )edit

It says no module named launch_xml for me. Where do I find this module? I'm using ROS Dashing

isel gravatar image isel  ( 2023-04-04 03:29:10 -0500 )edit

Question Tools

1 follower


Asked: 2022-09-03 14:19:18 -0500

Seen: 1,252 times

Last updated: Sep 03 '22