Launch File
1 Using launch files
2 Creating launch Files
3 Starting nodes in namespace
4 Remapping names
5 Other launch elements
1 Using launch files
Launch files are provided by Ros and can run multiple nodes files at the same time. Launch files are written in a special XML format and are widely used in ROS packages.
1.1 Running Launch files
$ roslaunch package_name Launch_file_name
Eg:roslaunch Turtlesim Example.launch
(1) Tip1:rosrun can run only one nodes, Roslaunch may run multiple nodes at the same time.
Tip2:launch files may not be included in the package. At this point, you simply point to the absolute path of the launch file to run.
$ roslaunch Completely_path
eg:$ Roslaunch ~/opt/ros/indigo/share/turtlesim/launch/example.launch
TIP3: For ease of execution, each node is best to be independent of each other.
(2) detailed display (Request verbosity)
$ roslaunch-v package_name Launch_file_name
(3) End launch file
CTRL + C
2 Creating launch Files
(1) Launch files are generally launch suffix as file names, placed under the Package launch folder. The simplest launch file can contain only a few nodes.
(2) The launch file is an XML file, and each XML file must have a root element. The root element of the launch file is defined by a pair of launch tags.
<launch>
...
</launch>
The other elements in the launch file must be between this pair of tags.
(3) The core of the launch file is a series of node elements, with each node element starting a node. The Node element looks as follows:
<node
Pkg= "Package_name" type= "Executable_name" name= "Node_name"
/>
TIP1: The final "/" is essential.
TIP2: can also be written <node pkg= "..." type= "..." name= "..." ></node>
You must use this form if you have other tags in the node.
(4) A node element contains three required attributes: pkg, type, name.
The pkg and type attribute indicates which node in which the Ros should run, note that the type here is the name of the executable file, and name is optionally given, overwriting the node name specified in the original file ros::init.
(5) using anonymous (anonymous name)
Name= "$ (anon base_name)"
(6) Node log files (log file)
One of the differences between running Roslaunch and running a single node with Rosrun is that by default, the standard output of the nodes that Roslaunch runs is redirected to log file and not displayed in the console.
The location and name of the log file are as follows:
~/.ros/log/run_id/node_name-number-stdout.log
Where run_id is a special identifier that was generated after master started, number is an integer representing the nodes quantity. For example, Turtlesim-1-stdout.log; Teleop_key-3-stdout.log.
(7) Output to console
output= "screen" with the output property, which displays only one node.
If all nodes output is displayed, use the--screen command line.
$ roslaunch--screen package_name launch_file_name
If the running file does not display the desired output, you can see if the node attribute set has output= "screen".
(8) Requirements for Rebirth (Request respawning)
When all nodes are turned on, Roslaunch monitors each node to record those nodes that are still active. For each node, when it terminates, we can ask Roslaunch to restart the node by using the Respawn property.
Respawn= "true"
(10) Required nodes
The Required property, contrary to respawn, cannot be used with the same node at the same time.
Required= "true"
When a required node terminates, all other nodes will terminate and exit. Such commands are sometimes useful. For example, when a very important node fails, the entire session is discarded, and the nodes with the Respawn attribute will stop.
(11) Running each nodes in a separate window
We run Rosrun Node_name in our respective termin, but when we run roslaunch, all the nodes share the same terminal, which is inconvenient for those who need to enter from the console nodes. You can use the Launch-prefix property.
launch-prefix= "Command-prefix"
eg:launch-prefix= "Xterm-e"
Equivalent to xterm-e rosrun Turtlesim Turtle_teleop_key
The Xterm command indicates that a new terminal-e parameter tells Xterm to execute the remaining command line.
Of course, the Launch-prefix attribute is not limited to xterm. It can be used for debugging (through GDB or valgrind), or for reducing the execution order of processes (through Nice).
3 executing nodes in namespace
A common method for setting default namespace for node-a process called "pushing down into a namespace"-is used to launch a file and specify the NS attribute in its node element.
Ns= "Namespace"
The node names in the launch file is relative names. In the same launch file, the same node names is allowed to appear in different namespace. Roslaunch requires node names to be base names--does not specify any namespaces relative names, and if node name is global name appears in the node element, an error is given.
4 remapping names (remapping names)
In addition to parsing relative names and private Names,ros, remapping is also supported to modify the name that nodes is currently using.
Remapping is equivalent to changing names, and each remapping needs to provide a original name and a new name. Each node uses its original name, and the ROS client library replaces it with remapping name.
Create remapping name two methods:
1. For a single node, remapping on the command line (Remap object can be node,topic, etc.).
Original-name:=new-name
Eg: $ rosrun turtlesim turtlesim_node Turtle1/pose:=tim
2. Remap names in launch file, using remap element
<remap from= "Original_name" to "new_name" >
If remap appears at the beginning of the launch file as a child element of the launch file, the remapping will be used for all subsequent nodes. If remap is a child element of a node, it is used only for that node.
Eg:<node pkg= "Turtlesim" type= "Turtlesim_node" name= "Turtle1" >
<remap from = "Turtle1/pose" to "Tim" >
</node>
Note: Before Ros is remapping, all name of remaping, including original and new names, will be resolved to global names. So, after remapping, all the names are usually relative names.
5 Other launch elements
5.1 including other files
For inclusion of other launch files, including all nodes and parameters of these launch files, with include element.
<include file= "Path-to-launch-file" >
In this case, the file attribute must write out the full path name of the launch file, which is cumbersome. Therefore, the commonly used
<include file= "$ (find package_name)/launch_file_name"/>
Note that when the launch file is executed, Roslaunch searches for all subdirectories under that package; Therefore, package_name must be given. In addition, include also supports the NS attribute, putting its contents in the specified namespace.
<include file= "..." ns= "Namespace_name"/>
5.2 Launch Arguments
To facilitate launch file refactoring, Roslaunch supports launch arguments, which also becomes arguments or args, similar to local variables.
Note: Although argument and parameter may sometimes be interchangeable, their significance in Ros is quite different. Parameters is a numerical value used by the ROS system, which exists on parameter server, and nodes can be programmed by Ros::p aram::get function, which can be obtained by the user Rosparam. In contrast, arguments only has meaning within launch files, and nodes cannot directly get their values.
(1) Statement argument
<arg name= "Arg_name" >
(2) Specify the value of the argument
Each argument in the launch file must have a specified value. There are several ways to assign a value.
First, assigning values on the command line
$ roslaunch package_name launch_file_name Arg-name:=arg_value
The second is to assign a value when declaring argument
<arg name= "Arg_name" default= "Arg_name"/>
<arg name= "Arg_name" value= "Arg_name"/>
The difference between the above two lines is that command-line arguments can override default, but cannot override value.
(3) Get the value of the variable
Once you declare a argument and assign a value, we can use the argument by Arg.
$ (arg arg-name)
If the row appears, Roslaunch replaces the value on its left with the value of the given arg-name.
(4) Pass argument value to included launch file
<include file= "Path-to-file" >
<arg name= "Arg_name" value= "Arg_value"/>
......
</include>
In the launch file, the same arguments appears in the launch file and in the launch file it contains, and it is written in both the launch file and included launch file:
<arg name= "Arg_name" value= "$ (arg arg_name)"/>
The first arg_name represents argument in the Indluded launch file, and the second Arg_name represents launch in the argument file. The result is the designated argument in launch documents and included The same values are available in the launch file.
5.3 Creating Groups
Group element can organize the specified nodes in a large launch file. It has two uses:
First, group can put several nodes into the same namespace
<group ns= "Namespace" >
<node pkg= "..." .../>
<node pkg= "..." .../>
......
</group>
Note that if grouped node already has its own namespace and is relative name, then the node's namespace is its relative name and the group namespace is the suffix.
Second, group can start or terminate a set of nodes at the same time.
<group if= "0 or 1" >
......
</group>
If the value of this property is 1