By Toradex秦海

1). 简介

基于类似NXP iMX8这样性能强劲的ARM平台处理器,越来越多的工业智能/机器人应用比如AGV/AMR产品控制器在ARM平台上面实现,在这个过程中不可避免的就涉及到将机器人应用开发框架移植到ARM平台来运行,因此本文就着重示例基于Ycoto Project/Openembedded环境,将ROS(Robot Operating System)编译集成到嵌入式Linux中运行。

ROS是一种为机器人应用设计的分布式处理框架,集成了大量相关库和工具,目的是为了提高机器人应用开发时代码复用率, 目前ROS已经发展到ROS2,这里就演示将ROS2最新版本Foxy集成到iMX8 Linux BSP中。

 

本文的演示的平台来自于Toradex Apalis iMX8 ARM嵌入式平台,这是一个基于NXP iMX8QM ARM处理器,支持Cortex-A72+A53和Coretex-M4架构的计算机模块平台。

 

 

2). 准备

a). Apalis iMX8QM 4GB WB IT ARM核心版配合Ioxra 载板,连接调试串口UART1(载板X22)到开发主机方便调试。

 

 

3). Apalis iMX8 Ycoto Linux 集成ROS2编译环境配置和部署

a). Apalis iMX8 Ycoto Linux 通过Ycoto/Openembedded 框架编译,具体的配置方法请参考这里,首先下载好针对Apalis iMX8适用的基于Ycoto Dunfeil版本的BSP 5.x.y编译环境。

----------------------------------

$ 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环境

----------------------------------

$ 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). 配置编译环境,添加编译ROS2 Foxy版本需要的相关layer,由于目前ycoto 编译ROS还无法支持图形界面相关,因此也要在编译环境中将相关的package排除出去。

./ 添加环境变量

----------------------------------

### 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更新部署到模块,目前最新季度发布版本为Ycoto Linux V5.2,这里使用Reference-Minimal BSP image进行测试

 

 

4). ROS2 Foxy测试

a). 修改ROS初始化相关脚本权限,增加执行权限

-------------------------------

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). 总结

本文基于NXP iMX8嵌入式平台演示了通过Ycoto Project/Openembedded框架将ROS2 Foxy集成到嵌入式Linux BSP中,目前meta-ros layer除了Foxy,还支持ROS1 melodic,ROS1 noetic,ROS2 dashing,ROS2 eloquent,其他ROS版本可以自行根据所需要的layer不同而适应修改后编译。

 

参考文献

https://github.com/ros/meta-ros/wiki/OpenEmbedded-Build-Instructions

https://developer.toradex.cn/knowledge-base/board-support-package/openembedded-core