0%

ROS基础:launch文件

roslaunch的主要作用时启动多个节点,同时在参数服务器上设置参数。使用roslaunch时,会自动启动roscore。

常见语法

  1. $(find pkg): 获得包的相对路径;
  2. $(arg foo): 计算foo的值,arg可以理解成launch文件的内部变量,args是node中传递给节点的参数;
  3. ifunless:所有标签都支持ifunless标签,用来作为条件判断;

launch标签

  1. launch: 最大的标签,唯一的作用是作为launch容器,包含其他标签;

  2. node: 启动节点的标签。launch文件不能保证里面指定的节点的启动顺序,这个是故意设计的,因为在外部无法知道一个节点何时完全初始化了,所以在写节点的时候,要充分考虑节点的启动顺序带来的安全性问题。

    1
    <node name="listener1" pkg="rospy_tutorials" type="listener" args="--test" respawn="true" />
  3. include:加入另一个launch文件;

    1
    <include file="$(find ur_description)/launch/ur5_bringup.launch" />
  4. remap:参数重映射,可以参考重映射博客;

    1
    <remap from="/different_topic" to="/needed_topic"/>
  5. param: 设置参数服务器上的参数,可以使用value, textfile, binfile, command命令加载具体参数。如果该标签放在node下面,将被当做私有参数。

    1
    <param name="publish_frequency" type="double" value="10.0" />
  6. rosparam: 将yaml文件设置为参数为参数服务器上的参数,同样的,如果该标签出现在node里面,将作为私有参数;

    1
    <rosparam command="load" file="$(find ur_description)/config/kinematics.yaml" />
  7. arg: 作为launch文件的局部变量使用,使得launch文件的扩展性更强。一般利用arg在多个launch文件传递参数,或者为param设置值。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    # my_file.launch
    <include file="included.launch">
    <!-- all vars that included.launch requires must be set -->
    <arg name="hoge" value="fuga" />
    </include>

    # included.launch:
    <launch>
    <!-- declare arg to be passed in -->
    <arg name="hoge" />

    <!-- read value of arg -->
    <param name="param" value="$(arg hoge)"/>
    </launch>
  8. group: 将节点归组,方便统一处理,比如设置命名空间等;

  9. ns:设置命名空间,可以用在node, include,group中。

总结

launch文件在ros中使用非常频繁,语法琐碎且简单。使用时,建议直接从例程代码中直接修改,同时知道各个标签的含义,便于自己修改和定制化。

参考文献

  1. http://wiki.ros.org/roslaunch
  2. http://wiki.ros.org/roslaunch/Architecture
  3. http://wiki.ros.org/roslaunch/XML