Files

161 lines
8.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## [系统要求](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id1)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#system-requirements "Link to this heading")
当前 Humble Hawksbill 基于 Debian 的目标平台包括:
- 第一级:Ubuntu Linux - Jammy (22.04) 64位
- 第三级:Ubuntu Linux - Focal (20.04) 64位
- 第三级:Debian Linux - Bullseye (11) 64位
其他支持程度不同的 Linux 平台包括:
- Arch Linux,请参阅[替代安装说明](https://wiki.archlinux.org/index.php/ROS#ROS_2)
- Fedora Linux,请参阅[替代安装说明](https://ros2docs.robook.org/humble/Installation/Alternatives/Fedora-Development-Setup.html)
- OpenEmbedded / webOS OSE,请参阅[替代安装说明](https://github.com/ros/meta-ros/wiki/OpenEmbedded-Build-Instructions)
如 [REP 2000](https://www.ros.org/reps/rep-2000.html) 中所定义。
## [系统设置](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id2)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#system-setup "Link to this heading")
### [设置区域](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id3)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#set-locale "Link to this heading")
请确保您有一个支持 `UTF-8` 的区域设置。如果您处于最简环境中(例如 docker 容器),区域设置可能是一些类似 `POSIX` 的选项。我们使用以下设置通过了测试。但是,如果您使用不同的支持 `UTF-8` 的区域设置,也应该没问题。
```bash
locale # 检查 UTF-8 支持
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 # 验证设置
```
### [添加 ROS 2 apt 仓库](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id4)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#add-the-ros-2-apt-repository "Link to this heading")
你需要将 ROS 2 apt 仓库添加到你的系统中。
首先确保 [Ubuntu Universe 仓库](https://help.ubuntu.com/community/Repositories/Ubuntu) 已启用。
```bash
sudo apt install software-properties-common
sudo add-apt-repository universe
```
然后使用 apt 添加 ROS 2 GPG 密钥。
```bash
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
```
然后将仓库添加到你的源列表中。
```bash
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
```
### [安装开发工具和 ROS 工具](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id5)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#install-development-tools-and-ros-tools "Link to this heading")
安装常用软件包。
```bash
sudo apt update && sudo apt install -y \
python3-flake8-docstrings \
python3-pip \
python3-pytest-cov \
ros-dev-tools
```
根据您的 Ubuntu 版本安装软件包。
Ubuntu 22.04 LTS 及更高版本 Ubuntu 20.04 LTS
```bash
sudo apt install -y \
python3-flake8-blind-except \
python3-flake8-builtins \
python3-flake8-class-newline \
python3-flake8-comprehensions \
python3-flake8-deprecated \
python3-flake8-import-order \
python3-flake8-quotes \
python3-pytest-repeat \
python3-pytest-rerunfailures
```
## [获取 ROS 2 代码](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id6)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#get-ros-2-code "Link to this heading")
创建工作区并克隆所有仓库:
```bash
mkdir -p ~/ros2_humble/src
cd ~/ros2_humble
vcs import --input https://raw.githubusercontent.com/ros2/ros2/humble/ros2.repos src
```
## [使用 rosdep 安装依赖](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id7)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#install-dependencies-using-rosdep "Link to this heading")
ROS 2 包是在经常更新的 Ubuntu 系统上构建的。在安装新包之前,建议您确保系统是最新的。
%% `sudo apt upgrade` %%
```bash
sudo rosdep init
rosdep update
rosdep install --from-paths src --ignore-src -y --skip-keys "fastcdr rti-connext-dds-6.0.1 urdfdom_headers"
```
**注意**:如果您使用的是基于 Ubuntu 的发行版(如 Linux Mint)但系统未标识为 Ubuntu,您可能会收到类似 `Unsupported OS [mint]` 的错误消息。在这种情况下,请在上述命令后追加 `--os=ubuntu:jammy`。
## [安装额外的 DDS 实现(可选)](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id8)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#install-additional-dds-implementations-optional "Link to this heading")
如果您想使用默认之外的 DDS 或 RTPS 供应商,可以在此处找到说明[这里](https://ros2docs.robook.org/humble/Installation/DDS-Implementations.html)。
## [在工作区中构建代码](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id9)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#build-the-code-in-the-workspace "Link to this heading")
如果您已经通过其他方式(deb 包或二进制发行版)安装了 ROS 2,请确保在未激活其他安装的新环境中运行以下命令。同时确保您的 `.bashrc` 中没有 `source /opt/ros/${ROS_DISTRO}/setup.bash`。您可以使用命令 `printenv | grep -i ROS` 来确保 ROS 2 未被激活。输出应为空。
有关使用 ROS 工作区的更多信息,请参阅[本教程](https://ros2docs.robook.org/humble/Tutorials/Beginner-Client-Libraries/Colcon-Tutorial.html)。
```bash
cd ~/ros2_humble/
colcon build --symlink-install
```
**注意**:如果编译所有示例时遇到问题,导致无法成功构建,您可以像使用 [CATKIN_IGNORE](https://github.com/ros-infrastructure/rep/blob/master/rep-0128.rst) 一样使用 `COLCON_IGNORE` 来忽略子树或从工作区中移除文件夹。例如:如果您想避免安装庞大的 OpenCV 库,只需在 `cam2image` 演示目录中运行 `touch COLCON_IGNORE` 即可将其排除在构建过程之外。
## [环境设置](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id10)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#environment-setup "Link to this heading")
### [源化安装脚本](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id11)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#source-the-setup-script "Link to this heading")
通过源化以下文件来设置您的环境。
# 如果不使用 bash,请将 ".bash" 替换为您的 shell
# 可能的取值为:setup.bash, setup.sh, setup.zsh
```bash
. ~/ros2_humble/install/local_setup.bash
```
## [尝试一些示例](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#id12)[](https://ros2docs.robook.org/humble/Installation/Alternatives/Ubuntu-Development-Setup.html#try-some-examples "Link to this heading")
在一个终端中,源化安装脚本然后运行 C++ `talker`:
```bash
. ~/ros2_humble/install/local_setup.bash
ros2 run demo_nodes_cpp talker
```
在另一个终端中源化安装脚本然后运行 Python `listener`:
```bash
. ~/ros2_humble/install/local_setup.bash
ros2 run demo_nodes_py listener
```
您应该能看到 `talker` 显示它正在 `Publishing` 消息,而 `listener` 显示 `I heard` 这些消息。这表明 C++ 和 Python API 都能正常工作。太好了!