当前位置:网站首页>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节点管理器,而且可以实现每个节点的各种配置,为多个节点的操作提供了很大便利。这个文件包含一组其他文件。每个包含的文件都包含与系统的某个部分(如定位、传感器处理和路径规划)有关的节点和参数(可能是嵌套的包含)。
边栏推荐
- 2.1 ros+px4 simulation - Fixed Point flight control
- Uninstall mavros
- Projet Visualisation et analyse des données sur les épidémies basées sur le Web crawler
- SAS因子分析(proc factor过程和因子旋转以及回归法求因子得分函数)
- [interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV
- [ROS] review of 2021 ROS Summer School
- Some tips for programmers to deal with stress
- 項目_基於網絡爬蟲的疫情數據可視化分析
- Conda安装Pytorch后numpy出现问题
- Beijing Dongcheng District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
猜你喜欢

threejs:流光效果封装

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

Garbled code when the command parameter contains% in VisualStudio debugging

Record the packaging of the googlechrome browser plug-in

Once you know these treasure websites, you can't live without them!!!

ROS parameter server

PX4从放弃到精通(二十四):自定义机型

条码固定资产管理系统的作用,固定资产条码化管理

记录打包GoogleChrome浏览器插件

How to write this with data and proc without SQL
随机推荐
Is the SQL query result different from what you expected? Mostly "null" is making trouble
IRS application release 16: H5 application design guide
Negative number +0+ positive number
Multi interest recall model practice | acquisition technology
About mobx
数字ic设计自学ing
北京門頭溝區高新技術企業培育支持標准,補貼10萬
Leetcode 1814 count nice pairs in an array (recommended by map)
threejs:两点坐标绘制贝赛尔曲线遇到的坑
Implementing MySQL fuzzy search with node and express
hooks的设计哲学
Beijing Yanqing District high tech enterprise cultivation support standard, with a subsidy of 100000 yuan
记录打包GoogleChrome浏览器插件
中间件_Redis_06_Redis的事务
Hao expresses his opinions: what small good habits have you adhered to?
Norme de soutien à la culture des entreprises de haute technologie du district de Mentougou à Beijing, subvention de 100 000 RMB
Projet Visualisation et analyse des données sur les épidémies basées sur le Web crawler
ROS parameter server
Multipartfile and file interoperation tool classes
多兴趣召回模型实践|得物技术