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 userosrunto 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
Right-click on the selected package -> Add
launchfolderRight-click on the selected
launchfolder -> Add launch fileEdit 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.,screendirects output to the console).
Run the launch file:
roslaunch package_name launch_file_name.launchResult: Multiple nodes are started simultaneously.