NXP iMX8基于Ycoto Project編譯ROS2
By Toradex秦海
1). 簡介
基于類似NXP iMX8這樣性能強勁的ARM平臺處理器,越來越多的工業(yè)智能/機器人應用比如AGV/AMR產(chǎn)品控制器在ARM平臺上面實現(xiàn),在這個過程中不可避免的就涉及到將機器人應用開發(fā)框架移植到ARM平臺來運行,因此本文就著重示例基于Ycoto Project/Openembedded環(huán)境,將ROS(Robot Operating System)編譯集成到嵌入式Linux中運行。
ROS是一種為機器人應用設(shè)計的分布式處理框架,集成了大量相關(guān)庫和工具,目的是為了提高機器人應用開發(fā)時代碼復用率, 目前ROS已經(jīng)發(fā)展到ROS2,這里就演示將ROS2最新版本Foxy集成到iMX8 Linux BSP中。
本文的演示的平臺來自于Toradex Apalis iMX8 ARM嵌入式平臺,這是一個基于NXP iMX8QM ARM處理器,支持Cortex-A72+A53和Coretex-M4架構(gòu)的計算機模塊平臺。
2). 準備
a). Apalis iMX8QM 4GB WB IT ARM核心版配合Ioxra 載板,連接調(diào)試串口UART1(載板X22)到開發(fā)主機方便調(diào)試。
3). Apalis iMX8 Ycoto Linux 集成ROS2編譯環(huán)境配置和部署
a). Apalis iMX8 Ycoto Linux 通過Ycoto/Openembedded 框架編譯,具體的配置方法請參考這里,首先下載好針對Apalis iMX8適用的基于Ycoto Dunfeil版本的BSP 5.x.y編譯環(huán)境。
----------------------------------
$ repo init -u https://git.toradex.com/toradex-manifest.git -b dunfell-5.x.y -m tdxref/default.xml
$ repo sync
----------------------------------
b). 下載meta-ros 和meta-python2 layer到上面下載好的ycoto環(huán)境
----------------------------------
$ cd …/oe-core/layers/
### fetch meta-ros layer
$ git clone -b dunfell https://github.com/ros/meta-ros.git
### fetch meta-phthon2 layer
$ git clone -b dunfell https://github.com/YoeDistro/meta-python2.git
----------------------------------
c). 配置編譯環(huán)境,添加編譯ROS2 Foxy版本需要的相關(guān)layer,由于目前ycoto 編譯ROS還無法支持圖形界面相關(guān),因此也要在編譯環(huán)境中將相關(guān)的package排除出去。
./ 添加環(huán)境變量
----------------------------------
### generate init env
$ cd …/oe-core/
$ source export
### add new env
$ export ROS_OE_RELEASE_SERIES="dunfell"
### make new env valid with bitbake
$ export BB_ENV_EXTRAWHITE="$BB_ENV_EXTRAWHITE ROS_OE_RELEASE_SERIES"
----------------------------------
./ 修改 build/conf/bblayers.conf 文件
----------------------------------
${TOPDIR}/../layers/meta-freescale-distro \
${TOPDIR}/../layers/meta-toradex-demos \
${TOPDIR}/../layers/meta-qt5 \
+ ${TOPDIR}/../layers/meta-python2 \
+ ${TOPDIR}/../layers/meta-ros/meta-ros2-foxy \
+ ${TOPDIR}/../layers/meta-ros/meta-ros2 \
+ ${TOPDIR}/../layers/meta-ros/meta-ros-common \
+ ${TOPDIR}/../layers/meta-ros/meta-ros-backports-gatesgarth \
\
\
${TOPDIR}/../layers/meta-toradex-distro \
----------------------------------
./ 修改 build/conf/local.conf 文件
----------------------------------
### modify machine setting to apalis imx8
MACHINE ?= "apalis-imx8"
### add ros-core only or ros-world packagegroup for all ros2-foxy packages
IMAGE_INSTALL_append = " packagegroup-ros-world"
### blacklist below packages which currently not supported in ycoto compilation
### detailed impact package refer to \ /layers/meta-ros/meta-ros2-foxy/conf/ros-distro/include/foxy/ros-distro-recipe-blacklist.inc and \ layers/meta-ros/meta-ros2-foxy/recipes-core/packagegroups/packagegroup-ros-world-foxy.bb files
ROS_WORLD_SKIP_GROUPS = " opengl qt5 qt5-widgets pyqt5 qt-gui-cpp x11 ffmpeg webots-python-modules java libomp connext gazebo coinor-libipopt gurumdds ignition doosan-robot2 clang launch pugixml lanelet2-traffic-rules mongodb kobuki-ftdi ros1"
### define package graphviz version
PREFERRED_VERSION_graphviz = "2.40.1%"
### accept freescale EULA license
ACCEPT_FSL_EULA = "1"
----------------------------------
./ 修改 layers/meta-ros/meta-ros2-foxy/recipes-bbappends/osqp-vendor/osqp-vendor_0.0.2-1.bbappend 文件修復當前版本中的bug
----------------------------------
-SRCREV_osqp = "c536acf012d071eed3529e0147afdd419348362a"
+SRCREV_osqp = "36ad83aed022e714c2fda1f13138443150435994"
SRCREV_qdldl = "12d56ee6b9494efee1da1e1dc6e7ac9c226f9ccf"
----------------------------------
d). 編譯image和SDK
-------------------------------
# compile Reference-Minimal image
$ bitbake bitbake tdx-reference-minimal-image
# compile Reference-Multimedia image
$ bitbake bitbake tdx-reference-multimedia-image
# compile SDK
bitbake tdx-reference-multimedia-image -c populate_sdk
-------------------------------
e). Ycoto Linux image部署
參考這里通過Toradex Easy installer將上面編譯好的image更新部署到模塊,目前最新季度發(fā)布版本為Ycoto Linux V5.2,這里使用Reference-Minimal BSP image進行測試
4). ROS2 Foxy測試
a). 修改ROS初始化相關(guān)腳本權(quán)限,增加執(zhí)行權(quán)限
-------------------------------
root@apalis-imx8:~# chmod +x /etc/profile.d/ros/*
root@apalis-imx8:~# ls -al /etc/profile.d/ros/setup.sh
-rwxr-xr-x 1 root root 4372 Mar 9 2018 /etc/profile.d/ros/setup.sh
-------------------------------
b). 通過下面命令進行ROS2 Foxy簡單測試
-------------------------------
### check network connection
root@apalis-imx8:~# ping lge.com
### source setup script to export env
root@apalis-imx8:~# source /usr/bin/ros_setup.sh
### ros topic print
root@apalis-imx8:~# ros2 topic list
/parameter_events
/rosout
### ros interface print
root@apalis-imx8:~# ros2 interface list -m
……
### test
root@apalis-imx8:~# (sleep 5; ros2 topic pub /chatter std_msgs/String "data: Hello world") &
[1] 826
root@apalis-imx8:~# ros2 topic echo /chatter
publisher: beginning loop
publishing #1: std_msgs.msg.String(data='Hello world')
publishing #2: std_msgs.msg.String(data='Hello world')
publishing #3: std_msgs.msg.String(data='Hello world')
publishing #4: std_msgs.msg.String(data='Hello world')
data: Hello world
---
publishing #5: std_msgs.msg.String(data='Hello world')
data: Hello world
……
-------------------------------
5). 總結(jié)
本文基于NXP iMX8嵌入式平臺演示了通過Ycoto Project/Openembedded框架將ROS2 Foxy集成到嵌入式Linux BSP中,目前meta-ros layer除了Foxy,還支持ROS1 melodic,ROS1 noetic,ROS2 dashing,ROS2 eloquent,其他ROS版本可以自行根據(jù)所需要的layer不同而適應修改后編譯。
參考文獻
https://github.com/ros/meta-ros/wiki/OpenEmbedded-Build-Instructions
https://developer.toradex.cn/knowledge-base/board-support-package/openembedded-core
*博客內(nèi)容為網(wǎng)友個人發(fā)布,僅代表博主個人觀點,如有侵權(quán)請聯(lián)系工作人員刪除。