Skip to content

1.4.3 Launch File Demonstration

1. Requirement

A program may need to start multiple nodes. For example: in the built-in ROS turtle case, to control the turtle's movement, multiple windows need to be opened to start roscore, the turtle interface node, and the keyboard control node respectively. If we use rosrun to start them one by one each time, the efficiency is obviously low. How can we optimize this?

The optimization strategy provided by the official ROS is to use launch files, which can start multiple ROS nodes at once.

2. Implementation

  1. Right-click on the selected package -> Add launch folder

  2. Right-click on the selected launch folder -> Add launch file

  3. Edit the content of the launch file:

    xml
    <launch>
        <node pkg="helloworld" type="demo_hello" name="hello" output="screen" />
        <node pkg="turtlesim" type="turtlesim_node" name="t1"/>
        <node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
    </launch>
    • node -> Defines a node to be launched.
    • pkg -> The name of the package the node belongs to.
    • type -> The name of the executable node file.
    • name -> The name assigned to the node (can be used for remapping and other references).
    • output -> Sets the log output target (e.g., screen directs output to the console).
  4. Run the launch file:

    roslaunch package_name launch_file_name.launch

  5. Result: Multiple nodes are started simultaneously.