PIBOT移植ROS2记录(8)-launch文件的三种格式

1. launch文件格式

我们知道ROS1个launch文件是xml格式的,ROS2在前面的文章中我们都是使用python格式实现的,事实上ROS2也是支持xml格式的,而且ROS2还支持yaml格式,参考官方文档分别做了实现

1.1 python格式

直接可以参考之前的实现bringup_launch.py

1.2 xml格式

实现:bringup_launch.xml

对比ROS1 XML格式ROS2 XML格式,可以看到有些许的不同点

我们直接实现后对比2个文件的差别(左边为ROS1的launch file,右边为ROS2的launch file)
ROS1 VS ROS2

可以看到ROS2不支持docif, rosparam,同时arg改为var, type改为exec,但总体上差别不大,熟悉ROS1的可以很快的修改过来。

想要查看全部的差别,可以直接访问官方文档

我们可以直接输入下面命令测试

ros2 launch  pibot_bringup bringup_launch.xml baudrate:=921600 use_imu:=true
ros2 launch  pibot_bringup bringup_launch.xml use_imu:=false

1.3 yaml格式

实现:bringup_launch.yaml

运行测试,命令与上面的基本一致

ros2 launch  pibot_bringup bringup_launch.yaml baudrate:=921600 use_imu:=true
ros2 launch  pibot_bringup bringup_launch.yaml use_imu:=false

2. Python、XML or YAML

ROS2支持三种格式,具体应该使用哪个,官方也给出了说明


For most applications the choice of which ROS 2 launch format comes down to developer preference. However, if your launch file requires flexibility that you cannot achieve with XML or YAML, you can use Python to write your launch file. Using Python for ROS 2 launch is more flexible because of following two reasons:

Python is a scripting language, and thus you can leverage the language and its libraries in your launch files.

ros2/launch (general launch features) and ros2/launch_ros (ROS 2 specific launch features) are written in Python and thus you have lower level access to launch features that may not exposed by XML and YAML.


即具体看自己喜好,但使用python更灵活,而使用python会更复杂和冗长。后面我们将使用pythonlaunch文件

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值