RDKX5到手怎么搭建初始ROS2 humble环境?

到手RDK X5开发板后,烧录官方镜像RDKOS 3.5.0 Desktop,该镜像能直接用我的ROS2 humble工作包吗,还是需要自己搭建环境呢?我的工作包有底盘、slam_toolbox建图、导航等功能

结论

RDKOS 3.5.0 Desktop 镜像已预装 ROS2/TROS 环境,无需从零搭建,但需要确认以下几点:


:white_check_mark: 第一步:验证当前环境

烧录完成后,在终端执行以下命令检查:

# 1. 检查 ROS2 是否可用
ros2 --version

# 2. 检查 TROS 是否安装
ls /opt/tros/

# 3. 查看已安装的 ROS2 包
apt list --installed | grep ros-humble

:wrench: 第二步:根据结果选择方案

情况 A:已安装标准 ROS2 Humble

# 直接 source 环境
source /opt/ros/humble/setup.bash

# 验证
ros2 topic list

→ 你的工作包(底盘、slam_toolbox、导航)大概率可直接使用

情况 B:只安装了 TROS(TogetherROS)

# source TROS 环境
source /opt/tros/humble/setup.bash

# 验证
ros2 topic list

→ TROS 兼容 ROS2 Humble,但部分包名可能有差异,需检查:

  • slam_toolbox → 通常兼容
  • 底盘驱动 → 可能需要适配 TROS 的驱动接口
  • 导航 → nav2 包通常兼容

情况 C:ros2: command not found

参考社区帖子:RDK X5烧录完镜像之后测试ROS2

# 手动安装 ROS2 Humble
sudo apt update
sudo apt install ros-humble-desktop
source /opt/ros/humble/setup.bash

:warning: 注意事项

项目 说明
架构差异 RDK X5 是 ARM 架构,你的工作包如果在 x86 编译,需交叉编译或在板卡上重新编译
依赖包 检查 package.xml 中的依赖是否已安装:rosdep install --from-paths src
TROS 兼容性 如使用 TROS,参考官方文档:5.1.2 apt安装与升级

:books: 推荐资源

  1. RDK DOC - 快速开始
  2. 第20届智能车备赛指南 - 包含完整的 ROS2 建图导航案例
  3. 交叉编译环境配置

:light_bulb: 建议操作

  1. 先烧录镜像,执行第一步验证命令
  2. 如果遇到问题,把终端输出贴到本帖回复
  3. 工作包建议先在板卡上 colcon build 编译测试

需要我帮你查具体的驱动适配或编译问题吗?

我的应该是情况A,我执行sudo apt upgrade -y升级的时候,非常慢,我是否需要修改国内镜像源呢

结论

需要修改镜像源,RDKOS 默认使用官方源,国内访问速度慢。推荐改用阿里源或清华源。


:wrench: 修改镜像源步骤

:one: 备份原配置

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

:two: 替换为阿里源(Ubuntu 22.04/Jammy)

sudo tee /etc/apt/sources.list > /dev/null <<EOF
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
EOF

:three: 更新软件包索引

sudo apt update

:four: 执行升级

sudo apt upgrade -y

:clipboard: 其他可选镜像源

镜像源 地址
清华大学 https://mirrors.tuna.tsinghua.edu.cn/ubuntu/
中科大 https://mirrors.ustc.edu.cn/ubuntu/
华为云 https://repo.huaweicloud.com/ubuntu/

替换时只需把上面步骤中的 mirrors.aliyun.com 换成对应域名即可。


:warning: 注意事项

项目 说明
ROS 源 ROS2 包通常在 packages.ros.org,如也慢可单独替换 ROS 源
升级风险 apt upgrade 可能升级内核/驱动,建议先测试关键功能
TROS 用户 如使用 TROS,部分包可能来自地平线私有源,升级前确认

:light_bulb: 建议

升级完成后,再执行一次你的工作包编译测试:

cd ~/你的工作包路径
colcon build --symlink-install
source install/setup.bash
ros2 launch 你的启动文件

如果升级后出现新问题,把报错信息贴到本帖,我帮你排查。

执行root@ubuntu:~/xhc_ros2_ws# colcon
-bash: colcon: command not found为什么会找不到?

结论

colcon 未找到是因为没有安装或没有 source 环境。RDKOS 镜像可能预装了 ROS2 基础包,但 colcon 需要单独安装或手动 source。


:wrench: 解决步骤

:one: 先 source ROS2 环境

# 如果是标准 ROS2
source /opt/ros/humble/setup.bash

# 如果是 TROS
source /opt/tros/humble/setup.bash

# 验证
ros2 --version

:two: 检查 colcon 是否可用

colcon --version

如果还是 command not found,继续下一步安装。

:three: 安装 colcon 相关包

sudo apt update
sudo apt install python3-colcon-common-extensions python3-colcon-mixin

:four: 永久配置环境变量(可选但推荐)

# 编辑 ~/.bashrc
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
# 或者如果是 TROS
# echo "source /opt/tros/humble/setup.bash" >> ~/.bashrc

# 使配置生效
source ~/.bashrc

:white_check_mark: 验证安装

# 检查 colcon 版本
colcon --version

# 进入工作空间编译
cd ~/xhc_ros2_ws
colcon build --symlink-install

# source 编译后的环境
source install/setup.bash

# 测试运行
ros2 launch 你的启动文件

:warning: 常见原因

原因 解决方法
未 source 环境 执行 source /opt/ros/humble/setup.bash
colcon 未安装 sudo apt install python3-colcon-common-extensions
环境变量未持久化 添加到 ~/.bashrc
使用了错误的 shell 确认用的是 bash 而不是 sh

:light_bulb: 建议

安装完成后,建议一次性安装常用开发工具:

sudo apt install python3-colcon-common-extensions \
                 python3-rosdep \
                 python3-vcstool \
                 ros-humble-slam-toolbox \
                 ros-humble-navigation2

如果安装过程中遇到依赖问题,把报错信息贴出来,我帮你排查。

root@ubuntu:~/xhc_ros2_ws# source /opt/ros/humble/setup.bash
root@ubuntu:~/xhc_ros2_ws# ros2 --version
usage: ros2 [-h] [–use-python-default-buffering] Call ros2 <command> -h for more detailed usage. …
ros2: error: unrecognized arguments: --version
root@ubuntu:~/xhc_ros2_ws#

结论

ROS2 环境已激活,但版本可能较老或命令语法不同。ros2 命令可用,继续解决 colcon 问题即可。


:wrench: 正确检查 ROS2 版本的方法

# 方法1:查看 apt 安装的包版本
apt list --installed | grep ros-humble

# 方法2:查看 ros2 帮助
ros2 -h

# 方法3:检查具体命令
ros2 topic -h

:bullseye: 核心问题:安装 colcon

你现在的重点是让 colcon 可用,执行以下命令:

# 1. 确保 ROS2 环境已 source
source /opt/ros/humble/setup.bash

# 2. 安装 colcon
sudo apt update
sudo apt install python3-colcon-common-extensions python3-colcon-mixin

# 3. 验证安装
colcon --version

:white_check_mark: 完整编译流程测试

# 1. 进入工作空间
cd ~/xhc_ros2_ws

# 2. 安装工作包依赖(重要!)
rosdep install --from-paths src -y

# 3. 编译
colcon build --symlink-install

# 4. source 编译结果
source install/setup.bash

# 5. 测试运行
ros2 launch 你的启动文件

:warning: 如果 colcon 安装失败

可能遇到的情况及解决:

问题 解决
源太慢 确认已换国内镜像源(阿里/清华)
依赖冲突 先执行 sudo apt update 再安装
权限问题 确保用 sudo 或当前是 root 用户

:light_bulb: 建议:永久配置环境变量

避免每次都要手动 source:

# 添加到 ~/.bashrc
echo "source /opt/ros/humble/setup.bash" >> ~/.bashrc
echo "source ~/xhc_ros2_ws/install/setup.bash" >> ~/.bashrc

# 生效
source ~/.bashrc

先执行 安装 colcon 的命令,把终端输出贴出来,有报错我帮你解决。

root@ubuntu:~/xhc_ros2_ws# sudo apt install python3-colcon-common-extensions python3-colcon-mixin
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
python3-colcon-core : Depends: python3-distlib but it is not installable
Recommends: python3-pytest-cov but it is not installable
python3-colcon-notification : Depends: python3-notify2 but it is not installable
E: Unable to correct problems, you have held broken packages.

结论

这是典型的依赖缺失问题,原因是 Ubuntu 的 universe 和 multiverse 仓库未启用,或者 ROS 源未正确配置。


:wrench: 完整解决方案

:one: 启用所有 Ubuntu 仓库

# 添加 universe 和 multiverse 仓库
sudo add-apt-repository universe
sudo add-apt-repository multiverse

# 如果 add-apt-repository 命令不存在,先安装
sudo apt install software-properties-common

:two: 配置 ROS2 官方源(重要!)

RDKOS 可能只配置了 Ubuntu 源,缺少 ROS 包源:

# 添加 ROS2 GPG 密钥
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

# 添加 ROS2 humble 源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

:three: 更新并安装依赖

# 更新包索引
sudo apt update

# 先单独安装缺失的依赖
sudo apt install python3-distlib python3-notify2 python3-pytest-cov

# 再安装 colcon
sudo apt install python3-colcon-common-extensions python3-colcon-mixin

:clipboard: 如果上述方法仍失败:使用 pip 安装 colcon

作为备选方案,可以用 Python pip 安装:

# 确保 pip 已安装
sudo apt install python3-pip

# 使用 pip 安装 colcon
pip3 install colcon-common-extensions colcon-mixin

# 验证
colcon --version

:white_check_mark: 验证并编译

# 1. 确认 colcon 可用
colcon --version

# 2. 进入工作空间
cd ~/xhc_ros2_ws

# 3. 安装工作包依赖
rosdep init  # 如果提示已初始化可忽略
rosdep update
rosdep install --from-paths src -y --ignore-src

# 4. 编译
colcon build --symlink-install

# 5. source 环境
source install/setup.bash

:warning: 常见问题排查

问题 检查命令 解决
源配置是否正确 cat /etc/apt/sources.list 确认有 universe 和 multiverse
ROS 源是否存在 cat /etc/apt/sources.list.d/ros2.list 按步骤 2 添加
包索引是否最新 sudo apt update 看是否有错误 检查网络连接和镜像源

:light_bulb: 建议

执行完上述步骤后,把 sudo apt update 的输出贴出来,如果有报错我能更精准帮你定位问题。

如果 pip 方案成功了,记得后续编译工作包时可能需要额外安装一些 ROS 依赖包。

E: Failed to fetch https://mirrors.aliyun.com/ubuntu/dists/jammy/main/binary-arm64/Packages 404 Not Found [IP: 117.33.166.61 443]
E: Failed to fetch https://mirrors.aliyun.com/ubuntu/dists/jammy-security/main/binary-arm64/Packages 404 Not Found [IP: 117.33.166.61 443]
E: Failed to fetch https://mirrors.aliyun.com/ubuntu/dists/jammy-updates/main/binary-arm64/Packages 404 Not Found [IP: 117.33.166.61 443]
E: Failed to fetch https://mirrors.aliyun.com/ubuntu/dists/jammy-proposed/main/binary-arm64/Packages 404 Not Found [IP: 117.33.166.61 443]
E: Failed to fetch https://mirrors.aliyun.com/ubuntu/dists/jammy-backports/main/binary-arm64/Packages 404 Not Found [IP: 117.33.166.61 443]
E: Some index files failed to download. They have been ignored, or old ones used instead.

结论

阿里源配置有误,RDKOS 3.5.0 可能基于定制化 Ubuntu,需要换用清华源或确认系统实际版本。


:wrench: 紧急修复步骤

:one: 先确认系统版本

# 查看实际 Ubuntu 版本
cat /etc/os-release
lsb_release -a

确认是 22.04 (jammy) 还是其他版本。


:two: 换用清华源(推荐)

阿里源部分路径可能同步延迟,改用清华源:

# 备份
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak2

# 写入清华源 (Ubuntu 22.04/jammy)
sudo tee /etc/apt/sources.list > /dev/null <<EOF
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
EOF

:three: 清理缓存并更新

# 清理 apt 缓存
sudo apt clean
sudo rm -rf /var/lib/apt/lists/*

# 重新生成索引
sudo apt update

:four: 如果清华源也失败:使用 RDK 官方源

RDKOS 可能使用地平线私有源,检查是否有官方配置:

# 查看现有源配置
cat /etc/apt/sources.list
ls /etc/apt/sources.list.d/

# 查看是否有 horizon 相关源
grep -r "horizon\|d-robotics" /etc/apt/sources.list*

:clipboard: 备选方案:直接用 pip 安装 colcon

如果 apt 源问题短期无法解决,先用 pip 安装 colcon 继续开发:

# 安装 pip
sudo apt install python3-pip

# 用 pip 安装 colcon(不依赖 apt 源)
pip3 install --user colcon-common-extensions colcon-mixin

# 添加用户 bin 到 PATH
echo 'export PATH=~/.local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

# 验证
colcon --version

:white_check_mark: 验证流程

# 1. 确认 colcon 可用
colcon --version

# 2. 编译工作包
cd ~/xhc_ros2_ws
colcon build --symlink-install

# 3. source 环境
source install/setup.bash

:light_bulb: 建议

  1. 先执行 确认系统版本 的命令,把输出贴出来
  2. 尝试清华源方案
  3. 如果还是失败,先用 pip 方案 让 colcon 跑起来,不耽误开发

把 cat /etc/os-release 的输出贴出来,我帮你确认正确的源配置。

root@ubuntu:~/xhc_ros2_ws# cat /etc/os-release
PRETTY_NAME=“Ubuntu 22.04.5 LTS”
NAME=“Ubuntu”
VERSION_ID=“22.04”
VERSION=“22.04.5 LTS (Jammy Jellyfish)”
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL=“https://www.ubuntu.com/”
SUPPORT_URL=“https://help.ubuntu.com/”
BUG_REPORT_URL=“https://bugs.launchpad.net/ubuntu/”
PRIVACY_POLICY_URL=“https://www.ubuntu.com/legal/terms-and-policies/privacy-policy”
UBUNTU_CODENAME=jammy
root@ubuntu:~/xhc_ros2_ws# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy

结论

系统确认是 Ubuntu 22.04.5 LTS (jammy),阿里源 404 可能是同步延迟或网络问题。换用清华源更稳定,同时提供 pip 备选方案。


:wrench: 解决方案

方案 A:换用清华源(推荐)

# 1. 备份当前配置
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak3

# 2. 写入清华源
sudo tee /etc/apt/sources.list > /dev/null <<EOF
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
EOF

# 3. 清理缓存
sudo apt clean
sudo rm -rf /var/lib/apt/lists/*

# 4. 更新索引
sudo apt update

如果成功,继续安装 colcon:

sudo apt install python3-colcon-common-extensions python3-colcon-mixin

方案 B:直接用 pip 安装 colcon(快速备选)

如果 apt 源问题短期解决不了,先用 pip 让 colcon 跑起来:

# 1. 安装 pip
sudo apt install python3-pip

# 2. 用 pip 安装 colcon
pip3 install --user colcon-common-extensions colcon-mixin

# 3. 添加用户 bin 到 PATH
echo 'export PATH=~/.local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

# 4. 验证
colcon --version

方案 C:添加 ROS2 官方源(如果缺少 ROS 包)

RDKOS 可能只配置了 Ubuntu 源,缺少 ROS 包源:

# 添加 ROS2 GPG 密钥
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg

# 添加 ROS2 humble 源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

# 更新
sudo apt update

:white_check_mark: 编译工作包完整流程

# 1. 确认 colcon 可用
colcon --version

# 2. 进入工作空间
cd ~/xhc_ros2_ws

# 3. 安装工作包依赖
rosdep init 2>/dev/null || true
rosdep update
rosdep install --from-paths src -y --ignore-src

# 4. 编译
colcon build --symlink-install

# 5. source 环境
source install/setup.bash

# 6. 测试
ros2 topic list

:light_bulb: 建议

  1. 优先试方案 A(清华源),把 sudo apt update 的输出贴出来
  2. 如果清华源也失败,用方案 B(pip) 先让 colcon 跑起来,不耽误开发
  3. 后续再慢慢排查 apt 源问题

把 sudo apt update 的结果贴出来,有报错我继续帮你解决。

root@ubuntu:~/xhc_ros2_ws# sudo apt install python3-colcon-common-extensions python3-colcon-mixin
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
python3-colcon-core : Depends: python3-distlib but it is not installable
Recommends: python3-pytest-cov but it is not installable
python3-colcon-notification : Depends: python3-notify2 but it is not installable
E: Unable to correct problems, you have held broken packages.

结论

问题根源:Ubuntu 的 universe 仓库未启用,python3-distlib 等包在 universe 仓库中。

最快速的解决方案是 直接用 pip 安装 colcon,不依赖 apt 源配置。


:rocket: 快速方案:用 pip 安装 colcon(推荐)

# 1. 安装 pip
sudo apt install python3-pip

# 2. 用 pip 安装 colcon
pip3 install --user colcon-common-extensions colcon-mixin

# 3. 添加用户 bin 到 PATH
echo 'export PATH=~/.local/bin:$PATH' >> ~/.bashrc
source ~/.bashrc

# 4. 验证
colcon --version

:wrench: 备选方案:启用 universe 仓库

如果想用 apt 安装,需要先启用 universe 仓库:

# 1. 查看当前源配置
cat /etc/apt/sources.list

# 2. 确认每行都包含 universe,如没有则编辑
sudo sed -i 's/jammy main restricted/jammy main restricted universe multiverse/g' /etc/apt/sources.list

# 3. 清理并更新
sudo apt clean
sudo rm -rf /var/lib/apt/lists/*
sudo apt update

# 4. 安装缺失依赖
sudo apt install python3-distlib python3-notify2

# 5. 安装 colcon
sudo apt install python3-colcon-common-extensions python3-colcon-mixin

:white_check_mark: 安装完成后编译工作包

cd ~/xhc_ros2_ws

# 安装工作包依赖
rosdep init 2>/dev/null || true
rosdep update
rosdep install --from-paths src -y --ignore-src

# 编译
colcon build --symlink-install

# source 环境
source install/setup.bash

# 测试
ros2 topic list

:light_bulb: 建议

优先用 pip 方案,5 分钟内就能让 colcon 跑起来,不耽误开发。

把 colcon --version 的输出贴出来,确认成功后我们继续排查工作包编译问题。

llecting colcon-library-path
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b8/02/4e4dd0cb94491774e87cf479066a8b6ef1f653889a0c9fb957f527c165f7/colcon_library_path-0.2.1-py3-none-any.whl (4.9 kB)
Collecting colcon-recursive-crawl
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/89/1c/04c4382add856e6109cc9a2beca3f40aeceabce4d09cf832ea1bac97c3d9/colcon_recursive_crawl-0.2.3-py3-none-any.whl (8.3 kB)
Collecting colcon-package-selection
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6f/58/fb91adaab07ed20865839acd45a6f88a030751c19688e4781d556d34a1b5/colcon_package_selection-0.2.10-py3-none-any.whl (16 kB)
Collecting colcon-package-information
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1e/ee/a6b0ffdc06c67f3ab740c3bf8efaf520c7adb3b4bf189b447e90101ff838/colcon_package_information-0.4.1-py3-none-any.whl (15 kB)
Collecting colcon-core
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7c/ba/4710fa60e3e6cf1491daba9bde1f208eeeabb3546b989aff6e84bbc414fa/colcon_core-0.21.0-py3-none-any.whl (141 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 141.5/141.5 KB 4.5 MB/s eta 0:00:00
Requirement already satisfied: PyYAML in /usr/lib/python3/dist-packages (from colcon-mixin) (5.4.1)
Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from colcon-core->colcon-common-extensions) (25.0)
Collecting pytest-repeat
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/73/d4/8b706b81b07b43081bd68a2c0359fe895b74bf664b20aca8005d2bb3be71/pytest_repeat-0.9.4-py3-none-any.whl (4.2 kB)
Collecting pytest-cov
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9d/7a/d968e294073affff457b041c2be9868a40c1c71f4a35fcc1e45e5493067b/pytest_cov-7.1.0-py3-none-any.whl (22 kB)
Collecting pytest-rerunfailures
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ce/93/3cdcc4033444e822e01b573414b03fd37fd5533070c750477b8f5fa5224b/pytest_rerunfailures-16.4-py3-none-any.whl (16 kB)
Requirement already satisfied: EmPy in /usr/lib/python3/dist-packages (from colcon-core->colcon-common-extensions) (3.3.4)
Collecting distlib
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/02/08/9c41fb51ab5b43eb21674aff13df270e8ba6c4b29c8624e328dc7a9482af/distlib-0.4.3-py2.py3-none-any.whl (470 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 470.6/470.6 KB 2.0 MB/s eta 0:00:00
Collecting setuptools<80,>=30.3.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0d/6d/b4752b044bf94cb802d88a888dc7d288baaf77d7910b7dedda74b5ceea0c/setuptools-79.0.1-py3-none-any.whl (1.3 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.3/1.3 MB 3.1 MB/s eta 0:00:00
Requirement already satisfied: pytest in /usr/lib/python3/dist-packages (from colcon-core->colcon-common-extensions) (6.2.5)
Requirement already satisfied: tomli>=1.0.0 in /usr/lib/python3/dist-packages (from colcon-core->colcon-common-extensions) (1.2.2)
Requirement already satisfied: argcomplete in /usr/lib/python3/dist-packages (from colcon-argcomplete->colcon-common-extensions) (1.8.1)
Collecting notify2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f9/69/99d2bc2d98a802b6f58d1e0a774a933b3fea5ef11455379561b71c04370b/notify2-0.3.1-py2.py3-none-any.whl (8.0 kB)
Collecting colcon-pkg-config
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/75/28/d738200c7eed21cd78df901fa78818618f5b85dd39ea7c3905b367fcb033/colcon_pkg_config-0.1.0-py3-none-any.whl (4.5 kB)
Collecting catkin-pkg>=0.4.14
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/99/1b/50316bd6f95c50686b35799abebb6168d90ee18b7c03e3065f587f010f7c/catkin_pkg-1.1.0-py3-none-any.whl (76 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76.4/76.4 KB 4.3 MB/s eta 0:00:00
Requirement already satisfied: python-dateutil in /usr/lib/python3/dist-packages (from catkin-pkg>=0.4.14->colcon-ros->colcon-common-extensions) (2.8.1)
Requirement already satisfied: docutils in /usr/lib/python3/dist-packages (from catkin-pkg>=0.4.14->colcon-ros->colcon-common-extensions) (0.17.1)
Requirement already satisfied: pyparsing in /usr/lib/python3/dist-packages (from catkin-pkg>=0.4.14->colcon-ros->colcon-common-extensions) (2.4.7)
Collecting coverage[toml]>=7.10.6
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/47/c6/99d0f1c1dd1583aaf8c1deca447e44426be54a76027a8c55e29970f22b15/coverage-7.15.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (252 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 252.1/252.1 KB 4.0 MB/s eta 0:00:00
Collecting pytest
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/24/25/1de2678b631f5a49215c6c96fff41ba892b0a34df68d6d80292b1b48aa7f/pytest-9.1.1-py3-none-any.whl (386 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 386.5/386.5 KB 1.6 MB/s eta 0:00:00
Collecting pluggy>=1.2
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/54/20/4d324d65cc6d9205fabedc306948156824eb9f0ee1633355a8f7ec5c66bf/pluggy-1.6.0-py3-none-any.whl (20 kB)
Collecting exceptiongroup>=1
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8a/0e/97c33bf5009bdbac74fd2beace167cab3f978feb69cc36f1ef79360d6c4e/exceptiongroup-1.3.1-py3-none-any.whl (16 kB)
Requirement already satisfied: iniconfig>=1.0.1 in /usr/lib/python3/dist-packages (from pytest->colcon-core->colcon-common-extensions) (1.1.1)
Requirement already satisfied: pygments>=2.7.2 in /usr/lib/python3/dist-packages (from pytest->colcon-core->colcon-common-extensions) (2.11.2)
Collecting typing-extensions>=4.6.0
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/49/d3/b8441a820a491ddfc024b0b0cf0393375b75ea13866d9c66727e54c2fc80/typing_extensions-4.16.0-py3-none-any.whl (45 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 45.6/45.6 KB 3.1 MB/s eta 0:00:00
Installing collected packages: notify2, distlib, typing-extensions, setuptools, pluggy, coverage, exceptiongroup, catkin-pkg, pytest, pytest-rerunfailures, pytest-repeat, pytest-cov, colcon-core, colcon-zsh, colcon-test-result, colcon-recursive-crawl, colcon-python-setup-py, colcon-powershell, colcon-pkg-config, colcon-parallel-executor, colcon-package-selection, colcon-package-information, colcon-output, colcon-notification, colcon-mixin, colcon-metadata, colcon-library-path, colcon-devtools, colcon-defaults, colcon-bash, colcon-argcomplete, colcon-cmake, colcon-cd, colcon-ros, colcon-common-extensions
WARNING: The scripts coverage, coverage-3.10 and coverage3 are installed in ‘/root/.local/bin’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts catkin_create_pkg, catkin_find_pkg, catkin_generate_changelog, catkin_package_version, catkin_prepare_release, catkin_tag_changelog and catkin_test_changelog are installed in ‘/root/.local/bin’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts py.test and pytest are installed in ‘/root/.local/bin’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script colcon is installed in ‘/root/.local/bin’ which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed catkin-pkg-1.1.0 colcon-argcomplete-0.3.3 colcon-bash-0.5.0 colcon-cd-0.1.1 colcon-cmake-0.2.30 colcon-common-extensions-0.3.0 colcon-core-0.21.0 colcon-defaults-0.2.9 colcon-devtools-0.3.0 colcon-library-path-0.2.1 colcon-metadata-0.2.5 colcon-mixin-0.2.3 colcon-notification-0.3.1 colcon-output-0.2.14 colcon-package-information-0.4.1 colcon-package-selection-0.2.10 colcon-parallel-executor-0.4.0 colcon-pkg-config-0.1.0 colcon-powershell-0.5.0 colcon-python-setup-py-0.2.9 colcon-recursive-crawl-0.2.3 colcon-ros-0.5.0 colcon-test-result-0.3.8 colcon-zsh-0.5.0 coverage-7.15.1 distlib-0.4.3 exceptiongroup-1.3.1 notify2-0.3.1 pluggy-1.6.0 pytest-9.1.1 pytest-cov-7.1.0 pytest-repeat-0.9.4 pytest-rerunfailures-16.4 setuptools-79.0.1 typing-extensions-4.16.0
WARNING: Running pip as the ‘root’ user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
root@ubuntu:~/xhc_ros2_ws# echo ‘export PATH=~/.local/bin:$PATH’ >> ~/.bashrc
root@ubuntu:~/xhc_ros2_ws# source ~/.bashrc
root@ubuntu:~/xhc_ros2_ws# colcon --version
usage: colcon [-h] [–log-base LOG_BASE] [–log-level LOG_LEVEL] {build,extension-points,extensions,graph,info,list,metadata,mixin,test,test-result,version-check} …
colcon: error: argument verb_name: invalid choice: ‘–version’ (choose from ‘build’, ‘extension-points’, ‘extensions’, ‘graph’, ‘info’, ‘list’, ‘metadata’, ‘mixin’, ‘test’, ‘test-result’, ‘version-check’)

结论

colcon 已成功安装! 只是验证命令用错了,colcon 不支持 --version 参数。


:white_check_mark: 正确的验证方式

# 方法1:查看版本信息
colcon version-check

# 方法2:查看帮助(确认命令可用)
colcon build --help

# 方法3:直接测试编译
cd ~/xhc_ros2_ws
colcon build --symlink-install

:bullseye: 下一步:编译你的工作包

# 1. 进入工作空间
cd ~/xhc_ros2_ws

# 2. 初始化 rosdep(如果没做过)
sudo rosdep init 2>/dev/null || true
rosdep update

# 3. 安装工作包依赖
rosdep install --from-paths src -y --ignore-src

# 4. 编译
colcon build --symlink-install

# 5. source 环境
source install/setup.bash

# 6. 测试功能
ros2 topic list
ros2 launch 你的启动文件

:warning: 注意事项

项目 说明
root 用户 你当前是 root 用户,开发时注意权限问题
PATH 配置 ~/.local/bin 已添加到 PATH,重启终端后仍有效
依赖包 如编译报错缺少 ROS 包,用 sudo apt install ros-humble-包名 安装

:light_bulb: 常见问题预判

如果编译时遇到以下问题:

# 问题1:找不到某个 ROS 包
# 解决:apt install ros-humble-包名

# 问题2:slam_toolbox 缺失
# 解决:sudo apt install ros-humble-slam-toolbox

# 问题3:navigation2 缺失
# 解决:sudo apt install ros-humble-navigation2

现在执行 colcon build --symlink-install 试试,把编译输出贴出来,有报错我帮你解决! :rocket:

root@ubuntu:~/xhc_ros2_ws# sudo apt install ros-humble-slam-toolbox
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
ros-humble-slam-toolbox : Depends: libceres2 (>= 2.0.0+dfsg1) but it is not installable
Depends: libceres-dev but it is not installable
Depends: liblapack-dev but it is not installable
Depends: ros-humble-nav2-map-server but it is not going to be installed
Depends: ros-humble-rviz-common but it is not going to be installed
Depends: ros-humble-rviz-default-plugins but it is not going to be installed
Depends: ros-humble-rviz-ogre-vendor but it is not going to be installed
Depends: ros-humble-rviz-rendering but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

结论

apt 源配置仍不完整,缺少 universe 仓库和 ROS 官方源,导致 libceres、liblapack 等依赖无法安装。

有两个解决方案:修复 apt 源 或 源码编译 slam_toolbox。


:rocket: 方案 A:快速修复 apt 源(推荐先试)

# 1. 写入完整源的配置(包含 universe/multiverse)
sudo tee /etc/apt/sources.list > /dev/null <<EOF
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
EOF

# 2. 添加 ROS2 humble 官方源
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null

# 3. 清理缓存并更新
sudo apt clean
sudo rm -rf /var/lib/apt/lists/*
sudo apt update

如果 sudo apt update 成功无 404 错误,继续安装:

sudo apt install ros-humble-slam-toolbox

:wrench: 方案 B:源码编译 slam_toolbox(如果 apt 源始终失败)

# 1. 创建源码目录
mkdir -p ~/slam_ws/src
cd ~/slam_ws/src

# 2. 克隆 slam_toolbox
git clone -b humble https://github.com/SteveMacenski/slam_toolbox.git

# 3. 安装编译依赖
sudo apt install libceres-dev liblapack-dev libeigen3-dev

# 4. 编译
cd ~/slam_ws
colcon build --symlink-install

# 5. source 环境
source install/setup.bash

:high_voltage: 方案 C:先测试基础功能(不耽误开发)

如果 slam_toolbox 短期搞不定,可以先测试其他功能:

# 1. 先编译你的工作包(不依赖 slam_toolbox 的部分)
cd ~/xhc_ros2_ws
colcon build --symlink-install
source install/setup.bash

# 2. 测试底盘驱动
ros2 launch 你的底盘启动文件

# 3. 测试其他节点
ros2 topic list
ros2 node list

:clipboard: 请先执行这个诊断命令

# 查看当前源配置
cat /etc/apt/sources.list
cat /etc/apt/sources.list.d/ros2.list 2>/dev/null || echo "ROS 源未配置"

# 测试更新
sudo apt update 2>&1 | head -20

把输出贴出来,我帮你确认源配置是否正确。


:light_bulb: 建议

优先级 方案 耗时
1 修复 apt 源 → apt 安装 10 分钟
2 源码编译 slam_toolbox 30 分钟
3 先测其他功能,slam 后续处理 立即

先执行诊断命令,把输出贴出来,我们快速定位问题!