当前位置:网站首页>ROS 笔记(10)— launch 文件启动
ROS 笔记(10)— launch 文件启动
2022-06-29 14:38:00 【wohu1104】
1. 背景
一个程序中可能需要启动多个节点,比如:ROS 内置的小乌龟案例,如果要控制乌龟运动,要启动多个窗口,分别启动 roscore、乌龟界面节点、键盘控制节点。如果每次都调用 rosrun 逐一启动,显然效率低下,如何优化?
官方给出的优化策略是使用 launch 文件(通过 xml 文件实现多节点的配置和启动),可以一次性启动多个 ROS 节点,并且可以自动启动 ROS Master。
2. 实现
2.1 创建功能包
$ catkin_create_pkg launch
Created file launch/package.xml
Created file launch/CMakeLists.txt
Successfully created files in /home/wohu/project/ros/ros_demo/src/launch. Please adjust the values in package.xml.
2.2 添加 launch 文件

launch.yaml 文件内容
<launch>
<node pkg="turtlesim" type="turtlesim_node" name="t1"/>
<node pkg="turtlesim" type="turtle_teleop_key" name="key1" />
</launch>
2.3 运行
$ roslaunch launch launch.yaml
... logging to /home/wohu/.ros/log/e021148a-f125-11ec-92ca-00e070ce7d11/roslaunch-wohu-pc-17490.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://wohu-pc:35733/
SUMMARY
========
PARAMETERS
* /rosdistro: melodic
* /rosversion: 1.14.13
NODES
/
key1 (turtlesim/turtle_teleop_key)
t1 (turtlesim/turtlesim_node)
auto-starting new master
process[master]: started with pid [17500]
ROS_MASTER_URI=http://localhost:11311
setting /run_id to e021148a-f125-11ec-92ca-00e070ce7d11
process[rosout-1]: started with pid [17512]
started core service [/rosout]
process[t1-2]: started with pid [17516]
process[key1-3]: started with pid [17520]
3. launch 文件语法

3.1 launch 标签
<launch> 标签是所有 launch 文件的根标签,充当其他标签的容器,所有其它标签都是 launch 的子级。
3.2 node 标签
<node> 标签用于指定 ROS 节点,是最常见的标签,需要注意的是: roslaunch 命令不能保证按照 node 的声明顺序来启动节点(节点的启动是多进程的)。
属性如下:
pkg=“包名”
节点所属的包
type=“nodeType”
节点类型(与之相同名称的可执行文件)
name=“nodeName”
节点名称(在 ROS 网络拓扑中节点的名称)
args=“xxx xxx xxx” (可选)
将参数传递给节点
machine=“机器名”
在指定机器上启动节点
respawn=“true | false” (可选)
如果节点退出,是否自动重启
respawn_delay=" N" (可选)
如果 respawn 为 true, 那么延迟 N 秒后启动节点
required=“true | false” (可选)
该节点是否必须,如果为 true,那么如果该节点退出,将杀死整个 roslaunch
ns=“xxx” (可选)
在指定命名空间 xxx 中启动节点
clear_params=“true | false” (可选)
在启动前,删除节点的私有空间的所有参数
output=“log | screen” (可选)
日志发送目标,可以设置为 log 日志文件,或 screen 屏幕,默认是 log
子级标签
env 环境变量设置
remap 重映射节点名称
rosparam 参数设置
param 参数设置
3.3 include 标签

include 标签用于将另一个 xml 格式的 launch 文件导入到当前文件
属性
file=“$(find 包名)/xxx/xxx.launch”
要包含的文件路径
ns=“xxx” (可选)
在指定命名空间导入文件
子级标签
env 环境变量设置
arg 将参数传递给被包含的文件
3.4 remap 标签

用于话题重命名
from=“xxx”
原始话题名称to=“yyy”
目标名称

3.5 param 标签

<param> 标签主要用于在参数服务器上设置参数,参数源可以在标签中通过 value 指定,也可以通过外部文件加载,在 <node> 标签中时,相当于私有命名空间。
属性
name=“命名空间/参数名”
参数名称,可以包含命名空间
value=“xxx” (可选)
定义参数值,如果此处省略,必须指定外部文件作为参数源
type=“str | int | double | bool | yaml” (可选)
指定参数类型,如果未指定,roslaunch 会尝试确定参数类型,规则如下:
如果包含 ‘.’ 的数字解析未浮点型,否则为整型
“true” 和 “false” 是 bool 值(不区分大小写)
其他是字符串

3.6 rosparam 标签
<rosparam> 标签可以从YAML 文件导入参数,或将参数导出到 YAML 文件,也可以用来删除参数,<rosparam> 标签在 <node> 标签中时被视为私有。
属性
command=“load | dump | delete” (可选,默认 load)
加载、导出或删除参数
file=“$(find xxxxx)/xxx/yyy…”
加载或导出到的 yaml 文件
param=“参数名称”
ns=“命名空间” (可选)
3.7 group 标签
<group> 标签可以对节点分组,具有 ns 属性,可以让节点归属某个命名空间
属性
ns=“名称空间” (可选)
clear_params=“true | false” (可选)
启动前,是否删除组名称空间的所有参数(慎用…此功能危险)
子级标签
除了launch 标签外的其他标签
3.8 arg 标签

<arg> 标签是用于动态传参,类似于函数的参数,可以增强 launch 文件的灵活性。
属性
name=“参数名称”
default=“默认值” (可选)
value=“数值” (可选)
不可以与 default 并存
doc=“描述”
参数说明
示例:
- launch文件传参语法实现,hello.lcaunch
<launch>
<arg name="xxx" />
<param name="param" value="$(arg xxx)" />
</launch>
- 命令行调用launch传参
roslaunch hello.launch xxx:=值
边栏推荐
- 仿头条新闻资讯dz模板 Discuz新闻资讯商业版GBK模板源码
- Differences between @resource and @autowired annotations automatically injected:
- Weigao blood purification sprint to Hong Kong: annual revenue of RMB 2.9 billion, net profit decreased by 12.7%
- 《canvas》之第6章 图片操作
- 精品商城拼团秒杀优惠折扣全功能完美双端自适应对接个人免签网站源码
- 校园跑腿微信小程序跑腿同学带直播新版源码
- Build your own website (19)
- Class template case - array class encapsulation
- 建立自己的网站(19)
- Redis installation in windows and Linux Environment
猜你喜欢

Imitation headline news information DZ template discuz news information business version GBK template source code

Source code of campus secondary market

云上第一课 | 建个小破站有多简单?云计算老司机带你一小时搞定

MySQL 数据库 - 通用语法 DDL DML DQL DCL

Deploy redis sentry in k8s

FIFO implementation with single port RAM

精品商城拼团秒杀优惠折扣全功能完美双端自适应对接个人免签网站源码

Build your own website (19)

Query function of Excel vlookup

EXCEL的查询功能Vlookup
随机推荐
ModStartBlog 现代化个人博客系统 v5.2.0 主题开发增强,新增联系方式
Kubernetes pod troubleshooting guide
Thanos store component
Methods of accessing external services in istio grid
JS will have variable promotion and function promotion
华理生物冲刺科创板:年营收2.26亿 拟募资8亿
Whitelabel Error Page访问
I log in to the RDB database and prompt that the master account authorization is required. How do I know who to call?
Chapter 14 of canvas physical animation
You need to know about project procurement management
Is 100W data table faster than 1000W data table query in MySQL?
类模板案例-【数组类封装】
How bad can a programmer be?
Laravel - Composer 安装指定 Laravel 版本
高并发软件(网站,服务器端接口)的评价指标
Asynchronous artifact completable future
墨滴排版
If I am in Foshan, where can I open an account? Is it safe to open an account online?
中国软冰淇淋市场预测与投资前景研究报告(2022版)
June 27 talk SofiE