ROS1 Launch File
ROS launch is a very useful command as it is capable to:
- run multiple nodes at the same time.
- set parameters.
- perform rosparam commands.
- set execution options.
ROS launch file (.launch) is an XML file which looks like below. As it is an XML, indentation matters.
An example launch file that sets a parameter:
1 2 3 |
<launch> <param name="parameter_name" value="10"> </launch> |
In a launch file with parameters and nodes, parameters are loaded (sent to the parameter server) before any node is run.
An example launch file that sets a parameter by using arg:
1 2 3 4 |
<launch> <arg name="variable" default="10"/> <param name="parameter_name" value="$(arg variable)"/> </launch> |
An example launch file that loads the parameters in a yaml file:
1 2 3 |
<launch> <rosparam command="load" file="$(find package_name)/config/name.yaml"/> </launch> |
An example launch file that run multiple nodes:
1 2 3 4 |
<launch> <node pkg="package_name" type="node_name" name="custom_node_name" output="screen"/> <node pkg="package_name" type="node_name.py" name="custom_node_name" output="screen"/> </launch> |
The argument “type” denotes the NODE_NAME, whereas the argument “name” denotes a custom name for the node (usually set as the same to the NODE_NAME, although it can be different). Notice that nodes are run at the same time, not based on the order they are written in the launch file.
Launch file that run nodes with the same names but within multiple namespace groups:
1 2 3 4 5 6 7 8 9 10 |
<launch> <group ns="ns1"> <node pkg="package_name" type="publisher" name="publisher"/> <node pkg="package_name" type="subscriber.py" name="subscriber"/> </group> <group ns="ns2"> <node pkg="package_name" type="publisher" name="publisher"/> <node pkg="package_name" type="subscriber.py" name="subscriber"/> </group> </launch> |
The official documentation of roslaunch can be found here: http://wiki.ros.org/roslaunch/XML
Some tips to write roslaunch for large projects can be found here: http://wiki.ros.org/roslaunch/Tutorials/Roslaunch%20tips%20for%20larger%20projects
Running a launch file
A launch is run by using the following CLI command:
1 |
roslaunch [PACKAGE_NAME] LAUNCH_FILE_NAME.launch |
To display all the outputs of the running nodes in the terminal, add –screen argument in the roslaunch command:
1 |
roslaunch [PACKAGE_NAME] LAUNCH_FILE_NAME.launch --screen |
The “roscore” command is not needed to be given before running “roslaunch”, because running “roslaunch” will automatically starts the ROS Master.