前言
A-LOAM(Advanced implementation of Lidar Odometry And Mapping)是香港科技大学空中机器人团队基于 LOAM 论文重写的激光SLAM系统。它使用Eigen + Ceres Solver替代了原始 LOAM 中复杂的手动求导,代码结构清晰,是3D激光SLAM入门的最佳选择。
GitHub: https://github.com/HKUST-Aerial-Robotics/A-LOAM
1. 系统环境要求
| 项目 | 要求 | 说明 |
|---|---|---|
| 操作系统 | Ubuntu 18.04 / 20.04 LTS | 本文以 Ubuntu 20.04 为例 |
| ROS | Melodic / Noetic | 必须 |
| C++ 标准 | C++14 | Ceres 1.14 要求 |
| CMake | 3.3.2+ | |
| 内存 | 4GB+ | KITTI 数据集需 8GB+ |
| 显卡 | 无要求 | 纯CPU计算 |
2. 依赖库全景图
A-LOAM 依赖体系 ├── ROS Noetic(通信 + 可视化 + 点云工具) │ ├── roscpp, rospy —— C++/Python通信 │ ├── sensor_msgs —— 传感器消息定义 │ ├── nav_msgs —— Path/Odometry消息 │ ├── pcl_ros / pcl_conversions —— PCL与ROS桥接 │ ├── tf / tf2 —— 坐标变换 │ └── rviz —— 3D可视化 ├── Ceres Solver 1.14.0 —— 非线性优化(必须 1.14.x!) │ ├── Eigen3 —— 线性代数 │ ├── gflags / glog —— 命令行/日志 │ ├── suitesparse —— 稀疏矩阵求解 │ └── lapack / blas —— 线性代数底层 ├── PCL 1.10+ —— 点云处理(KD-Tree、体素滤波) └── OpenCV(可选) —— 仅 kittiHelper 需要⚠️最重要的坑:Ceres 版本必须是1.14.x。其他版本(1.13、2.0、2.1、2.2)都会导致 A-LOAM 编译失败或运行异常。
3. 第一步:安装 ROS Noetic
# 添加 ROS 源sudosh-c'echo "deb http://packages.ros.org/ros/ubuntu focal main" > /etc/apt/sources.list.d/ros-latest.list'# 添加密钥sudoaptinstallcurlcurl-shttps://raw.githubusercontent.com/ros/rosdistro/master/ros.asc|sudoapt-keyadd-# 更新并安装sudoaptupdatesudoaptinstall-yros-noetic-desktop-full# 初始化 rosdepsudorosdep init rosdep update# 设置环境变量echo"source /opt/ros/noetic/setup.bash">>~/.bashrcsource~/.bashrc4. 第二步:安装 PCL 和基础依赖
# PCL 点云库(Ubuntu 20.04 自带 PCL 1.10)sudoaptinstall-ylibpcl-dev pcl-tools# ROS 中的 PCL 桥接包sudoaptinstall-yros-noetic-pcl-ros ros-noetic-pcl-conversions\ros-noetic-pcl-msgs# 可视化sudoaptinstall-yros-noetic-rviz ros-noetic-rqt# 基础工具sudoaptinstall-ybuild-essential cmakegitsudoaptinstall-ylibeigen3-dev libboost-all-dev# OpenCV(kittiHelper 需要)sudoaptinstall-ylibopencv-dev5. 第三步:编译安装 Ceres Solver 1.14.0
这是最容易出错的步骤,务必严格按以下命令操作。
# 下载 Ceres 1.14.0 源码wgethttp://ceres-solver.org/ceres-solver-1.14.0.tar.gztar-zxvfceres-solver-1.14.0.tar.gzcdceres-solver-1.14.0# 安装编译依赖sudoaptinstall-yliblapack-dev libsuitesparse-dev\libcxsparse3 libgflags-dev\libgoogle-glog-dev libgtest-dev# 编译安装mkdirbuild&&cdbuild cmake..-DCMAKE_BUILD_TYPE=Releasemake-j$(nproc)sudomakeinstall# 验证安装ls/usr/local/lib/libceres.a# 应该存在ls/usr/local/include/ceres/# 应该有头文件为什么不能用 apt 安装?
sudo apt install libceres-dev在 Ubuntu 20.04 上安装的是 Ceres 2.0,与 A-LOAM 不兼容。
Ceres 版本不匹配的典型报错
error: 'class ceres::LocalParameterization' has no member named 'Set' error: 'ceres::Problem::Options' has no member named 'local_parameterization_ownership'如果遇到这些错误,说明 Ceres 版本不对。卸载重装 1.14.0:
# 卸载系统安装的 Ceressudoaptremove libceres-devsudorm-f/usr/local/lib/libceres*sudorm-rf/usr/local/include/ceressudorm-f/usr/local/lib/cmake/Ceres/6. 第四步:创建工作空间并编译 A-LOAM
# 创建工作空间mkdir-p~/catkin_ws/srccd~/catkin_ws/src# 克隆 A-LOAMgitclone https://github.com/HKUST-Aerial-Robotics/A-LOAM.git# 编译cd~/catkin_ws catkin_make# 设置环境变量echo"source ~/catkin_ws/devel/setup.bash">>~/.bashrcsource~/.bashrcUbuntu 20.04 OpenCV 4.x 兼容性修复
如果在 Ubuntu 20.04 上遇到 OpenCV 相关编译错误:
# 修改 CMakeLists.txt,添加准确的 OpenCV 查找路径# 在 find_package(OpenCV REQUIRED) 之前添加:sed-i's/find_package(OpenCV REQUIRED)/set(OpenCV_DIR "\/usr\/lib\/x86_64-linux-gnu\/cmake\/opencv4")\nfind_package(OpenCV REQUIRED)/'~/catkin_ws/src/A-LOAM/CMakeLists.txt或者直接禁用 kittiHelper(非必须模块):
# 在 CMakeLists.txt 中注释掉 kittiHelper 的编译# add_executable(kittiHelper src/kittiHelper.cpp)7. 第五步:下载测试数据集
KITTI 数据集(推荐,HDL-64激光雷达)
# 下载 KITTI Odometry 数据集序列00(约 4GB)wgethttps://s3.eu-central-1.amazonaws.com/avg-kitti/raw_data/2011_10_03_drive_0027/2011_10_03_drive_0027_sync.zipunzip2011_10_03_drive_0027_sync.zip# 将 KITTI 数据转为 ROS bag# 修改 kittiHelper.cpp 中的路径后编译运行:# rosrun aloam_velodyne kittiHelperNSH 数据集(VLP-16,体积小适合快速测试)
原始论文使用的小型室内外数据集,可从 NSH 官方下载或使用其他 VL-16 数据替代。
8. 第六步:运行测试
VLP-16 模式
# 终端1:启动 A-LOAMroslaunch aloam_velodyne aloam_velodyne_VLP_16.launch# 终端2:播放数据包rosbag play YOUR_BAG_FILE.bag--clockHDL-64 模式(KITTI)
# 终端1:启动 A-LOAMroslaunch aloam_velodyne aloam_velodyne_HDL_64.launch# 终端2:播放 KITTI bagrosbag play kitti_2011_10_03_drive_0027_synced.bag--clock-r1运行成功后,RViz 中会显示:
- 白色点云:当前帧面点(surf)
- 彩色点云:当前帧角点(corner)
- 彩色线条:里程计轨迹
- 绿色线条:建图轨迹
- 彩色大点云:全局地图
9. 运行 rosbag 数据集的注意事项
9.1 使用 --clock 参数
# 必须加 --clock,否则 A-LOAM 使用系统时间会出问题rosbag play xxx.bag--clock# 控制播放速度rosbag play xxx.bag--clock-r1# 正常速度rosbag play xxx.bag--clock-r0.5# 半速(给算法更多处理时间)9.2 查看轨迹
# 订阅 odometry 话题rostopicecho/aft_mapped_path# 使用 rqt 可视化轨迹rqt_plot /aft_mapped_path/pose/pose/position/x:y:z10. 常见问题排查
问题1:Ceres 版本不兼容
error: no matching function for call to 'ceres::Problem::AddResidualBlock(...)'解决:严格安装 Ceres 1.14.0,参见上文第三节。
问题2:找不到 PCL 包
Could not find a package configuration file provided by "PCL"解决:
sudoaptinstall-ylibpcl-dev ros-noetic-pcl-ros问题3:编译时 OpenCV 冲突
undefined reference to cv::imread(...)解决:Ubuntu 20.04 自带 OpenCV 4.2,需要在 CMakeLists.txt 中正确指定:
find_package(OpenCV 4 REQUIRED)问题4:运行时点云不显示
- 检查
/velodyne_points话题是否有数据:rostopic hz /velodyne_points - 检查 RViz 中的 Fixed Frame 是否设置为
camera_init - 确保 rosbag 播放时加了
--clock参数
问题5:轨迹漂移严重
- 检查 LiDAR 内参是否正确(launch 文件中的
scan_line等参数) - KITTI 序列中车辆掉头时漂移严重,这是 LOAM 的无回环特性导致的正常现象
- 考虑使用 LeGO-LOAM 或 LIO-SAM 获得更好的效果
11. 可选:Docker 安装(免环境配置)
A-LOAM 官方提供了 Docker 支持:
cd~/catkin_ws/src/A-LOAM/dockermakebuild# 启动 Docker 容器./run.sh16# VLP-16 模式./run.sh64# HDL-64 模式# 然后在容器内播包测试12. A-LOAM vs ORB-SLAM 安装对比
| 对比项 | ORB-SLAM2/3 | A-LOAM |
|---|---|---|
| 传感器 | 相机 | 激光雷达 |
| 框架依赖 | 独立可执行文件 | 必须 ROS |
| 核心优化库 | g2o(自带) | Ceres 1.14(手动安装) |
| 可视化 | Pangolin(手动安装) | RViz(ROS自带) |
| OpenCV | 必须(3.x或4.x) | 可选(仅数据转换) |
| 编译时间 | ~10-15分钟 | ~5-10分钟 |
| 安装难度 | ★★★ | ★★(主要坑在Ceres版本) |
总结
| 步骤 | 操作 | 时间 |
|---|---|---|
| 安装 ROS Noetic | apt install | 10-20分钟 |
| 安装 PCL + 基础依赖 | apt install | 5分钟 |
| 编译 Ceres 1.14.0 | 下载+编译+安装 | 15-30分钟 |
| 编译 A-LOAM | catkin_make | 5-10分钟 |
| 下载测试数据 | 取决于网速 | 10-30分钟 |
整个流程约40分钟至1.5小时。核心坑点只有一个——Ceres 版本必须是 1.14.x。掌握这一点,安装基本不会出问题。