赞
踩
我们知道ROS1个launch
文件是xml
格式的,ROS2在前面的文章中我们都是使用python
格式实现的,事实上ROS2也是支持xml
格式的,而且ROS2还支持yaml
格式,参考官方文档分别做了实现
直接可以参考之前的实现bringup_launch.py
对比ROS1 XML格式和ROS2 XML格式,可以看到有些许的不同点
我们直接实现后对比2个文件的差别(左边为ROS1的launch file,右边为ROS2的launch file)
可以看到ROS2不支持doc
,if
, 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
运行测试,命令与上面的基本一致
ros2 launch pibot_bringup bringup_launch.yaml baudrate:=921600 use_imu:=true
ros2 launch pibot_bringup bringup_launch.yaml use_imu:=false
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
会更复杂和冗长。后面我们将使用python
的launch
文件
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。