ROS进阶学习手记6.1 -- Launch File


在以后的ROS运用中,我们逐渐需要运行多个nodes,而launch file的编写是ROS高级运用的基础。

官方的launch file wiki文档好像不是很好用:wiki.ros.org/roslaunch/

这里我主要参考:A Gentle Introduction to ROS by JasonM. O’Kane  的 Chapter6

先来尝尝鲜:
   

接着就是好好读书。

这里只会写一点总结文字。 :)


== roslaunch - Commands and launch file ==

1. How to usd launch file:

  Command:

    $ roslaunch package-name launch-file-name

    $ roslaunch ~/{workspace}/src/{pkgname}/example.launch


  All of the nodes in a launch file are started at roughly the same time.

  Request verbose output:

    $ roslaunch -v package-name launch-file-name


2. Creating launch files:

  2.1 Where to place launch files

    {pkg directory}/launch/launchfile.launch

  2.2 Basic ingredients

    The simplest launch files consist of a root element containing several node elements.

    <launch>
      <node pkg="package-name" type="executable-name" name="node-name" />
    </launch>

    You can also also write the closing tag explicitly:

      <node pkg="..." type="... " name="... "></node>

    In fact, this explicit closing tag is needed if the node has children, such as remap or
paramelements.

    pkg 和 type 两个属性指定了ROS应该运行哪个程序来启动这个节点。相当于两行rosrun命令,一行指定pkg name,一行指定excutabel name。
    name 属性给这个node分配了一个名称。它会覆盖node代码中ros::init段给自己分配的那个name.
    看下面这个例子:

      <node
        pkg="turtlesim"
        type="turtle_teleop_key"
        name="teleop_key "
        required="true "
        launch −prefix="xterm −e"
        ns="sim1 "
      />    

默认下,$ROS_HOME/log会存储roslaunch运行后的log文件。通过output="log|screen"(optional) 来改。

    roslaunch --screen package-name launch-file-name

   output="screen" or "log"

   Requesting respawning:   respawn="true"
   Requiring nodes:              required="true"
   Launching nodes in their own windows:

     launch-prefix="command-prefix"
     launch-prefix="xterm -e"
     xterm -e rosrun turtlesim turtle_teleop_key


   node标签还有一些属性,也非常有用. 更多请见:
   http://wiki.ros.org/roslaunch/XML/node#Attributes
   

   2.3 Launching nodes inside a namespace

   ROS supports relative names, which utilize the concept of a default namespace. The usual way to set the default namespace for a node—a process often called pushing down into a namespace—is to use a launch file, and assign the ns attribute in its node element:
   ns="namespace"

   e.g.
   ---------------------------------

   <launch>
   <node
      name="turtlesim_node"
      pkg="turtlesim"
      type="turtlesim_node"
      ns="sim1"
   />
   <node
      pkg="turtlesim"
      type="turtle_teleop_key"
      name="teleop_key"
      required="true"
      launch−prefix="xterm−e"
      ns="sim1"
   />
   <node
      name="turtlesim_node"
      pkg="turtlesim"
      type="turtlesim_node"
      ns="sim2"
   />
   <node
      pkg="agitr"
      type="pubvel"
      name="velocity_publisher"
      ns="sim2"
   />
   </launch>

 ----------------------------
    In this case, both nodes have the same relative name, turtlesim_node. Such identical relative names
are not a problem, however, because the global names to which they are resolved, namely /sim1/turtlesim_node and /sim2/turtlesim_node, are different.

3. Remapping names

   任何node的名字都可以被重映射,当它在命令行中launched时。这是一个ROS的强大功能。它可以让你通过命令行在多种配置下,运行同样的node,而不冲突。还可以为private node prarmeter 提供 assignment. 这个可以让你区别复杂的名字(defer complex name assignments to the actual runtime loading of the system. )在系统运行期间。
   http://wiki.ros.org/Remapping%20Arguments
   

   3.1 Creating remappings

   There are two ways create remappings when starting a node.
     original-name:=new-name
   or:
     <remap from="original-name" to="new-name" />

   3.2 Reversing a turtle

   写一个broadcaster,收听cmd_vel,翻转,发布一个叫做cmd_vel_reversed的topic。然后让turtlesim_node remapping到cmd_vel_reversed上。
   

4. Other launch file elements

   我们以下面这个launch file为例,说几个Other launch file elements
   =========================

 1 <launch>
 2    <include
 3    file="$(findagitr)/doublesim.launch"
 4    />
 5    <arg
 6    name="use_sim3"
 7    default="0"
 8    />
 9
10    <groupns="sim3"if="$(arguse_sim3)">
11    <node
12    name="turtlesim_node"
13    pkg="turtlesim"
14    type="turtlesim_node"
15    />
16    <node
17    pkg="turtlesim"
18    type="turtle_teleop_key"
19    name="teleop_key"
20    required="true"
21    launch−prefix="xterm−e"
22    />
23    </group>
24</launch>


   =========================

   4.1 Including other files

   <include file="path-to-launch-file" />
   <include file="$(find package-name)/launch-file-name" />
   <include file=". . . " ns="namespace" />


   4.2 Launch arguments

   让launch files 是可以配置的, roslaunch命令支持launch arguments, 也叫做arguments or args.
   这有点像可执行文件的局部变量。好处是比如每次运行时,有些小地方的不同,通过使用一些arguments,你可以避开代码的重复。
   
   Declaring arguments
   To declare the existence of an argument, use an arg element:
     <arg name="arg-name" />

   Assigning argument values
   launch file里的argument必须要赋值,You can provide a value on the roslaunch command line:

      $ roslaunch package-name launch-file-name arg-name:=arg-value

   Alternatively, in your launchfile, using one of these two syntaxes:

      <arg name="arg-name" default="arg-value" />
      <arg name="arg-name" value="arg-value" />

   注意:argument values set by "value" cannot be changed.

   Accessing argument values
   Once an argument is declared and a value assigned to it, you can use its value using an arg substitution, like this:
      $(arg arg-name)
   
   Sending argument values to included launch files
     <include file="path-to-launch-file">
       <arg name="arg-name" value="arg-value"/>
       . . .
     </include>

   4.3 Creating groups

   One final launch file feature is the group element, which provides a convenient way to organize nodes in a large launch file.
   Groups can push several nodes into the same namespace.
     <group ns="namespace" />
      . . .
     </group>
   Every node within the group starts with the given default namespace.
   Group还可以加一些条件,使某些节点使能或使不能。更多详情请参见教材。。

总结

   这里我们看到通过launch file和 roslaunch 命令,如何实现 启动nodes, 加上复杂的配置。具体的内容参见教材。
   《A Gentle Introduction to ROS by JasonM. O’Kane》南卡罗来纳州立大学教授写的。免费pdf
 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值