1、准备工作
需要提前安装Ceres solver和PCL,如果你安装的是完整版ROS那么PCL已经自动安装好了,ceres安装参见我另一篇博客https://blog.csdn.net/weixin_53073284/article/details/125908045?spm=1001.2014.3001.5501;
2、编译和报错
##报错1:error: ‘CV_LOAD_IMAGE_GRAYSCALE’ was not declared in this scope
##报错2:fatal error: opencv/cv.h: No such file or directory
##报错3:报错信息刷屏,这是c++编译器版本不对应引起的
##报错4:运行aloam时只有一条轨迹没有点云信息
mkdir -p aloam_ws/src
cd aloam_ws/src
git clone https://github.com/HKUST-Aerial-Robotics/A-LOAM.git
cd ..
catkin_make
你不想一个个尝试错误的话可以照着下面红色##########改动汇总###########的步骤一步到位
##报错1:改A-LOAM/src/kittiHelper.cpp里的CV_LOAD_IMAGE_GRAYCALE为cv::IMAGE_GRAYCALE
##报错2:改 A-LOAM/src/scanRegistration.cpp里的#include <opencv/cv.h>为#include <opencv2/imgproc.hpp>
##报错3:改A-LOAM下的CMakeLists.txt里的c++11为c++14
##报错4:运行A-LOAM时只有一条绿色的里程计轨迹没有点云信息, 改 A-LOAM/src/下所有/camera_init为camera_init,要改三个cpp文件,laserMapping.cpp和scanRegistration.cpp和laserOdometry.cpp,使用ctrl+h快捷键快速替换
##########改动汇总########### 改完记得重新catkin_make
//改A-LOAM下的CMakeLists.txt
c++11 改为 c++14
//改A-LOAM/src/kittiHelper.cpp
CV_LOAD_IMAGE_GRAYCALE 改为 cv::IMAGE_GRAYCALE //91行和93行
//改A-LOAM/src/scanRegistration.cpp里的
#include <opencv/cv.h> 改为 #include <opencv2/imgproc.hpp>
//改A-LOAM/src/三个cpp文件laserMapping.cpp和scanRegistration.cpp和laserOdometry.cpp
//使用ctrl+h快捷键快速替换
/camera_init 改为 camera_init
3、下载数据集
百度网盘链接链接:https://pan.baidu.com/s/1BBKDanm_q0jULC0XpxWlRA 提取码:7u9n
4、运行aloam
cd ~/aloam_ws
source devel/setup.bash
roslaunch aloam_velodyne aloam_velodyne_VLP_16.launch
//在数据集的下载位置右键新开终端
rosbag play YOUR_DATASET_FOLDER/nsh_indoor_outdoor.bag
5、保存tum格式轨迹方便evo工具评估轨迹误差
在Lassermapping.cpp 228行后添加如下内容,改完记得catkin_make重新编译
//记得改为你的路径
std::ofstream pose1("/home/lds/txt/aloam.txt", std::ios::app);
pose1.setf(std::ios::scientific, std::ios::floatfield);
pose1.precision(15);
Eigen::Matrix3d rotation_matrix;
rotation_matrix = q_w_curr.toRotationMatrix();
Eigen::Matrix<double, 4, 4> myaloam_pose;
myaloam_pose.topLeftCorner(3,3) = rotation_matrix;
myaloam_pose(0,3) = t_w_curr.x();
myaloam_pose(1,3) = t_w_curr.y();
myaloam_pose(2,3) = t_w_curr.z();
Eigen::Matrix3d temp;
temp = myaloam_pose.topLeftCorner(3,3);
Eigen::Quaterniond quaternion(temp);
pose1 << odomAftMapped.header.stamp << " "
<< myaloam_pose_f(0,3) << " "
<< myaloam_pose_f(1,3) << " "
<< myaloam_pose_f(2,3) << " "
<< quaternion.x() << " "
<< quaternion.y() << " "
<< quaternion.z() << " "
<< quaternion.w() << std::endl;
pose1.close();
6、记得把"/home/lds/txt/aloam.txt"改为你的路径,提前在该路径下新建一个名为aloam.txt的文本,ctrl+c结束建图后你可以在aloam.txt看到aloam保存的tum格式轨迹