ROS launch文件的作用和编写

来源:互联网 发布:sql视图是什么 编辑:程序博客网 时间:2024/04/26 00:34

launch文件功能

使用launch file, 可以同时启动多个ros节点,包括ROS-master. 所以这样只要一个roslaunch,就可以启动 roscore和多个节点程序。

如何启动launch 文件

roslaunch package-name launch-file-name

如何创建launch 文件

  1. 首先要有一个存放launch 文件的地方

    • .launch 文件可以放在 功能包的根目录下
    • .launch 文件也可以放在功能包下单独的launch文件夹下
  2. launch文件的基本编写结构

    • 根元素中间包含了若干个节点元素
    • 每个节点元素中包含了其相应的节点属性信息

根元素 -launch文件的头和尾
 <launch>
……
</launch>

节点元素 – 每个node的头和尾
<node
pkg=”turtlesim”     //功能包名
type=”turtlesim_node”   //节点名
name=”turtle1”    //节点重命名  这三个是必须属性
/>

可选属性
respawn=”true”  //自动重启
required=”true”  //必要节点,这个出问题了,整个launch结束
output=”screen”  //输出打印信息
launch-prefix=”xterm -e” //单独维护一个窗口 比如要输入或者单独查看日志信息
ns=”name-space” //定义命名空间,同一命名空间下节点的话题才能通信
【区别于上面的name  name只是重命名了节点,话题没变;而ns重定义了空间,话题变了】
<remap from="original-name" to "new-name"> //话题重映射
1.写一个新节点 订阅original,修改,重新发布new
2.然后把原来订阅这个话题的节点的程序重映射一下

组元素 若干节点放在同一个组内
<group ns="name-space">
……
</group>

group可以设置一些规则
<group if="$arg arg-name"> //可以通过这个参数的值,决定执行这个组,还是不执行这个组 【1执行   0忽略】
<group unless="$arg arg-name"> //可以通过这个参数的值,决定执行这个组,还是不执行这个组 【0执行   1忽略】

其他元素

_在各节点文件之上,的一些操作

<arg name="art-name" />    //参数声明<arg name="fcu_url" default="/dev/ttyACM0:57600" />  //参数赋值(也可以在 启动launch时赋值, arg-name:="arg-value")<include file="$(find mavros)/launch/node.launch"> //在这个launch文件中启动其他的launch文件,(包括节点和参数)

一个简单launch文件的例子

<launch><nodepkg="turtlesim"type="turtlesim_node"name="turtle1"/><nodepkg="turtlesim"type="turtlesim_node"name="turtle2"/><nodepkg="turtlesim"type="turtlesim_node"name="turtle3"/><nodepkg="hello_ros"type="circle_pub"name="circle"respawn="true"/><nodepkg="hello_ros"type="pose_sub"name="pose_sub"respawn="true"launch-prefix="xterm -e"/></launch>