coral 迁移_如何在Google Coral Edge TPU开发板上运行ROS 2 Foxy

本文详细介绍了如何在Google Coral Edge TPU开发板上安装和运行ROS 2 Foxy,包括交叉编译ROS 2、在板上设置环境、测试ROS 2系统等步骤。此外,还提到了如何利用Coral板的Edge TPU进行计算机视觉任务。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

coral 迁移

When I created a robot 15 years ago out of PVC tubes, acrylic plates, a very heavy laptop and my mother’s yoga mat, that was tasked with collecting brightly coloured balls but was more interested in plain white walls, I could have only dreamt of the Computer Vision possibilities crammed into affordable credit card sized boards available nowadays. Google’s Coral board is one of these, equipped with a Tensor Processing Unit (TPU) that is optimised to run modern deep neural networks very efficiently.

15年前,当我用PVC管,丙烯酸板,一台非常沉重的笔记本电脑和我母亲的瑜伽垫创建一个机器人时,他的任务是收集色彩鲜艳的球,但对纯白的墙壁更感兴趣,我只能梦想着如今,计算机视觉的可能性塞入了价格可承受的信用卡大小的板中。 Google的Coral板就是其中之一,它配备了Tensor处理单元(TPU),该单元经过优化可非常高效地运行现代深度神经网络。

In my previous post I described how we use the Odroid-XU4 as the main compute of our humanoid robots in our RoboCup team. This is another quite capable little board, able to run some deep(ish) neural networks at a reasonable frame rate and resolution (as we showed in our 2018 paper), but the complexity of the models it can handle is still very limited compared to the current state of the art in computer vision. That is why we have started experimenting with the Coral board, to give the perception system of our robots a big boost by using its Edge TPU.

在我以前的文章中,我描述了如何使用Odroid-XU4作为RoboCup团队中人形机器人的主要计算工具。 这是另一个功能强大的小板,能够以合理的帧速率和分辨率运行一些深度神经网络(如我们在2018年论文中所示 ),但是与之相比,它可以处理的模型的复杂性仍然非常有限计算机视觉的最新技术。 这就是为什么我们开始试验Coral板的原因,从而通过使用Edge TPU大大提高了我们机器人的感知系统。

The first step towards this was to get our middleware of choice running on the board: ROS 2. The second Long Term Support version of ROS 2, codenamed Foxy Fitzroy, has recently been released with a lot of improvements, so we decided to get that installed. Whereas with previous versions we were able to build the system directly on the board itself (although it needed a full night to complete), Foxy has become too big and the board runs out of memory when compiling the ROS 2 C++ client libraries. This meant we had to cross-compile the whole thing instead, for which luckily some tools are available, but this method does require some special steps. I will give a run through of those here so others can enjoy the combination of these platforms as well.

第一步是让我们选择的中间件在板上运行:ROS2。第二个长期支持版本的ROS 2(代号Foxy Fitzroy)最近发布了很多改进,因此我们决定让它已安装。 在以前的版本中,我们可以直接在开发板上直接构建系统(尽管需要整夜完成),而Foxy太大了,在编译ROS 2 C ++客户端库时,开发板的内存不足。 这意味着我们不得不交叉编译整个程序,幸运的是,可以使用它们进行编译,但是此方法确实需要一些特殊步骤。 我将在这里进行介绍,以便其他人也可以享受这些平台的组合。

准备好董事会 (Have your board ready)

I assume you have gone through the official getting-started guide and successfully flashed the board, have it connected to your local network and reachable from the machine you will do the cross-compilation on, and have initial access set up with the mendel development tool (mdt), being able to log into your board with mdt shell. Later on we want to use SSH without mdt, which should be possible by using the key that it created on first log in; try it out by running:

我假设您已经阅读了官方的入门指南,并成功地刷新了开发板,将其连接到本地网络并且可以从您要进行交叉编译的机器上访问,并且已经使用mendel开发工具设置了初始访问权限( mdt ) ,能够使用mdt shell登录您的主板。 稍后,我们希望使用不带mdt SSH,这应该可以通过使用第一次登录时创建的密钥来实现。 通过运行尝试一下:

$ ssh -i ~/.config/mdt/keys/mdt.key mendel@deft-llama.local

My board called itself deft-llama, replace that name with the name of yours throughout this article.

我的董事会自称为deft-llama ,在本文全文中用您的名字替换该名字。

安装工具 (Install tools)

We will use the ROS cross-compile tool to save us from having to set up a whole cross-compilation toolchain ourselves. It works by running the cross-compilation inside of a Docker container on top of the QEMU emulator. Not the most straightforward way… and not really the fastest either… but it makes the process relatively easy for us. Follow their instructions to install Docker (don’t miss the bit about the docker group!), and then install QEMU and the cross-compilation and other tools we will be using:

我们将使用ROS交叉编译工具来使我们免于自己设置整个交叉编译工具链的麻烦。 它通过在QEMU仿真器顶部的Docker容器内部运行交叉编译来工作。 这不是最直接的方法……也不是最快的方法……但是它使我们的工作相对容易。 按照他们的说明安装Docker ( 不要错过有关 docker 组的知识! ),然后安装QEMU和交叉编译以及我们将要使用的其他工具:

$ sudo apt install qemu-user-static python3-pip curl git rsync$ pip3 install ros_cross_compile vcstool

I’m assuming you use Ubuntu, if not then you should be familiar with finding and installing these packages on your flavour of Linux. Finally, make sure you have a few gigabytes of free disk space available to cater to the docker environment and compilation output that will be created.

我假设您使用Ubuntu,否则,您应该熟悉在Linux风格上查找和安装这些软件包的过程。 最后,确保您有几GB的可用磁盘空间可用于docker环境和将要创建的编译输出。

准备工作区 (Prepare workspace)

Next we have to fetch ROS 2’s source code, and prepare some other files that will be used to control and configure the cross-compilation process. Start with creating some main directories:

接下来,我们必须获取ROS 2的源代码,并准备其他一些文件,这些文件将用于控制和配置交叉编译过程。 首先创建一些主目录:

$ mkdir -p ros2-crosscompile/ws/src$ cd ros2-crosscompile$ mkdir custom-data

ROS 2’s codebase is distributed over a whole bunch of Git repositories. We have to fetch a file with a list of them and their tags to use, and then use vcstool to clone them all in one go:

ROS 2的代码库分布在一大堆Git存储库中。 我们必须获取一个包含它们及其要使用的标签列表的文件,然后使用vcstool克隆它们:

$ curl -O https://raw.githubusercontent.com/ros2/ros2/foxy/ros2.repos$ vcs import ws/src < ros2.repos

Unfortunately this pulls in some stuff that has dependencies that are not available and that we don’t want to use right now anyway. When running the whole process later on rosdep is used to install all dependencies and we have to tell it to skip the missing ones to not break. Create a dependencies file that replaces these with empty lists: create the file custom-data/skip.yaml and edit it to have the following contents:

不幸的是,这引入了一些依赖项,这些依赖项尚不可用,我们现在也不想使用。 当稍后在rosdep上运行整个过程时,将使用rosdep来安装所有依赖项,我们必须告诉它跳过丢失的依赖项以免中断。 创建一个依赖文件,将其替换为空列表:创建文件custom-data/skip.yaml并将其编辑为具有以下内容:

console_bridge:
debian: []
fastcdr:
debian: []
fastrtps:
debian: []
rti-connext-dds-5.3.1:
debian: []
urdfdom_headers:
debian: []
tango_icons_vendor:
debian: []

Next, create the file rosdep-script.sh (directly inside the ros2-crosscompile directory) and fill it with the following commands that will be run to put skip.yaml into the right place and ensure it gets picked up:

接下来,创建文件rosdep-script.sh (直接在ros2-crosscompile目录中)并用以下命令填充该文件,将运行这些命令以将skip.yaml放到正确的位置并确保将其拾取:

#!/usr/bin/env bash
mkdir -p /etc/ros/rosdep/custom-rules
cp ./custom-data/skip.yaml /etc/ros/rosdep/custom-rules/skip.yaml
echo "yaml file:/etc/ros/rosdep/custom-rules/skip.yaml" > /etc/ros/rosdep/sources.list.d/10-skip.list

On top of that we will also disable building some packages to reduce the build time a bit, including the Rviz2 and RQT visualisation tools. This is not necessary and you can skip this, but you would probably want to run those tools on your host machine instead of directly on the Coral board. The following commands create empty marker files that tell the Colcon build tool to skip them:

最重要的是,我们还将禁用某些软件包的构建以减少构建时间,包括Rviz2和RQT可视化工具。 这不是必需的,您可以跳过此步骤,但是您可能希望在主机上而不是直接在Coral板上运行这些工具。 以下命令创建了空的标记文件,这些文件告诉Colcon构建工具跳过它们:

$ touch ws/src/ros2/rviz/COLCON_IGNORE$ touch ws/src/ros-visualization/COLCON_IGNORE$ touch ws/src/ros2/system_tests/COLCON_IGNORE

The final file to prepare is ws/defaults.yaml, which will be used by Colcon to create a compact and optimised release build. Edit it to read:

要准备的最终文件是ws/defaults.yaml ,Colcon将使用它创建一个紧凑且优化的发行版本。 编辑它为:

build:
merge-install: true
mixin: [release]

Phew, that’s the hard bit done!

ew,这很难完成!

进行实际的交叉编译 (Do the actual cross-compilation)

Now you are ready to kick off the cross-compilation process:

现在,您可以开始交叉编译过程了:

$ ros_cross_compile $(pwd)/ws \
--arch aarch64 \
--os debian \
--rosdistro foxy \
--custom-rosdep-script $(pwd)/rosdep-script.sh \
--custom-data-dir $(pwd)/custom-data

If all went well this will compile the whole of ROS 2 Foxy Fitzroy for the Coral dev board — or actually for any 64-bit ARM platform. This will take a good amount of time, so this is as good a moment as any for grabbing some dinner, replacing all the screws on your robots, or read your favourite web comic.

如果一切顺利,这将为Coral开发板或实际上为任何64位ARM平台编译整个ROS 2 Foxy Fitzroy。 这将花费大量时间,因此与抓晚餐,更换机器人上的所有螺钉或阅读喜爱的网络漫画一样,这是一个好时机。

复制到板并进行测试 (Copy to the board & test)

When the compilation is finally done, the results of all this work is available in the ws/install_aarch64 directory. The complete ROS 2 system is contained in there, so we can copy the whole thing over to the board now. We will use rsync, ensuring the right SSH key is used:

最终完成编译后,所有这些工作的结果将在ws/install_aarch64目录中提供。 完整的ROS 2系统包含在其中,因此我们现在可以将整个内容复制到板上。 我们将使用rsync ,确保使用正确的SSH密钥:

$ rsync -arzP \
-e 'ssh -i ~/.config/mdt/keys/mdt.key' \
ws/install_aarch64 mendel@deft-llama.local:

Now SSH into the board and ensure that all system dependencies are properly installed on the board:

现在,SSH进入开发板,并确保所有系统相关性均已正确安装在开发板上:

$ ROS_OS_OVERRIDE=debian:buster rosdep --os debian:buster update$ ROS_OS_OVERRIDE=debian:buster rosdep --os debian:buster install \
--from-paths install_aarch64/share \
--ignore-src \
--rosdistro foxy -y \
--skip-keys "console_bridge fastcdr fastrtps osrf_testing_tools_cpp poco_vendor rmw_connext_cpp rosidl_typesupport_connext_c rosidl_typesupport_connext_cpp rti-connext-dds-5.3.1 tinyxml_vendor tinyxml2_vendor urdfdom urdfdom_headers tango_icons_vendor cyclonedds"

Now you are (finally!) ready to try out the standard talker/listener demo on your Coral board:

现在,您(终于可以!)准备在珊瑚板上尝试标准的演讲者/听众演示:

$ source install_aarch64/setup.bash$ ros2 launch demo_nodes_cpp talker_listener.launch.py
[INFO] [launch]: All log files can be found below /home/mendel/.ros/log/2020-07-07-15-53-05-727808-deft-llama-12179
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [talker-1]: process started with pid [12182]
[INFO] [listener-2]: process started with pid [12183]
[talker-1] [INFO] [1594137187.273531702] [talker]: Publishing: 'Hello World: 1'
[listener-2] [INFO] [1594137187.279673904] [listener]: I heard: [Hello World: 1]
[talker-1] [INFO] [1594137188.272416191] [talker]: Publishing: 'Hello World: 2'
[listener-2] [INFO] [1594137188.275080792] [listener]: I heard: [Hello World: 2]
...

If the output looks anything like that, you’re done!

如果输出看起来像这样,就完成了!

从这往哪儿走 (Where to go from here)

Now you naturally want to do something much more advanced with the board than printing some text… If you develop your own ROS 2 packages for the Coral board you can choose to cross-compile them similarly to what we did here for ROS 2 itself. However, unless you make things too complex, a workflow where you just compile your packages on the board itself can work fine as well. Because the OS is basically just Debian you can install all the build and development tools straight onto the board.

现在,您自然希望对板进行比打印一些文本更高级的事情……如果您为珊瑚板开发自己的ROS 2软件包,则可以选择像在此为ROS 2本身所做的那样交叉编译它们。 但是,除非您使事情变得过于复杂,否则只需在主板上编译程序包的工作流程就可以正常工作。 因为该操作系统基本上只是Debian,所以您可以将所有构建和开发工具直接安装到板上。

But of course you want to use the TPU! We have been building a ROS 2 package to work with Tensorflow Lite, including its tools and operators to take full advantage of the Edge TPU. It currently supports image classification, object detection and semantic segmentation. You can check out our repository to give it a try (also without a TPU):

但是,您当然要使用TPU! 我们一直在构建与Tensorflow Lite一起使用的ROS 2软件包,包括其工具和操作员,以充分利用Edge TPU。 它目前支持图像分类,对象检测和语义分割。 您可以查看我们的存储库以尝试一下(也可以不使用TPU):

Image for post
Snapshot of ROS 2 TF Lite package running object detection at 30Hz on the Coral board, visualised using RQT
ROS 2 TF Lite软件包在珊瑚板上以30Hz频率运行对象检测的快照,使用RQT可视化

Watch this space for more How-Tos and updates about this setup in the future, and we’d love to see how other people use these tools, so do drop a comment with how you’re getting along with it when you give it a try!

观看此空间,以获取更多将来的设置方法和更新,我们很乐意看到其他人如何使用这些工具,因此,当您给它一个工具时,请留下您如何与之相处的评论尝试!

翻译自: https://medium.com/@sgvandijk/how-to-run-ros-2-foxy-on-googles-coral-edge-tpu-dev-board-319c893526a4

coral 迁移

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值