roslaunch文件的本质是xml文件,首先要简单了解一些xml相关语法:
1、标签必须闭合
<launch> launch> //成对的标签闭合,中间可以写内容
<node XXXX /> //当没有中间内容需要写时,也可使用自闭合标签,此时仍然可以为标签添加属性,XXXX内容就代表属性部分
2、使用注释
——————————————常用———————————-
对参数服务器进行参数设置
"base_controller" pkg="base_controller" type = "base_controller" >
name是给这个节点起的名字,pkg是工作空间中节点包的名称,type是包中需要运行的具体节点,其指向的文件必须有对应的可执行文件。
<include file="$(find rbx1_nav)/launch/gmapping.launch"/>
"laser_scan" pkg="laser_scan_publisher_tutorial" type = "laser_scan_publisher">
"scan" value = "laser" />
laser_scan_publisher这个节点程序设置了一个可让用户更改的参数,为了传递这个参数,使用标签,name是参数在程序内部的名称,value是给对应参数赋值。
"turtlebot_teleop" type="turtlebot_teleop_key" name="turtlebot_teleop_keyboard" output="screen">
"scale_linear" value="0.1" type="double"/>
"scale_angular" value="0.4" type="double"/>
"turtlebot_teleop_keyboard/cmd_vel" to="cmd_vel" />
上述代码启动了一个turtlebot_teleop节点,该节点原本发布了一个消息叫做turtlebot_teleop_keyboard/cmd_vel, 其实这个话题与cmd_vel话题中的消息类型是完全一样的,因为能够发送cmd_vel话题的节点太多了,为了区分,程序设计时使用了节点名称+话题名的方式,此时为了方便订阅,需要将这种话题做一次重映射,使用
"move_base" type="move_base" respawn="false" name="move_base" output="screen" clear_params="true">
file="$(find rbx1_nav)/config/fake/costmap_common_params.yaml" command="load" ns="global_costmap" />
file="$(find rbx1_nav)/config/fake/costmap_common_params.yaml" command="load" ns="local_costmap" />
file="$(find rbx1_nav)/config/fake/local_costmap_params.yaml" command="load" />
file="$(find rbx1_nav)/config/fake/global_costmap_params.yaml" command="load" />
file="$(find rbx1_nav)/config/fake/base_local_planner_params.yaml" command="load" />
当参数特别多时,全部写在launch文件里就不方便了,为此,可以通过加载文件来传递参数,上述代码从4个文件加载了参数,其中costmap_common_params.yaml文件中的参数值被传递到两个不同的命名空间中。
比如,gmapping.launch中有这样一句:
<launch>
<arg name="scan_topic" default="scan" />
…………
launch>
其中,scan_topic这个参数就是说,使用roslaunch启动这个launch文件时,可以传递一个参数,该参数可以让用户指定一个话题名称,如果用户传递了话题参数,则新的话题参数将取代scan,若果没传递参数,scan_topic取默认值scan,你可以这样写:
roslaunch ~/文件路径/gmapping.launch scan_topic:=abc
此时,
from="scan" to="$(arg scan_topic)"/>
上述代码是gmapping.launch中的语句,若用户传递了自定义的参数,则scan会被映射为指定的话题名称,使得gmapping接收的激光话题名称为用户指定的名称。
启动节点多了可以分分组,不同组可以使用不同的命名空间,使得节点参数不冲突。该标签套在
属性是写在标签里的,比如
"base_controller" pkg="base_controller" type = "base_controller">
pkg =“mypackage” 是catkin空间中节点的名称。
type =“nodetype” 节点下的程序名称,必须有一个具有相同名称相应的可执行文件,catkin编译后可自动产生该可执行文件。
name =“nodename” 用户给该节点起的名称。
respawn =“true” 如果节点退出,则自动重新启动节点。
output=“screen”; 将对应node的输出信息打印在屏幕上,如果不写这一句,所有程序中的输出将存在home/.ros/log目录下。
若想显示所有nodes的输出,启动launch文件时还可以添加–screen参数
`roslaunch --screen package_name launch_file_name //此时所有输出会显示在终端