Launch文件:通过xml文件实现多节点的配置和启动(可自动启动ROS Master)。
一、 基本语法:
1、<launch>:launch文件中的根元素采用<launch>标签定义。
2、<node>:启动节点。语法:<node pkg="package-name" type="executable-name" name="node-name" />
(1)pkg:节点所在的功能包的名称。
(2)type:节点的可执行文件名称。
(3)name:节点运行时的名称。自己命名,在运行时会替代可执行文件的名称。
(4)其他参数:output、respawn、required、ns、args等。
3、参数设置:
(1)设置ROS系统运行中的参数,存储在参数服务器中。
如:<param name="output_frame" value="odom" />,其中name表示参数名,value表示参数值。
加载参数文件中的多个参数,可使用:<rosparam file="params.yaml" command="load" ns="params"/> 其中file表示参数文件的路径,command表示对参数文件执行的操作,ns表示将加载的参数放置到这个命名空间下。
(2)launch文件内部的局部变量,仅限于launch文件使用。
如:<arg name="arg-name" default="arg-value" />,其中name表示参数名,value表示参数值。局部变量的调用:<param name="foo" value="$(arg arg-name)" /> 或者 <node name="node" pkg="package" type="type" args="$(arg arg-name)" />
(3)重映射ROS计算图资源的命名。
如:<remap from="/turtlebot/cmd_vel" to="/cmd_vel" />,其中from是原命名,to是重映射之后的命名。
(4)包含其他launch文件,类似C/C++语言中的头文件包含
如:<include file="$(dirname)/other.launch" />,其中file表示包含其他launch文件的路径。
使用roslaunch <功能包名> <launch文件名> 来启动launch文件。launch文件的示例: