launch启动文件使用方法

发布时间 2023-08-02 11:05:53作者: 穿着校服浪天下

launch文件结构

  • 通过XML文件实现多节点的配置和启动
  • 可自动启动ROS Master
  • 不再需要打开多个终端用多个rosrun命令来启动不同的节点

launch文件语法

  • <launch>

launch文件中的根元素采用<launch>标签定义

  • <node>

启动节点<node pkg="package-name" type="executable-name" name="node-name" />
pkg:节点所在的功能包名称
type:节点的可执行文件名称
name:节点运行时的名称
output、respawn、required、ns、args

参数设置

  • <param>/<rosparam>

设置ROS系统运行中的参数,存储在参数服务器中。
<param name="output_frame" value="odom"/>
name:参数名
value:参数值
加载参数文件中的多个参数:
<rosparam file="params.yaml" command="load" ns="params" />

  • <arg>

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) /">

重映射

  • <remap>
    重映射ROS计算图资源的命名。
    <remap from="\turtlebot/cmd_vel" to="/cmd_vel" />

from:原命名
to:映射之后的命名

嵌套

  • <include>
    包含其他launch文件,类似C语言头文件包含
    <include file="$(dirname)"/other.launch" />
    file:包含的其他launch文件路径
    更多标签可参见:http://wiki.ros.org/roslaunch/XML

可以在功能包中创建一个launch文件夹来管理launch文件
catkin_make
cd /src
roslaunch {路径} qwq.launch