当前位置:网站首页>2021-7-18 ROS笔记-xml语言相关
2021-7-18 ROS笔记-xml语言相关
2022-06-11 00:29:00 【萧易风船长】
XML基本知识
本文参考http://wiki.ros.org/roslaunch/XML
基本规则
xml语言由一个个、一对对标签表述出来,是一种标记语言,按照深度优先遍历和后来者覆盖前者的规则。
节点常用属性
name="name"节点名字
type="filename"可执行文件名
pkg="package"功能包名
output="screen"把节点标准输出到终端屏幕
respawn="true"复位属性,节点停止时,会自动重启
required="true"必要节点,终止时,其他节点也终止
ns="namespace"命名空间,为节点内的相对名称添加命名空间前缀
args="arguments"节点输入的参数
arg
arg表示argument, 是处于launch文件内部的自定义的替换参数(substitution args),不可被文件外部使用
arg的创建
<arg name="arg_name" default="arg_value"/>
<arg name="arg_name" value="arg_value"/>
其中前者是变量,可以修改值,初值是arg_value;后者是常量,不可修改
arg的调用
<param name="foo" value=$(arg arg_name)/>
arg的传递
用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>
用终端
$ roslaunch %YOUR_ROS_PKG% my_file.launch hoge:=my_value
其他替换参数(substitution args)
环境配置的略
$(find pkg)
返回指定包的地址,例如:
<include file="$(find 2dnav_pr2)/config/map_server.xml" />
$(anon name)
首先要讲讲匿名(anonymous name),因为ros的系统中同一个名字的节点只能出现一次,所以后出现的同名节点会杀死前面在运行的节点。匿名节点让名字独特,这样就防止节点名重复。
使用方法:
<launch>
<node name="$(anon my_infra_red_sensor)" pkg="your_package" type="infra_red_sensor.py" />
</launch>
$(eval [expression])
表示python运算表达式的结果
用法:
<param name="circumference" value="$(eval 2.* 3.1415 * arg('radius'))"/>
方便起见,下面两者在表达式中是等价的
arg('radius')
radius
由于xml语言不能两个变量叠在一起,如
a=$(path)$(name)
我们可以用eval把各个变量连在一起,比如:
"$(eval arg('foo') + env('PATH') + 'bar' + find('pkg')"
if和unless
if 表示 如果表达式为true 那么 包含这个tag
unless 表示 如果表达式为true 那么不包含这个tag
例如
<param name="foo" value="bar" unless="$(arg foo)" />
remap
ramap是一种重映射,通过remap可以把一个topic重映射到另一个topic,就不用在py文件里修改topic了,举例:
<remap from="/different_topic" to="/needed_topic"/>
param
表示parameter,是存在ros服务器上的参数,可以被外部调用
用法:
文件内定义
<param name="publish_frequency" type="double" value="10.0" />
文件外(通过yaml文件)调用
<rosparam command="load" file="FILENAME" />
可通过rospy.get_param()获取
详见http://wiki.ros.org/rospy_tutorials/Tutorials/Parameters
group
相当于一个容器,
可以修改namespace参数
注释
<!-- This is a comment -->
package
基本格式
我们先来看一段.xml文件内容
<package format="2"> <!--2表示新的格式-->
<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>
<!--以上五个属性是最小集,必须的-->
<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作为根元素嵌套在最外层 表示为功能包
嵌套在里的是package的属性
可以看见属性可以不自带数据,也可以自带数据,数据类型都是字符串
元包
如果可以作为元包导出,在根元素里面需要加上下面这些
<export> <!--这里需要有export和metapacakge标签, 注意这种固定写法-->
<metapackage/>
</export>
元包的CMakeList最基础是这样的
cmake_minimum_required(VERSION 2.8.3)
project(ros_academy_for_beginners)
find_package(catkin REQUIRED)
catkin_metapackage() #声明本软件包是一个metapacakge
一般的则是这样的
cmake_minimum_required(VERSION 2.8.3)
project(foobar)
find_package(catkin REQUIRED roscpp std_msgs)
catkin_package()
*.launch
launch 用于同时运行多个节点
下面贴一段代码
<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>
启动文件(Launch File)是ROS中一种同时启动多个节点的途径,还可以自动启动ROSMaster节点管理器,而且可以实现每个节点的各种配置,为多个节点的操作提供了很大便利。这个文件包含一组其他文件。每个包含的文件都包含与系统的某个部分(如定位、传感器处理和路径规划)有关的节点和参数(可能是嵌套的包含)。
边栏推荐
- How much is the bonus of China Patent Award, with a subsidy of 1million yuan
- 数字ic设计自学ing
- Tencent Cloud Database tdsql - Dajia comments | The Past, Present and Future of basic software
- 条码固定资产管理系统的作用,固定资产条码化管理
- PX4装机教程(六)垂起固定翼(倾转)
- 复利的保险理财产品怎么样?可以买吗?
- [interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV
- Garbled code when the command parameter contains% in VisualStudio debugging
- Introduction to the policy support of Beijing China Patent Award, with a subsidy of 1million yuan
- 北京东城区高新技术企业培育支持标准,补贴10万
猜你喜欢

Classic questions: 01 backpack, complete backpack, multiple backpack, two-dimensional cost Backpack

2.2. Ros+px4 simulation multi-point cruise flight - Square

Yunna Qingyuan fixed assets management and barcode inventory system

2.1、ROS+PX4仿真---定点飞行控制

中间件_Redis_05_Redis的持久化

SAS因子分析(proc factor过程和因子旋转以及回归法求因子得分函数)

Current limiting and download interface request number control

Web3生态去中心化金融平台——Sealem Finance

What are programmers in big factories looking at? It took me two years to sort it out, and I will look at it and cherish it!

Is the SQL query result different from what you expected? Mostly "null" is making trouble
随机推荐
Leetcode divide and conquer method
Configurable custom implementation 1 Implementation interface, 2 Custom configuration 3 Default configuration
After a/b machine is connected normally, B machine suddenly restarts. Ask a what is the TCP status at this time? How to eliminate this state in the server program?
Yunna PDA wireless fixed assets inventory management system
[geometric vision] 4.2 piecewise linear transformation
Leetcode permutation and combination problem backtracking
QGC地面站使用教程
负数+0+正数
Record the packaging of the googlechrome browser plug-in
部分 力扣 LeetCode 中的SQL刷题整理
hooks的设计哲学
MultipartFile和File互转工具类
Be careful, these hidden "bugs" of "array" to "collection"“
1.3 ROS 无人机简介
threejs:如何获得几何体的boundingBox?
Beijing Fangshan District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
ava. Lang.noclassdeffounderror: org/apache/velocity/context/context solution
Application of object storage S3 in distributed file system
北京平谷区高新技术企业培育支持标准,补贴10万
QGC ground station tutorial