1. launch文件格式
我們知道ROS1個(gè)launch
文件是xml
格式的喊式,ROS2在前面的文章中我們都是使用python
格式實(shí)現(xiàn)的姨俩,事實(shí)上ROS2也是支持xml
格式的芦昔,而且ROS2還支持yaml
格式,參考官方文檔分別做了實(shí)現(xiàn)
1.1 python格式
直接可以參考之前的實(shí)現(xiàn)bringup_launch.py
1.2 xml格式
實(shí)現(xiàn):bringup_launch.xml
對(duì)比ROS1 XML格式和ROS2 XML格式账嚎,可以看到有些許的不同點(diǎn)
我們直接實(shí)現(xiàn)后對(duì)比2個(gè)文件的差別(左邊為ROS1的launch file克滴,右邊為ROS2的launch file)
[圖片上傳失敗...(image-1f99c7-1677593803194)]
可以看到ROS2不支持doc
泊窘,if
, rosparam
,同時(shí)arg
改為var
, type
改為exec
,但總體上差別不大熄驼,熟悉ROS1的可以很快的修改過(guò)來(lái)。
想要查看全部的差別烘豹,可以直接訪問(wèn)官方文檔
我們可以直接輸入下面命令測(cè)試
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格式
實(shí)現(xiàn):bringup_launch.yaml
運(yùn)行測(cè)試,命令與上面的基本一致
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支持三種格式,具體應(yīng)該使用哪個(gè)吴叶,官方也給出了說(shuō)明
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
會(huì)更復(fù)雜和冗長(zhǎng)蚌卤。后面我們將使用python
的launch
文件