Build and install ROS 2 Foxy Fitzroy under Ubuntu 20.04

Keywords: sudo github pip zlib

ROS 2 Foxy Fitzroy (hereinafter referred to as Foxy) was officially released on June 5, 2020. It is an LTS version and is supported until May 2023. This article is mainly based on the official compilation and installation tutorial [1] Complete and document any problems encountered during compilation.

1. System requirements

In the official Foxy target system, Ubuntu Linux - Focal Fossa (20.04) 64 bit is the first choice. In this paper, Ubuntu 20.04 64 bit is also selected, and Debian Linux - Buster (10), Fedora 32, Arch Linux, OpenEmbedded / webOS OSE are also included. However, Foxy has not been fully tested and is not recommended.


2. System settings

(1) Set locale

Make sure that the system locale supports UTF-8. Run locale on the terminal to view.
If UTF-8 is not supported, run the following code
sudo locale-gen en_US en_US.UTF-8 sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 export LANG=en_US.UTF-8

(2) Add ROS 2 apt warehouse

1) Using apt command to authenticate GPG key
sudo apt update && sudo apt install curl gnupg2 lsb-release curl -s | sudo apt-key add -
You may encounter ros.asc Can't download.
Question 1: ERROR: unable to process source Maybe it's because The site is on the wall.
Solution: modify the hosts file and add the ip address of this website [2].
#Open the hosts file
sudo gedit /etc/hosts
#Add at the end of the file
2) Add warehouse to source list
It is recommended to use the domestic Tsinghua ROS 2 image:
sudo sh -c 'echo "deb [arch=amd64] `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'
You can also use the official ROS 2 warehouse, which may be slow.
sudo sh -c 'echo "deb `lsb_release -cs` main" > /etc/apt/sources.list.d/ros2-latest.list'

(3) Install development tools and ROS tools

sudo apt update && sudo apt install -y \
  build-essential \
  cmake \
  git \
  libbullet-dev \
  python3-colcon-common-extensions \
  python3-flake8 \
  python3-pip \
  python3-pytest-cov \
  python3-rosdep \
  python3-setuptools \
  python3-vcstool \
# install some pip packages needed for testing
python3 -m pip install -U \
  argcomplete \
  flake8-blind-except \
  flake8-builtins \
  flake8-class-newline \
  flake8-comprehensions \
  flake8-deprecated \
  flake8-docstrings \
  flake8-import-order \
  flake8-quotes \
  pytest-repeat \
  pytest-rerunfailures \
# install Fast-RTPS dependencies
sudo apt install --no-install-recommends -y \
  libasio-dev \
# install Cyclone DDS dependencies
sudo apt install --no-install-recommends -y \

3. Get ROS 2 code

Create the workspace and get the ROS 2 code.
mkdir -p ~/ros2_foxy/src
cd ~/ros2_foxy
vcs import src < ros2.repos

If fast DDS cannot be downloaded normally, download and unzip to ~ / ros2 by yourself_ foxy/src/eProsima/Fast-DDS.​

4. Use rosdep to install dependency

sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src --rosdistro foxy -y --skip-keys "console_bridge fastcdr fastrtps rti-connext-dds-5.3.1 urdfdom_headers"

5. Compile ROS 2

cd ~/ros2_foxy/
colcon build --symlink-install
The problems encountered during compilation are as follows:
Q2: importerror: "from catkin_ pkg.package import parse_ package" failed: No module named catkin_ pkg.package
Solution [3]: pip install catkin_pkg
Question 3: importError: No module named em
Solution [4]: Python - M PIP install empty
Question 4: importError: No module named lark
Solution [5]: Python - M PIP install lark parser
Question 5: can not locate clang's built in include directory
Solution [6]: reinstall shiboken2 sudo apt remove shiboken2 libshiboken2-dev libshiboken2-py3-5.14 pip3 install --user shiboken2
Question 6: several reasons_ Where the add download is stuck, modify the corresponding CMakeLists.txt .
Solution: (1) ~ / ros2_ foxy/src/ros2/rosbag2/shared_ queues_ vendor/ CMakeLists.txt , lines 8-33
  PREFIX singleproducerconsumer
  #Self modification `path-to-file', zip See attachment for documents
  URL /path-to-file/
  URL_MD5 64c673dd381b8fae9254053ad7b2be4d

# Concurrent and blocking concurrent queue by moodycamel - header only, don't build, install
  PREFIX concurrentqueue
  # Self modification `path-to-file', zip See attachment for documents
  URL /path-to-file/
  URL_MD5 71a0d932cc89150c2ade85f0d9cac9dc
(2) ~/ros2_foxy/src/ros2/rviz/rviz_ogre_vendor/CMakeLists.txt 83-94 That's ok
    #Self modification `path-to-file', zip See attachment for documents zlib-1.2.11.tar.gz
    URL /path-to-file/zlib-1.2.11.tar.gz
    URL_MD5 1c9f62f0778697a09d36121ead88e08e
    #TIMEOUT 600
    LOG_CONFIGURE ${should_log}
    LOG_BUILD ${should_log}
Line 156-186
#    URL
    #Self modification `path-to-file', zip See attachment for documents external_projects/
    URL /path-to-file/
    URL_MD5 cdbea4006d223c173e0a93864111b936
#    TIMEOUT 1200
    LOG_CONFIGURE ${should_log}
    LOG_BUILD ${should_log}
      ${Patch_EXECUTABLE} -p1 -N < ${CMAKE_CURRENT_SOURCE_DIR}/pragma-patch.diff
      ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/FindFreetype.cmake ${CMAKE_CURRENT_BINARY_DIR}/ogre-v1.12.1-prefix/src/ogre-v1.12.1/CMake/Packages/FindFreetype.cmake
(3) ~/ros2_foxy/src/eProsima/foonathan_memory_vendor/CMakeLists.txt,57-73 That's ok
  #GIT_REPOSITORY foonathan/memory
  #GIT_TAG c619113
  #TIMEOUT 600
  #Self modification `path-to-file', zip See attachment for documents
  URL /path-to-file/
  URL_MD5 9fcf2cf8c63d9c74bf3d0c58ca98bf71
  # Avoid the update (git pull) and so the recompilation of foonathan_memory library each time.
(4) ~/ros2_foxy/src/ros2/rosbag2/zstd_vendor/CMakeLists.txt,32-43 That's ok
    #Self modification `path-to-file', zip See attachment for documents
    URL /path-to-file/
    URL_MD5 3a5c3a535280b7f4dfdbd739fcc7173f
    #TIMEOUT 60
    SOURCE_SUBDIR build/cmake

6. Environment setting

Open the file ~ /. bashrc and add it at the end of the file, so that the source command will be executed automatically every time the terminal is opened.
source ~/ros2_foxy/install/setup.bash

7. Testing

Open a terminal and run talker written in C + +:
ros2 run demo_nodes_cpp talker

Open another terminal and run the listener written in Python:

ros2 run demo_nodes_py listener

Operation result:

The API of C + + and Python can work normally.

8. Attachments

Extraction code: tdxu

reference resources


[1] Building ROS 2 on Linux,

[2] Solution to the connection error of rosdep init or rosdep update

[3] No module named catkin_pkg.package,

[4] Error in ROS custom message im portError:Nomodulenamedem_ wawayu_ Column for 0 - CSDN blog

[5] Name conflict in load grammar · Issue #361 · lark-parser/lark,

[6] rosbag2 build getting fail · Issue #604 · ros2/ros2, 

Posted by treybraid on Mon, 15 Jun 2020 23:04:31 -0700