当前位置:网站首页>2021-7-18 ROS notes XML language related

2021-7-18 ROS notes XML language related

2022-06-11 01:48:00 Captain xiaoyifeng

XML Basic knowledge

In this paper, the reference http://wiki.ros.org/roslaunch/XML

The basic rule

xml Language consists of 、 A pair of labels , It's a markup language , According to the rules of depth first traversal and later overwriting the former .

Common attributes of nodes

name="name" Node name
type="filename" Executable file name
pkg="package" Function package name
output="screen" Output the node standard to the terminal screen
respawn="true" Reset properties , When node stops , It will restart automatically
required="true" Necessary nodes , At the end of , Other nodes also terminate
ns="namespace" Namespace , Add a namespace prefix to the relative names within the node
args="arguments" Parameters entered by the node

arg

arg Express argument, Is in launch Custom replacement parameters inside the file (substitution args), Cannot be used outside the file

arg The creation of

<arg name="arg_name" default="arg_value"/>
<arg name="arg_name" value="arg_value"/>

Where the former is a variable , You can change the value , The initial value is arg_value; The latter is a constant , Do not modify the

arg Call to

<param name="foo" value=$(arg arg_name)/>

arg The transfer

use include

<include file="included.launch">
  <!-- all vars that included.launch requires must be set -->
  <arg name="hoge" value="fuga" />
</include>
<launch>
  <!-- declare arg to be passed in -->
  <arg name="hoge" /> 

  <!-- read value of arg -->
  <param name="param" value="$(arg hoge)"/>
</launch>

Use terminal

$ roslaunch %YOUR_ROS_PKG% my_file.launch hoge:=my_value

Other substitution parameters (substitution args)

Environment configuration is omitted

$(find pkg)

Returns the address of the specified package , for example :

<include file="$(find 2dnav_pr2)/config/map_server.xml" />

$(anon name)

First, let's talk about anonymity (anonymous name), because ros Nodes with the same name can only appear once in the system of , The node with the same name that appears later will kill the previous running node . Anonymous nodes make names unique , This prevents duplicate node names .
Usage method :

<launch>
    <node name="$(anon my_infra_red_sensor)" pkg="your_package" type="infra_red_sensor.py" />
</launch>

$(eval [expression])

Express python The result of the operation expression
usage :

<param name="circumference" value="$(eval 2.* 3.1415 * arg('radius'))"/>

Convenience , The following two are equivalent in the expression

arg('radius')
radius

because xml A language cannot have two variables superimposed on each other , Such as

a=$(path)$(name)

We can use eval Connect the variables together , such as :

"$(eval arg('foo') + env('PATH') + 'bar' + find('pkg')"

if and unless

if Express If the expression is true that Include this tag
unless Express If the expression is true So it doesn't include this tag
for example

<param name="foo" value="bar" unless="$(arg foo)" />

remap

ramap Is a remapping , adopt remap You can put a topic Remap to another topic, You don't have to be in py Modification in the document topic 了 , give an example :

<remap from="/different_topic" to="/needed_topic"/>

param

Express parameter, Exist ros Parameters on the server , Can be called externally
usage :
Defined in the file

<param name="publish_frequency" type="double" value="10.0" />

The documents ( adopt yaml file ) call

<rosparam command="load" file="FILENAME" />

It can be done by rospy.get_param() obtain
See http://wiki.ros.org/rospy_tutorials/Tutorials/Parameters

group

Equivalent to a container ,
You can modify namespace Parameters

notes

<!-- This is a comment -->

package

The basic format

Let's start with a paragraph .xml The contents of the document

<package format="2"> <!--2 Represents a new format -->
  <name>foobar</name>
  <version>1.2.4</version>
  <description>
  This package provides foo capability.
  </description>
  <maintainer email="[email protected]">PR-foobar</maintainer>
  <license>BSD</license>
<!-- The above five attributes are the minimum set , necessary -->
  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>roscpp</build_depend>
  <build_depend>std_msgs</build_depend>

  <exec_depend>roscpp</exec_depend>
  <exec_depend>std_msgs</exec_depend>
</package>

package Nested as the root element in the outermost layer Expressed as a feature pack
Nested inside is package Properties of
It can be seen that the attribute can not bring its own data , You can also bring your own data , Data types are strings

Yuan Bao

If it can be exported as a meta package , You need to add the following to the root element

<export> <!-- There needs to be export and metapacakge label ,  Pay attention to this fixed writing -->
<metapackage/>
</export>

Meta packaged CMakeList The most basic thing is

cmake_minimum_required(VERSION 2.8.3)
project(ros_academy_for_beginners)
find_package(catkin REQUIRED)
catkin_metapackage() # Declare that this package is a metapacakge

Generally, this is the case

cmake_minimum_required(VERSION 2.8.3)
project(foobar)
find_package(catkin REQUIRED roscpp std_msgs)
catkin_package()

*.launch

launch Used to run multiple nodes at the same time
Here's a piece of code

<launch>
  <group name="wg">
    <include file="$(find pr2_alpha)/$(env ROBOT).machine" />
    <include file="$(find 2dnav_pr2)/config/new_amcl_node.xml" />
    <include file="$(find 2dnav_pr2)/config/base_odom_teleop.xml" />
    <include file="$(find 2dnav_pr2)/config/lasers_and_filters.xml" />
    <include file="$(find 2dnav_pr2)/config/map_server.xml" />
    <include file="$(find 2dnav_pr2)/config/ground_plane.xml" />

    <!-- The navigation stack and associated parameters -->
    <include file="$(find 2dnav_pr2)/move_base/move_base.xml" />
  </group>
</launch>

Startup file (Launch File) yes ROS A way to start multiple nodes at the same time , It can also start automatically ROSMaster Node manager , And various configurations of each node can be realized , It provides great convenience for the operation of multiple nodes . This file contains a set of other files . Each included file contains a part of the system ( Such as positioning 、 Sensor processing and path planning ) Relevant nodes and parameters ( May be nested contains ).

原网站

版权声明
本文为[Captain xiaoyifeng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206110029367821.html