Launch Files¶
In this exercise, we will explore starting groups of nodes at once with launch files.
Motivation¶
The ROS architecture encourages engineers to use ‘’nodes’’ as a fundamental unit of organization in their systems, and applications can quickly grow to require many nodes to operate. Opening a new terminal and running each node individually quickly becomes unfeasible. It’d be nice to have a tool to bring up groups of nodes at once. ROS ‘’launch’’ files are one such tool. It even handles bringing roscore
up and down for you.
Reference Example¶
Scan-N-Plan Application: Problem Statement¶
In this exercise, you will:
- Create a new package,
myworkcell_support
. - Create a directory in this package called
launch
. - Create a file inside this directory called
workcell.launch
that:- Launches
fake_ar_publisher
- Launches
vision_node
- Launches
You may also choose to launch myworkcell_core
node with the others or keep it separate. We often configure systems with two main launch files. In this example, fake_ar_publisher
and vision_node
are “environment nodes”, while myworkcell_node
is an “application” node.
- “Environment” Launch File - driver/planning nodes, config data, etc.
- “Application” Launch File - executes a sequence of actions for a particular application.
Scan-N-Plan Application: Guidance¶
In your workspace, create the new package
myworkcell_support
with a dependency onmyworkcell_core
. Rebuild and source the workspace so that ROS can find the new package:cd ~/catkin_ws/src catkin create pkg myworkcell_support --catkin-deps myworkcell_core catkin build source ~/catkin_ws/devel/setup.bash
Create a directory for launch files (inside the new
myworkcell_support
package):roscd myworkcell_support mkdir launch
Create a new file,
workcell.launch
(inside thelaunch
directory) with the following XML skeleton:<launch> </launch>
Insert lines to bring up the nodes outlined in the problem statement. See the reference documentation for more information:
<node name="fake_ar_publisher" pkg="fake_ar_publisher" type="fake_ar_publisher_node" /> <node name="vision_node" pkg="myworkcell_core" type="vision_node" />
- Remember: All launch-file content must be between the
<launch> ... </launch>
tag pair.
- Remember: All launch-file content must be between the
Test the launch file:
roslaunch myworkcell_support workcell.launch
Note: roscore and both nodes were automatically started. Press Ctrl+C to close all nodes started by the launch file. If no nodes are left running, roscore is also stopped.
Notice that none of the usual messages were printed to the console window. Launch files will suppress console output below the ERROR severity level by default. To restore normal text output, add the
output="screen"
attribute to each of the nodes in your launch files:<node name="fake_ar_publisher" pkg="fake_ar_publisher" type="fake_ar_publisher_node" output="screen"/> <node name="vision_node" pkg="myworkcell_core" type="vision_node" output="screen" />