[ROS learning] Basic operation of node operation management launch file

The concept and function of the launch file

The launch file is a file in XML format, which can start multiple local and remote nodes, and can also set parameters in the parameter server.
The role of the launch file is to simplify the configuration and startup of nodes and improve the startup efficiency of ROS programs.

scenes to be used

The launch file is widely used in ros. For example, multiple nodes may need to be started in a program. In the small turtle case built in ROS, if you want to control the movement of the turtle, you need to start multiple windows, and start roscore, the turtle interface node, and the keyboard control node respectively. If you call rosrun to start one by one every time, it is obviously inefficient. At this time, you can use the launch file to optimize.

launch creation

Create a launch folder in the project, which stores the launch file of the project.
insert image description here
Since the launch file does not involve compilation, after changing the launch file, you don’t need to compile it, and run the command directly:

source ./devel/setup.bash

Update the environment, then run the roslaunch project name launch file:

roslaunch launch_base test01.launch

Hierarchy and commands in the launch file

1 tag launch

The launch tag is the root tag for all launch files and acts as a container for other tags.

Attributes:

deprecated = "Deprecated Notice" informs users that the current launch file is deprecated. When running, there will be a red warning message saying that this file is outdated or deprecated .

2 node label

The node label is used to specify the ROS node, which is the most common label. It should be noted that: the roslaunch command cannot guarantee to start the nodes in the order of declaration of the node (the start of the node is multi-process)

Attributes:

pkg="package name" the package to which the node belongs
type="nodeType" node type (executable file with the same name)
name="nodeName" node name (the name of the node in the ROS network topology)
args="xxx xxx xxx " (optional) pass parameter to node
machine="machinename" start node on specified machine
respawn="true|false" (optional) whether to restart automatically if node exits
respawn_delay="N" (optional) if If respawn is true, then start the node after a delay of N seconds
required="true | false" (optional) Whether the node is required, if true, then if the node exits, it will kill the entire roslaunch
ns="xxx" (optional ) Start the node in the specified namespace xxx
clear_params="true | false" (optional) Before starting, delete all parameters in the private space of the node
output="log | screen" (optional) The log sending target can be set as log log file, or screen screen, the default is log

child label

env environment variable setting
remap remap node name
rosparam parameter setting
param parameter setting

3 include tags

The include tag is used to import another launch file in xml format into the current file

Attributes

file="$(find package name)/xxx/xxx.launch" file path to include
ns="xxx" (optional) Import files in the specified namespace

<launch>
    <include file="$(find launch所在项目名)/launch/***.launch"/>
</launch>

child label

env environment variable setting
arg Pass arguments to included files

4 remap tags

This tag is used for topic renaming. Sometimes some topics need to be synchronized with other topics, and this command is needed for remapping.

Attributes

from="xxx" original topic name
to="yyy" target name

The child label does not contain
Example:
In this example, the /turtle1/cmd_vel topic in the case of the little turtle is mapped to /cmd_vel, so this topic can use the built-in teleop_twist_keyboard in ROS to control the speed of the little turtle

<node pkg="turtlesim" type="turtlesim_node" name="myTurtle" output="screen">
        <remap from="/turtle1/cmd_vel" to="/cmd_vel"/>
</node>

insert image description here
insert image description here
After commenting out the remap, and then opening teleop_twist_keyboard, I found that I have been waiting to subscribe to the content of /cmd_vel
insert image description here

5 param tags

The param tag is mainly used to set parameters on the parameter server. The parameter source can be specified by value in the tag or loaded by an external file. In the node tag, it is equivalent to a private namespace

Attributes

name="namespace/parameter name" parameter name, can include namespace
value="xxx" (optional) define parameter value, if omitted here, you must specify an external file as the parameter source
type="str | int | double | bool | yaml" (optional) specifies the parameter type, if not specified, roslaunch will try to determine the parameter type, the rules are as follows: if the number containing '.' is not a floating point type, otherwise it is an integer type "true" and "false" is a bool value (case insensitive), others are strings

child tags without
example

<launch>
<param name="param_A" type="int" value="100"/>
<node pkg="turtlesim" type="turtlesim_node" name="myTurtle" output="screen">
 <param name="param_A" type="int" value="100"/>
 </node>
 </launch>

insert image description here

6 rosparam tags

The rosparam tag can import parameters from a YAML file, or export parameters to a YAML file, and can also be used to delete parameters. The rosparam tag is considered private when it is in a node tag.

Attributes

command="load | dump | delete" (optional, default load) load, export or delete parameters
file="$(find xxxxx)/xxx/yyy..." load or export to the yaml file
param="parameter name"
ns = "namespace" (optional)

The child label does not contain
an example.
It can be found that rosparam will increase the namespace corresponding to the node in the node node.

<launch>
 <!-- 测试rosparam load 加载yaml文件 -->
    <rosparam command="load" file="$(find launch_base)/launch/param.yaml"/>
    <node pkg="turtlesim" type="turtlesim_node" name="myTurtle" output="screen">
         <rosparam command="load" file="$(find launch_base)/launch/param.yaml"/>
    </node>
</launch>

insert image description here
Test dump and delete

<launch>
<rosparam command="dump" file="$(find launch_base)/launch/param_out.yaml"/>
<rosparam command="delete" param="bg_R"/>
</launch>
7 group label

The group tag can group nodes and has the ns attribute, which allows nodes to belong to a certain namespace

Attributes

ns="namespace" (optional)
clear_params="true | false" (optional)
Whether to delete all parameters of the group namespace before starting (use with caution...this function is dangerous)

child label

tags other than the launch tag

Example It
is equivalent to starting two little turtle nodes

<launch>
    <group ns="first">
        <node pkg="turtlesim" type="turtlesim_node" name="myTurtle" output="screen" />
        <node pkg="turtlesim" type="turtle_teleop_key" name="myTurtleCon" output="screen" />
     </group>
      <group ns="second">
        <node pkg="turtlesim" type="turtlesim_node" name="myTurtle" output="screen" />
        <node pkg="turtlesim" type="turtle_teleop_key" name="myTurtleCon" output="screen" />
     </group>
</launch>
8 arg label

The arg tag is used for dynamic parameter passing, similar to function parameters, which can enhance the flexibility of the launch file

Attributes

name="parameter name"
default="default value" (optional)
value="value" (optional) cannot coexist with default
doc="description" parameter description

child tags without
example

<launch>
<!-- 类似声明固定的参数 -->
    <arg  name="car_len"   default="15"/>
    <param name="A" value="$(arg car_len)"/>
    <param name="B" value="$(arg car_len)"/>
    <param name="C" value="$(arg car_len)"/>
</launch>

Order

roslaunch hello.launch car_len:=

Guess you like

Origin blog.csdn.net/qq_29750461/article/details/128828579