前言
安装
安装环境:基于树莓派4B与Ubuntu20.04 mate
所遇问题

前言

1、关于ROS2.0的发布背景、优势等,可以参考古月居的ROS2探索总结系列。

2、相比于ROS1,ROS2的特点主要有以下几点:

(1)跨平台
  支持构建的系统包括Linux、windows、Mac、RTOS等。

(2)DDS
  ROS2取消了master机制,取而代之的是DDS(Data Distribution Service,数据分发服务)。DDS 的技术核心是以数据为核心的发布订阅模型(Data-Centric Publish-Subscribe ,DCPS),这种DCPS模型创建了一个“全局数据空间”(global data space)的概念,所有独立的应用都可以去访问。在DDS中,每一个发布者或者订阅者都成为参与者(participant),类似于ROS中节点的概念。每一个参与者都可以使用某种定义好的数据类型来读写全局数据空间。
  下图分别是ROS1 架构和ROS2 架构:
ROS1 架构

ROS2 架构

(3)对多机系统更为友好

3、学习过程中,主要使用两种运行环境:Ubuntu 20.04 amd64 和 Ubuntu 20.04 mate arm64,其中前者运行在笔记本上,后者运行在树莓派4B上。以amd64为主,对于arm64的差异会有一定的补充说明。

4、在学习过程中,主要参考古月居的文章和ROS2的官方教程。官方教程除了在线阅读之外,还可以下载到本地

$ git clone https://github.com/ros2/ros2_documentation.git
$ cd ~/ros2_documentation   #注意,这个路径可能不一样
$ make html

可能需要安装下面两个Python包

$ pip3 install sphinx
$ pip3 install sphinx_tabs

5、前言就这些,也许还会补充…

安装

  在Ubuntu 20.04 amd64上安装ROS2:根据官方教程Installing ROS 2 on Linux即可。
  在Ubuntu 20.04 mate arm64上装ROS2:根据官方教程Building ROS 2 on Linux即可。

  由于ROS2对arm架构的树莓派4B的支持不够,所以选择编译源码的方式安装,过程如下。

安装环境:基于树莓派4B与Ubuntu20.04 mate
硬件:树莓派4B arm64
系统:Ubuntu 20.04 mate
ROS:ROS Foxy

编译过程非常漫长,不算解决问题的时间,大概需要三到四个小时…

注意 编译后build文件夹不可删除,~/ros2_foxy/install/setup.bash关联build内的bash文件。

所遇问题

1、步骤 Add the ROS 2 apt repository

$ gpg:no valid openPGP data found

解决方案参考,这个问题在amd64安装中也存在:

# 打开hosts文件
$ sudo gedit /etc/hosts
# 在文件末尾添加
151.101.84.133 raw.githubusercontent.com

2、步骤 Install dependencies using rosdep解决方案同上

ERROR: cannot download default source list from:
https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
website may be down.

3、步骤 Build the code in the workspace——mimick_vendor

[Processing: mimick_vendor, orocos_kdl, rviz_ogre_vendor, urdfdom]                  
--- stderr: mimick_vendor                                                           
CMake Error at CMakeLists.txt:88 (message):
  Architecture 'armv7l' is not supported.

make[2]: *** [CMakeFiles/mimick-ext.dir/build.make:106: mimick-ext-prefix/src/mimick-ext-stamp/mimick-ext-configure] Error 1
make[1]: *** [CMakeFiles/Makefile2:137: CMakeFiles/mimick-ext.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
---
Failed   <<< mimick_vendor [57.1s, exited with code 2]

原因:

(1)mimick不支持armv7l架构。
(2)GitHub有两个mimick,分别是Snaipe/Mimick和ros2/Mimick,后者在前者的基础上修改应用到ros2。
(3)根据这里,arm7l是一个不同于arm32的体系结构,如果没有明确表示为单独的体系结构选项,它将不会被检测为兼容的体系结构。
(4)解决方案参考Snaipe/Mimick#17:在Snaipe/Mimick和ros2/Mimick的CMakeLists.txt中,有如下部分,可以看到不支持armv7l架构。

if (MSVC)
  //省略
else ()
  set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra -Wno-unused-parameter")

  enable_language (ASM)
  if (_ARCH MATCHES "${I386}")
    //省略
  elseif (_ARCH MATCHES "${AMD64}")
    //省略
  elseif (_ARCH MATCHES "${ARM32}")
    //省略
  elseif (_ARCH MATCHES "${ARM64}")
    //省略
  //加在这里***  
  else ()
    message (FATAL_ERROR "Architecture '${_ARCH}' is not supported.")
  endif ()
  set (ASM_EXTENSION ".S")
endif ()

解决方法是在对应位置增加以下代码段:

elseif (_ARCH MATCHES "armv7l")
    set (MMK_ARCH "arm")
    set (MMK_ABI "arm")
    set (MMK_BITS 32)
    set (MMK_ARCH_ARM 1)

(5)但是,这个CMakeLists.txt并不在/src/ros2/mimick_verdor文件夹内,而是在 /build/mimick_vendor/mimick-ext-prefix/src/mimick-ext,/src内只提供了url。需要打补丁的CMakeLists.txt可以在编译出错后找到,修改,再编译即可。
(6)这个问题估计很快就会被官方修改,期待…

4、步骤 Build the code in the workspace

如果觉得编译时间太长,可以选择不编译一些包,如一些demo,方法是在对应目录中,添加一个文件

$ touch AMENT_IGNORE

5、步骤 Build the code in the workspace——tracetools

--- stderr: rcl                                                                                                                           
    CMake Error at CMakeLists.txt:13 (find_package):
      By not providing "Findtracetools.cmake" in CMAKE_MODULE_PATH this project
      has asked CMake to find a package configuration file provided by
      "tracetools", but CMake did not find one.

      Could not find a package configuration file provided by "tracetools" with
      any of the following names:

        tracetoolsConfig.cmake
        tracetools-config.cmake

      Add the installation prefix of "tracetools" to CMAKE_PREFIX_PATH or set
      "tracetools_DIR" to a directory containing one of the above files.  If
      "tracetools" provides a separate development package or SDK, be sure it has
      been installed.
    ---

检查发现目录/src/ros-tracing/ros2_tracing下是空的,查看repos,找到如下内容

ros-tracing/ros2_tracing:
    type: git
    url: https://gitlab.com/ros-tracing/ros2_tracing.git
    version: foxy

然后,重新在对应的地址下载源码,解压到对应目录,再编译。