[ROS study notes 11] the use of ROS meta-function package and launch file

[ROS study notes 11] the use of ROS meta-function package and launch file

Written in the front, this series of notes refers to the tutorial of AutoLabor, the specific project address is here

foreword


ROS is a multi-process (node) distributed framework, a complete ROS system implementation:

It may contain multiple hosts;
each host has multiple workspaces;
each workspace contains multiple function packages;
each function package contains multiple nodes (Node), different Each node has its own node name;
each node may also set one or more topics (topic)...


1. ROS meta-function package

**Scenario: **Completing a systematic function in ROS may involve multiple function packages, such as the realization of the robot navigation module, which has different sub-level function packages such as maps, positioning, path planning, etc. So when the caller installs the module, does he need to install each function package one by one?

Obviously, the efficiency of installing function packages one by one is low. In ROS, there is a way to package different function packages into one function package. When installing a function module, just call the packaged function package directly. The package is also called metapackage.

concept

MetaPackage is a concept of a file management system for Linux. It is a virtual package in ROS, which has no substantive content, but it depends on other packages. In this way, other packages can be combined. We can think of it as a directory index of a book, telling us this Which subpackages are in the package collection and where to download them.

For example:

  • The sudo apt install ros-noetic-desktop-full command uses the meta-function package when installing ros. This meta-function package depends on some other function packages in ROS. When installing this package, it will also install dependencies.

And some common MetaPackage: navigation moveit! turtlebot3…

effect

It is convenient for users to install. We only need this package to organize and install other related packages together.

accomplish

First, create a new function package, no need to add new dependencies, and then modify package.xml, the content is as follows:

 <exec_depend>被集成的功能包</exec_depend>
 .....
 <export>
   <metapackage />
 </export>

Finally, modify CMakeLists.txtthe content as follows:CMakeLists cannot have line breaks, otherwise compilation will fail.

cmake_minimum_required(VERSION 3.0.2)
project(demo)
find_package(catkin REQUIRED)
catkin_metapackage()

Please also refer to:

Here is an example of creating a new meta-function package:

If we want to create a new MetaPackage to integrate the above three functional packages together, we can do this by first creating a new MetaPackage without any dependencies.

Just leave it blank here.

Then modify it package.xmlas follows:

Then modify it CMakeLists.txtas follows:


2. ROS node operation management launch file

We are no strangers to the use of launch files. In the first chapter, we have introduced:

A program may need to start multiple nodes, for example: ROS built-in small turtle case, if you want to control the movement of the turtle, you need to start multiple windows, respectively start roscore, the turtle interface node, and the keyboard control node. If you call rosrun to start one by one every time, it is obviously inefficient, how to optimize?

The optimization strategy adopted is to use the roslaunch command to collect the launch file to start the management node, and in the subsequent tutorials, the launch file is also used many times.

concept

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.

effect

Simplify the configuration and startup of nodes, and improve the startup efficiency of ROS programs.

1. Create a new launch file

Add a launch directory under the function package, create a new xxxx.launch file under the directory, and edit the launch file

<launch>
    <node pkg="turtlesim" type="turtlesim_node"     name="myTurtle" output="screen" />
    <node pkg="turtlesim" type="turtle_teleop_key"  name="myTurtleContro" output="screen" />
</launch>

2. Call the launch file

roslaunch 包名 xxx.launch

Note: When the roslaunch command executes the launch file, it will first judge whether roscore is started, if it is started, it will not start again, otherwise, it will automatically call roscore

The example effect is as follows:


2.1 Launch of the launch file label

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

1. Attributes

  • deprecated="弃用声明"

Inform the user that the current launch file has been enabled

2. Subset label

All other tags are subset tags of launch

Example:

2.2 launch file label node

<node>The 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 node in the order of declaration of the node (the start of the node is multi-process)

1. Attributes

  • pkg="package name"

    the package the node belongs to

  • type=“nodeType”

    Node type (executable with the same name)

  • name=“nodeName”

    NodeName (the name of the node in the ROS network topology)

  • args="xxx xxx xxx" (optional)

    Pass parameters to node

  • machine="machine name"

    Start the node on the specified machine

  • respawn="true|false" (optional)

    Whether to automatically restart if the node exits

Example:

  • respawn_delay="N" (optional)

    If respawn is true, start the node after a delay of N seconds

  • required="true|false" (optional)

    Whether the node must, if true, then if the node exits, the entire roslaunch will be killed

Example:

  • ns="xxx" (optional)

    Start the node in the specified namespace xxx

Example:

  • clear_params="true | false" (optional)

    Before starting, delete all parameters of the private space of the node

  • output="log|screen" (optional)

    Log sending target, can be set to log log file, or screen screen, the default is log

2. Child label

  • env environment variable settings
  • remap remaps node names
  • rosparam parameter setting
  • param parameter setting

2.3 Include of launch file tag

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

1. Attributes

  • file="$(find package name)/xxx/xxx.launch"

    file paths to include

  • ns="xxx" (optional)

    Import files in the specified namespace

2. Child label

  • env environment variable settings
  • arg to pass arguments to the included file

Example:

2.4 remap of launch file label

for topic renaming

1. Attributes

  • from=“xxx”

    original topic name

  • to=“yyy”

    target name

2. Subset label

none

Example:

I want to use python's built-in keyboard control node to control the movement of the turtle

rosrun teleop_twist_keyboard teleop_twist_keyboard.py

will conflict because

The topic of the keyboard control input is /cmd_veland the topic required by the turtle control input is /hello/turtle1/cmd_vel, the two are different, so they cannot be controlled.

Now we remapcan do this with .


2.5 param of launch file tag

<param>Tags are 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. When it is in the <node>tag, it is equivalent to a private namespace.

1. Attributes

  • name="namespace/parameter name"

    The parameter name, which can contain a namespace

  • value="xxx" (optional)

    Define the parameter value, if omitted here, you must specify an external file as the parameter source

  • type="str|int|double|bool|yaml" (optional)

    Specify 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 parsed as a floating point type, otherwise it is an integer type
    • "true" and "false" are bool values ​​(case insensitive)
    • else is a string

2. Child label

  • none

The example effect is as follows:


2.6 rosparam for launch file tag

<rosparam>Tags can import parameters from YAML files, export parameters to YAML files, and can also be used to remove parameters. <rosparam>Tags <node>are considered private when they are in a tag.

1. Attributes

  • command="load | dump | delete" (optional, default load)

    Load, export or delete parameters

  • file=“$(find xxxxx)/xxx/yyy…”

    yaml file to load or export to

  • param="parameter name"

  • ns="namespace" (optional)

2. Child label

  • none

An example:

First yamlthe file is set like this

Then import yamlthe parameters in


2.7 group of launch file label

<group>Labels can group nodes and have the ns attribute, allowing nodes to belong to a namespace

1. Attributes

  • ns="namespace" (optional)

  • clear_params="true | false" (optional)

    Before starting, whether to delete all parameters of the group namespace (use with caution...this function is dangerous)

2. Child label

  • tags other than the launch tag

Example:


2.8 arg of launch file label

<arg>Tags are used for dynamic parameter passing, similar to function parameters, which can enhance the flexibility of launch files

1. Attributes

  • name="parameter name"

  • default="default value" (optional)

  • value="value" (optional)

    Cannot coexist with default

  • doc="description"

    Parameter Description

2. Child label

  • none

3. Examples

  • Launch file parameter transfer syntax implementation, hello.lcaunch

    <launch>
        <arg name="xxx" />
        <param name="param" value="$(arg xxx)" />
    </launch>
    Copy
    
  • Command line calls launch to pass parameters

    roslaunch hello.launch xxx:=

An example:


Reference

http://www.autolabor.com.cn/book/ROSTutorials/di-2-zhang-ros-jia-gou-she-ji/23-fu-wu-tong-xin/224-fu-wu-tong-xin-zi-ding-yi-srv-diao-yong-b-python.html

Guess you like

Origin blog.csdn.net/qq_44940689/article/details/129338904