Common components in ROS (1)-launch startup file

Common components in ROS (1)-launch startup file
Whenever you need to run a ROS node or tool, you need to open a new terminal to run a command.
The launch file (Launch File) is a way to start multiple nodes at the same time in ROS. It can also automatically start the ROS Master node manager, and can implement various configurations of each node, providing a great way for the operation of multiple nodes. Great convenience.
1. Basic elements
A simple and complete launch file, which is described in the form of XML, contains a root element and two node elements
1. The <launch>
XML file must contain a root element, and the root element in the launch file is defined by tags , Other content in the file must be included in this tag:

<launch>
    ...
<launch>

2.
The core of the <node> startup file is to start the ROS node, which is defined by a label. The syntax is as follows:

<node pkg="package-name" type="executable-name" name="node-name" />

2. Parameter setting In
order to facilitate setting and modification, the launch file supports the function of parameter setting, which is similar to the variable declaration in the programming language. There are two label elements for parameter settings: <param> and <arg >, one represents parameter and the other represents argument. When translated into Chinese, these two label elements both mean "parameters", but the meanings of these two "parameters" are completely different.
1. <param>
parameter is the parameter in the operation of ROS system and is stored in the parameter server. The parameter is loaded through the <param> element in the launch file; after the launch file is executed, the parameter is loaded on the ROS parameter server. Each active node can get the value of parameter through the ros::param::get() interface, and the user can also get the value of parameter through the rosparam command in the terminal.
The usage of <param> is as follows:

<param name="output_frame" value="odom"/>

2. The <arg>
argument is another concept, similar to the local variables in the launch file, and is limited to the launch file to facilitate the reconstruction of the launch file. It has nothing to do with the internal implementation of the ROS node.
Set argument to use the <arg> tag element, the syntax is as follows:

<arg name="arg-name" defauit="arg-value"/>

When the argument needs to be used in the launch file, it can be called as follows:

<param name="foo" value="$(arg arg-name)" />
<node name="node" pkg="package" type="type" args="$(arg arg-name)" />

3. Remapping mechanism
The design goal of ROS is to increase the code reuse rate, so many of the feature packages in the ROS community can be used directly without paying attention to the internal implementation of the feature package.
ROS provides a remapping mechanism. Simply put, it is to take aliases. Similar to the alias mechanism in C++, we don’t need to modify the interface of other people’s function packages. We only need to remap the interface name and take an alias. The system recognizes it (the data types of the interfaces must be the same). The <remap> tag in the launch file can help us achieve this remapping function.
Fourth, nested multiplexing
In a complex system, there are often many launch files, and there will be dependencies between these launch files. If you want to directly reuse the content of an existing launch file, you can use the <include> tag to include other launch files, which is almost the same as the include in the C language.

<include file="$(dirname)/other.launch" />

Launch is a very practical and flexible function in the ROS framework. It is similar to a high-level programming language and can help us manage all aspects of starting the system. In the process of using ROS, in many cases, we don't need to write a lot of code. We only need to use the existing function package and edit the launch file to complete many robot functions.

Guess you like

Origin blog.csdn.net/weixin_45661757/article/details/112754953