ROS学习--(十)roslaunch

来源:互联网 发布:mac系统崩溃重装系统 编辑:程序博客网 时间:2024/04/30 15:21

http://wiki.ros.org/roslaunch
首先说之前说过的.launch文件的格式:
1.roslaunch是通过单通道来读XML文件的,有覆盖的原则,所以如果有很多个标签,那么有用的是最后一个标签,但是依赖于此是不明智的,所以推荐使用$(arg)/设置来操作重写行为
2.xml文件的标签分为两种,一种是《foo/》,另一种是《foo》《/foo》(《》换成<>)。格式的话最好有缩进。
3.替换参数(substitution args)(还没看懂)
Roslaunch 标签的特性使他能够使用替换参数,目前支持的有
$(env ENVIRONMENT_VARIABLE) – 替换掉当前环境的一个变量值,如果环境变量没有设置则launch会失败。该值不能 被重写

$(optenv ENVIRONMENT_VARIABLE)$(optenv ENVIRONMENT_VARIABLE default_value) 

–如果环境变量已设置,则替换他。如果提供了default_value,则环境变量没设置也可以替换。如果default_value没有提供,则会使用空字符串。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)" />

default_value第一句是1.第二句:/home/marvin/ros_workspace,第三句: ros和rock

$(find pkg)

例子: $(find rospy)/manifest.xml。这是用相对路径来指定名称,以当前文件夹为根目录的路径,即为相对路径。我们更鼓励使用相对路径,因为绝对路径会限制launch设置的可移植性。使用相对路径时指向文件系统路径的目录会自己放到行里

$(anon [name]) 

anon是anonymous的意思,这个是以[name]为基础生成一个匿名的id。两次及以上使用$(anon foo)会生成相同的id(这里foo是一个名字)。

$(arg foo)

$(arg foo) evaluates to the value specified by an tag. There must be a corresponding tag in the same launch file that declares the arg. 暂时不能理解。。。
大概就是能够将foo作为参数床给前面的什么东西。看例子

  <param name="foo" value="$(arg my_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)" />

第一句能够把my_foo赋给参数parameter.
第二三句则是将a,b作为参数,传给add_two_ints。

4.具体例子:

<launch>  <!--该标签用ROS_ROOT和ROS_PACKAGE_PATH覆盖了默认的定义-->  <machine name="local_alt" address="localhost" default="true" ros-root="/u/user/ros/ros/" ros-package-path="/u/user/ros/ros-pkg" />  <!--俩普通节点-->    <node name="listener-1" pkg="rospy_tutorials" type="listener" />  <node name="listener-2" pkg="rospy_tutorials" type="listener" args="-foo arg2" /> <!--可再生的节点3-->  <node name="listener-3" pkg="rospy_tutorials" type="listener" respawn="true" /> <!--命名空间里的节点-->  <node ns="wg1" name="listener-wg1" pkg="rospy_tutorials" type="listener" respawn="true" />  <!--一组命名空间为wg2的节点-->  <group ns="wg2"> <!--remap的意思是如果有节点要订阅chatter的消息,但我们只有节点hello(发布与chatter相同的消息)这是就可以把hello的消息传给chatter-->    <remap from="chatter" to="hello"/>    <node pkg="rospy_tutorials" type="listener" name="listener" args="--test" respawn="true" />    <node pkg="rospy_tutorials" type="talker" name="talker">      <!--给talker设置私有节点-->      <param name="talker_1_param" value="a value" />      <remap from="chatter" to="hello-1"/>      <env name="ENV_EXAMPLE" value="some value" />    </node>  </group></launch>

参数赋值

<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 0
原创粉丝点击