ROS2安装 (armhf篇)
文章源链接:https://xie-peiquan.gitee.io/categories/ROS2%E5%9F%BA%E7%A1%80/
由于ROS官方并没有提供armhf CPU架构的ROS2二进制安装文件,本篇整理了从ROS2源码编译安装的方法。本篇安装环境如下:
CPU架构:armv7l
操作系统:ubuntu20.04
1 更换镜像源(可选)
更换镜像源可以加速各种依赖库下载速度,这里提供常用的 ubuntu镜像源 和 pip源。
1.1 更换ubuntu镜像源
这里采用清华源,同学们可到该网站 https://mirror.tuna.tsinghua.edu.cn/help/ubuntu/ 寻找自己系统版本对应的源。需要注意的是,大部分高校提供的源都是X86架构的,对于arm设备需要在源加上‘-ports’ 。armv7l / ubuntu20.04的源如下:
mv /etc/apt/sources.list /etc/apt/sources.list.bak
vim /etc/apt/sources.list
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
1.2 更换 PIP 源
这里同样采用清华的pip源,可加速python第三方库的下载(后面需要),命令行输入以下命令即可。
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.trusted-host https://pypi.tuna.tsinghua.edu.cn
2 设置 locale
sudo apt update && sudo apt install locales
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
locale # verify settings
3 添加ROS2 存储库
# 1 确保启用universe存储库
sudo apt install software-properties-common
sudo add-apt-repository universe
# 2 添加ROS2 GPG 密钥
sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
# 3 添加存储库到 sources list
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
# 4 更新apt
sudo apt apdate
4 安装编译工具
sudo apt update && sudo apt install -y \
libbullet-dev \
python3-pip \
python3-pytest-cov \
ros-dev-tools
# 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 \
pytest
# install Fast-RTPS dependencies
sudo apt install --no-install-recommends -y \
libasio-dev \
libtinyxml2-dev
# install Cyclone DDS dependencies
sudo apt install --no-install-recommends -y \
libcunit1-dev
5 获取ROS2源码
mkdir -p ~/ros2_foxy/src
cd ~/ros2_foxy
wget https://raw.githubusercontent.com/ros2/ros2/foxy/ros2.repos --no-check-certificate
## github下载不稳定,可自行修改repos文件,添加代理前缀 https://ghproxy.com/
vcs import --input ./ros2.repos src
6 使用Rosdep安装依赖
sudo apt upgrade
cd /etc/ros/rosdep/sources.list.d && wget https://mirrors.tuna.tsinghua.edu.cn/github-raw/ros/rosdistro/master/rosdep/sources.list.d/20-default.list
rosdep update
rosdep install --from-paths src --ignore-src -y --skip-keys "fastcdr rti-connext-dds-5.3.1 urdfdom_headers"
7 编译ROS2源码
cd ~/ros2_foxy/
colcon build --symlink-install
8 设置环境变量
. ~/ros2_foxy/install/local_setup.bash
9 测试
## 运行talker
. ~/ros2_foxy/install/local_setup.bash
ros2 run demo_nodes_cpp talker
## 新起另一个终端,运行listener
. ~/ros2_foxy/install/local_setup.bash
ros2 run demo_nodes_py listener
~~欢迎到我个人博客 https://xie-peiquan.gitee.io/ 查看更多关于ROS2的文章,嘿嘿!