Robotics StackExchange | Archived questions

Launching xml file from python launch file

I'm trying to launch an xml launch file from a python launch file, but it's getting stuck on the <launch> section of the xml.

Is there a different way of doing this?

Code:

def generate_launch_description():
    return LaunchDescription([ 
        IncludeLaunchDescription(PythonLaunchDescriptionSource(
        os.path.join(get_package_share_directory('rosbridge_server'),
         'launch/rosbridge_websocket_launch.xml')))

    ])

Error:

  File "/opt/ros/foxy/share/rosbridge_server/launch/rosbridge_websocket_launch.xml", line 1
    <launch>
    ^
SyntaxError: invalid syntax

Asked by SonicBoom on 2022-07-26 05:14:05 UTC

Comments

Answers

To include an XML file, you need to use FrontendLaunchDescriptionSource instead of PythonLaunchDescriptionSource, which can be imported with from launch.launch_description_sources import FrontendLaunchDescriptionSource.

So the correct code would be:

def generate_launch_description():
    return LaunchDescription([ 
        IncludeLaunchDescription(FrontendLaunchDescriptionSource(
        os.path.join(get_package_share_directory('rosbridge_server'),
         'launch/rosbridge_websocket_launch.xml')))
    ])

Asked by JeremieBourque on 2022-07-28 10:15:31 UTC

Comments