ROS1/Linux——Launch文件使用
ROS1/Linux——Launch文件使用
文章目录
- ROS1/Linux——Launch文件使用
- 参考链接
- 优势
- 文件基本格式
- 基本语法
- node 节点
- param/rosparam/arg 参数设置
- remap 重映射
- include 嵌套
参考链接
- 标签参考链接:ROS官网
- 学习资料参考链接:【古月居】ROS入门
优势
- 不用通过手动启动 roscore
- 可以一次性启动多个需要启动的节点
- 可以嵌套
文件基本格式
- 保存格式:文件名.launch
- 文件内部格式
<launch><xxxxxx/> <!-- 这里塞各种东西 --><!-- 示例 --><param name="/turtle_number" value="2"/><node pkg="turtlesim" name="sim1" type="turtlesim_node"/> <node pkg="turtlesim" name="sim2" type="turtlesim_node"><param name="turtle_name1" value="a"/><param name="turtle_name2" value="b"/></node> <!-- 示例 -->
</launch>
基本语法
node 节点
<node pkg="turtlesim" name="sim1" type="turtlesim_node"/>
<!--
pkg: 节点所在的功能包名字
type: 节点的可执行文件
name: 节点运行时的文件(代替程序中初始化的原始节点名,便于启动多个)
output: 日志信息是否打印到终端(output="screen",打印到终端)
respawn: 如果突然挂了,是否要重新启动(respawn="true",该节点停止时,会自动重启,默认为false)
required: 是否一定需要启动(required="true",必要节点,当该节点终止时,launch文件中的其他节点也被终止。)
ns: 命名空间(避免命名冲突)
args: 给节点输入参数-->
param/rosparam/arg 参数设置
<!-- 把某个参数存储在参数服务器中 -->
<param name="output_frame" value="odom"/>
<!-- name: 参数名value: 参数值--><!-- 加载参数文件中的多个参数 -->
<rosparam file="params.yaml" command="load" ns="params"/><!-- 加载launch文件内部的变量,仅限于launch文件内使用 -->
<arg name="arg-name" value="arg-value"/>
<!-- name: 参数名value: 参数值-->
<!-- 调用arg -->
<param name="foo" value="$(arg arg-name)"/>
<node pkg="turtlesim" name="sim1" type="turtlesim_node" args="$(arg arg-name)"/>
remap 重映射
重映射ROS计算图资源的命名
<remap from="/turtlebot/cmd_vel" to="/cmd_vel"/>
<!-- 换完名字后,原始名字在计算图中将不存在from: 原命名to: 映射后的命名-->
include 嵌套
包含其他launch文件
<include file="$(dirname)/other.launch" depends="base.launch"/>
<!-- file: 其他launch文件的路径depends: 依赖某个launch文件(按序启动)$(dirname): 当前launch文件所在的文件夹$(find dirname): 找到名字为dirname的文件夹(一般是功能包名)-->