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

ROS2 launch nodes by python script

asked 2020-11-18 05:39:41 -0500

rostyv gravatar image

Hi everybody. I've a question: is there a way to launch nodes without using the "ros2 launch package_name launch_file" command? In particular, I'd like to launch a node directly from another node script written in Python. For example by using LaunchDescription structure with the informations related to the node I want to launch. So is there a python function in ROS2 libraries for accomplishing this? Thank you

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2022-05-18 13:38:15 -0500

m2-farzan gravatar image

This can be accomplished using the LaunchService class.

Basic example:

from launch import LaunchService

from my_launch_file import generate_launch_description

launch_service = LaunchService()

In this case, generate_launch_description() comes from a typical ros2 launch file. For example:

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
    rviz_node = Node(
    return LaunchDescription([
edit flag offensive delete link more


I think the method is blocking. Is there a way to launch the file and continue the script ?

Sam_Prt gravatar image Sam_Prt  ( 2022-06-30 07:43:22 -0500 )edit


buckley.toby gravatar image buckley.toby  ( 2023-05-09 12:02:39 -0500 )edit

Question Tools

1 follower


Asked: 2020-11-18 05:39:41 -0500

Seen: 815 times

Last updated: May 18 '22