ROS launch file 写法

ROS launch file 使用XML格式

以一个launch file 中对同一参数做多次配置,最后一次的配置将会生效


substitution args

Roslaunch tag可以利用substitution args,在launching nodes之前 roslaunch 会先处理substitution args,

目前支持如下的substitutuion args:

$(env ENVIRONMENT_VARIABLE)

从当前环境中带入一个环境变量的值,如果环境变量没有被设置的话,launch会失败。

这个值可以被<env>tags重写。

$(optenv ENVIRONMENT_VARIABLE)$(optenv ENVIRONMENT_VARIABLE default_value)

带入一个已设置的环境变量的值,当该环境变量没有被设置,采用default_value的值,

如果给default_value的值,会带入一个空的string。

default_value可以是多个单词,用空格隔开。

例子:

<param name="foo" value="$(optenv NUM_CPUS 1)" />
  <param name="foo" value="$(optenv CONFIG_PATH /home/marvin/ros_workspace)" />
  <param name="foo" value="$(optenv VARIABLE ros rocks)" />


$(find pkg)

例子: $(find rospy)/manifest.xml. 

指定package-relative path. 文件系统路径到package目录将会被inline方式带入。

Use of package-relative paths is highly encouraged as hard-coded paths inhibit the portability of the launch configuration.

高度鼓励使用package-relative paths作为hard-coded paths...


Forward and backwards slashes will be resolved to the local filesystem convention.

正反斜杠可用来处理本地文件系统转换。


$(anon name)

例子:$(anon rviz-l).

产生一个基于name的匿名id,name自身是一个独特的标识符:多次使用$(anon foo)

将会产生相同的被匿名的name。这被用于<node>名字属性attributes,用来创建具有匿名names的nodes

因为ROS需要nodes有独特的名字。

例子:

  <node name="$(anon foo)" pkg="rospy_tutorials" type="talker.py" />
  <node name="$(anon foo)" pkg="rospy_tutorials" type="talker.py" />


$(arg foo)

$(arg foo)等于一个由<arg>tag指定的值,在同一个launch file之中必须有一个对应的tag来声明这个<arg>。

例子:

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

将会把argument my_foo赋值给foo参数

另外一个例子:

<node name="add_two_ints_server" pkg="beginner_tutorials" type="add_two_ints_server" />
<node name="add_two_ints_client" pkg="beginner_tutorials" type="add_two_ints_client" args="$(arg a) $(arg b)" />

将会同时launch server和client 以参数来传递value a 和 value b,


可以通过下面的形式来launch project:

roslaunch beginner_tutorials launch_file.launch a:=1 b:=5


Substitution args当前被local machine解析,换句话说,环境变量和ROS package路径都会采用你当前环境的设置,即使是对于

remotely launched process也是如此。(即使你机器上的process是通过远程launch起来的,也只会采用你本地机器上的环境变量

和ROS package)。 


if 和 unless 属性(attributes)

所有的tags都支持 if 和 unless 属性,这样可以通过真值来包括或者排除一个tag

1 和 true是真,0和 false 是假,其他值都会导致error。

if=value(optional)

如果value等于ture,include tag和它的内容。

unless=value(optional)

除非value等于false,include tag和它的内容。

例子:

<group if="$(arg foo)">
  <!-- stuff that will only be evaluated if foo is true -->
</group>


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

 <!-- This param won't be set when "unless" condition is met -->


一些.launch XML 配置文件的例子


下面的例子展示了一个最小的launch配置脚本,它launch了一个“talker”node,这个node属于 rospy_tutorials package

这个node将会launch在本地机器上,并且使用当前所配置的ROS环境。

<launch>
  <node name="talker" pkg="rospy_tutorials" type="talker" />
</launch>


设置参数

也可以在parameter server上面设置参数,在任何node launch之前,这些参数将会被储存在parameter server上面

如果值没有什么歧义的话,你可以忽略type attribute.支持的type有str, int double,bool。你也可以给定一个文件的内容

而非使用textfile 或者 binfile attributes。

例子:

<launch>
  <param name="somestring1" value="bar" />
  <!-- force to string instead of integer -->
  <param name="somestring2" value="10" type="str" />

  <param name="someinteger1" value="1" type="int" />
  <param name="someinteger2" value="2" />

  <param name="somefloat1" value="3.14159" type="double" />
  <param name="somefloat2" value="3.0" />

  <!-- you can set parameters in child namespaces -->
  <param name="wg/childparam" value="a child namespace parameter" />

  <!-- upload the contents of a file to the server -->
  <param name="configfile" textfile="$(find roslaunch)/example.xml" />
  <!-- upload the contents of a file as base64 binary to the server -->
  <param name="binaryfile" binfile="$(find roslaunch)/example.xml" />

</launch>


  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值