当前位置:网站首页>Ros-10 roslaunch summary

Ros-10 roslaunch summary

2022-07-05 08:45:00 m0_ forty-six million ninety-three thousand eight hundred and t

One 、 Concept

Launch File is ROS Provided , You can run multiple nodes The file of .Launch The file is in a special XML Format to write , stay ROS packages Widely used in . Compare with rosrun, rosrun Only one can run node, roslaunch You can run multiple node, and roslaunch It will be detected before operation rosmaster Whether to start , If it is not started, it will start automatically .

Two 、 newly build launch file

 launch The documents are usually in the form of .launch Suffix as file name , Put it in package Of launch Under the folder , Launch File is XML file .

3、 ... and 、launch Label in file

3.1 launch label

Every XML The file has to have a root element. and launch Of documents root element By a pair launch Tag definition .

        <launch>

        ...

        </launch>

Launch Others in the file elements Must be in this pair tags Between .

launch There is an attribute in the tag :deprecated=" Disclaimer ", It can be used to inform users of the current launch The document has been discarded

3.2 node label

launch The core of the document is a series node elements, Every node element Start a node.node element as follows :

        <node pkg=”package_name” type=”executable_name” name=”node_name”/>

Every node All nodes are one rosrun. And each node Nodes must contain pkg,type,name Three attributes , You can also include output,respawn,required,ns Equal attribute .

1. attribute

        pkg=" Package name " The package to which the node belongs

  • type="nodeType" Node type ( Executable file name with the same name , That is, if it is py Document rules file name .py, If it is cpp The file can be written directly to the executable file generated after compilation )

  • name="nodeName"

    The name of the node ( stay ROS The name of the node in the 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 ): If the node exits , Whether to restart automatically

  • respawn_delay=" N" ( Optional ): If respawn by true, So delay N Start the node in seconds

  • required="true | false" ( Optional ): Whether the node must , If true, Then, if the node exits , Will kill the whole roslaunch

  • ns="xxx" ( Optional ): In the specified namespace xxx Start node , Namespace is ros Node prefix in network topology , This helps avoid node duplication

  • output="log | screen" ( Optional ): Log sending destination , It can be set to log Log files , or screen The screen , The default is log

2. Child labels

  • env Environment variable Settings

  • remap Remap node name

  • rosparam Parameter setting

  • param Parameter setting

The use of child labels will be introduced later

3.3 include label

include Tags can be imported into another launch File to current file , Be similar to C The language header file contains .

  Usage is as follows :

1. attribute

  • file="$(find Package name )/xxx/xxx.launch": File path to include

  • ns="xxx" ( Optional ): Import the file in the specified namespace

The specific use :

<include file="$(find pckname)/launch/filename.launch" />

2. Child labels  

  • env Environment variable Settings

  • arg Pass parameters to the included file

3.4 remap label

Remap : For renaming topics , Sometimes, no matter it is ros The topics provided by the system are still self-defined topics , The topic name has been fixed . meanwhile ros The system or its own defined subscribers , The name of the subscription has been written . However, sometimes the topic subscribed by subscribers is inconsistent with the topic name published by publishers , It can be used at this time remap Remapping topic names . You can choose to remap the topic name published by the publisher or the topic subscribed by the subscriber .

1. attribute

  • from="xxx": Original topic name

  • to="yyy": Target name

    <remap from=:" Topic name with namespace " to =" New words title "

2. Child labels  

         nothing  

for example  

<node pkg="turtlesim" type="turtlesim_node" name="my_turtle" output="screen">
    <remap from "/turtle/cmd" to="/cmd_vel"/>
</node>

1, When remap and node Parallel time ,from and to It can be for launch Any node in the file .
2, When remap When inside a node ,from Must be defined for the current node ,to It can be launch Any node in the file .

3.5 param label  

<param> The tag is mainly used to set parameters on the parameter server

1. attribute

  • name=" Namespace / Parameter name "

    Parameter name , Can contain namespaces

  • value="xxx" ( Optional )

    Define parameter values , If omitted here , You must specify an external file as the parameter source

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

    Specify parameter type , If not specified ,roslaunch Will try to determine the parameter type , The following rules :

    • If you include '.' The number of is not parsed as a floating point type , Otherwise, it is an integer

    • "true" and "false" yes bool value ( Case insensitive )

    • Others are strings

2. Child labels

  • nothing

param Tags can be in node Labels can also be used in node Use outside the label , But it should be noted that if in node Use in label param Set parameters , Then the declared parameters are parameters in the private namespace .( Is there anything special about the parameters of private namespaces ? Other nodes cannot be changed ?)

<launch>
    <param name=param_A" type="int" value="4" />
    <node pkg="turtlesim tyoe="turtlesim_node" name="my_turtle" output="screen">
       <param name=param_B" type="double" value="3.14" />
    </node>
    <node  pkg="turtlesim tyoe="turtle_teleop_key" name="my_key" output="screen"/>
</launch>

 3.6 rosparam label  

 <param> The tag is mainly used to set parameters on the parameter server ,<rosparam> Labels can be from YAML File import parameters , Or export parameters to YAML file , It can also be used to delete parameters ,<rosparam> Tag in <node> Label is treated as private .

1. attribute

  • command="load | dump | delete" ( Optional , Default load)

    load 、 Export or delete parameters

  • file="$(find xxxxx)/xxx/yyy...."

    Loaded or exported to yaml file

  • param=" Parameter name "

  • ns=" Namespace " ( Optional )

2. Child labels

  • nothing

example 1 from .yaml Load parameters in the file

<launch>
    <param name=param_A" type="int" value="4" />
    <rosparam command="load" file="$(find launch_basic)/launch/params.yaml"/>
    <node pkg="turtlesim tyoe="turtlesim_node" name="my_turtle" output="screen">
       <param name=param_B" type="double" value="3.14" />
       <rosparam command="load" file="$(find launch_basic)/launch/params.yaml"/>
    </node>
    <node  pkg="turtlesim tyoe="turtle_teleop_key" name="my_key" output="screen"/>
</launch>

rosparam Tags can be in node It can also be used in the label node Use outside the label , But it should be noted that if in node Use in label rosparam Set parameters , Then the declared parameters are parameters in the private namespace .

example 2 Export the currently active parameters to .yaml file

It should be noted that ,rosparam Whether in the node Is still in the label of node Out of label ,ros The system will execute this tag first . So if you want to export active parameters in the current system , You need to build another .launch file .

<rosparam command="dump" file="$(find pckname)/launch/params_out.yaml"/>

example 3 Delete the currently active parameter

<rosparam command=""delete" param=" Parameter name " />

 3.7 group label  

<group> Tags can group nodes , have ns attribute , Nodes can belong to a namespace

1. attribute

  • ns=" The name space " ( Optional )

  • clear_params="true | false" ( Optional )

    Before startup , Delete all parameters of the group namespace ( Use with caution .... This function is dangerous )

2. Child labels

  • except launch Labels other than labels
<launch>
    <group ns="first">
        <node pkg="turtlrsim" type="turtlesim_node" name="my_turtle" output="screen"/>
        <node pkg="turtlrsim" type="turtle_teleop_key" name="my_key" output="screen"/>
    </group>
    <group ns="second">
        <node pkg="turtlrsim" type="turtlesim_node" name="my_turtle" output="screen"/>
        <node pkg="turtlrsim" type="turtle_teleop_key" name="my_key" output="screen"/>
    </group>

You can see two groups node The nodes are exactly the same , But the runtime will not report an error , Because the namespace is different .

  3.8 arg label

<arg> The label is used for Dynamic transfer parameters , Similar to function macro definition , Can enhance launch Flexibility of documents

1. attribute

  • name=" Parameter name "

  • default=" The default value is " ( Optional )

  • value=" The number " ( Optional ) : You can't be with default Coexist

  • doc=" describe ": Parameter description

2. Child labels

  • nothing

For example, there is a length parameter , Several variables are used . At this time, I can define macros , Then call this macro parameter directly when assigning values to variables .

  Four 、 function launch file

Before operation source once :source devel/setup.bash

Then run the following command :

roslaunch pckname filename.launch

Reference resources :4.2.8 launch Document label arg · Autolabor-ROS Introduction to Robotics 《ROS Theory and practice 》 Zero basic course

原网站

版权声明
本文为[m0_ forty-six million ninety-three thousand eight hundred and t]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140540130488.html