从零到端到端自动驾驶实战-Pjoject2-第 1 章-环境搭建-CARLA-ROS2 集成
一、开发环境

这里我们用 智星云 的运算力服务,购买 3080显卡,0.7元/小时;
https://gpu.ai-galaxy.cn/console/dashboard
检查NVIDIA 驱动
检查驱动,查看 nvidia-smi 配置, 智星云默认已经装好了驱动。
(base) root@ubuntu22:~# nvidia-smi
Fri Jun 19 10:53:50 2026
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.78 Driver Version: 550.78 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 3080 Off | 00000000:00:08.0 Off | N/A |
| 30% 24C P8 14W / 320W | 10MiB / 10240MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| 0 N/A N/A 711 G /usr/lib/xorg/Xorg 4MiB |
+-----------------------------------------------------------------------------------------+
(base) root@ubuntu22:~#
查看CUDA:
# 验证 CUDA
# apt-get update
# apt install nvidia-cuda-toolkit
# 如果没有nvcc命令,则执行上边的命令:
nvcc --version
# 打印
(base) root@ubuntu22:~# nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Thu_Nov_18_09:45:30_PST_2021
Cuda compilation tools, release 11.5, V11.5.119
Build cuda_11.5.r11.5/compiler.30672275_0
(base) root@ubuntu22:~#
二、安装ROS2 Humble
ROS2 Humble 是我们今年(2026)的主力版本,官方支持到 2027 年 5 月。
2.1 添加 ROS2 软件源
# 确保 locale 是 UTF-8
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
# 添加 universe 源
sudo apt install software-properties-common
sudo add-apt-repository universe
# 添加 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
# 添加 ROS2 源到 apt 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
2.2 安装 ROS2 Humble 完整版
sudo apt update
sudo apt upgrade -y
# desktop-full 包含 RViz2, demos, 教学的例子等
sudo apt install ros-humble-desktop-full -y
# 安装 colcon (ROS2 编译工具)
sudo apt install python3-colcon-common-extensions -y
# 安装 rosdep (依赖管理)
sudo apt install python3-rosdep -y
sudo rosdep init
rosdep update
# 配置环境变量
echo 'source /opt/ros/humble/setup.bash' >> ~/.bashrc
source ~/.bashrc
为者常成,行者常至
自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)