在我第一篇博文Ubuntu 20.04配置ORB-SLAM2和ORB-SLAM3运行环境+ROS实时运行ORB-SLAM2+Gazebo仿真运行ORB-SLAM2+各种相关库的安装的基础环境下跑通LOAM系列
首先按照上一篇文章已经安装好了ROS noetic、Eigen3.4.0、OpenCV4.2.0和PCL1.10等三方库,它们的安装不再赘述,另外文章中使用的数据已经在评论区分享
A-LOAM在Github的开源地址:https://github.com/HKUST-Aerial-Robotics/A-LOAM。接下来根据代码要求,需要安装Ceres,另外环境的变化导致源码不能编译通过,需要修改源码
(1)下载源码包
参考Github,点击Follow Ceres Installation转到安装网站,点击You can start with the latest stable release,直接把Ceres包给下载下来。
(2)安装依赖
#CMake(已安装)
sudo apt-get install cmake
#google-glog + gflags
sudo apt-get install libgoogle-glog-dev libgflags-dev
#Use ATLAS for BLAS & LAPACK
sudo apt-get install libatlas-base-dev
#Eigen3(已安装)
sudo apt-get install libeigen3-dev
#SuiteSparse and CXSparse (optional)
sudo apt-get install libsuitesparse-dev
(3)编译源码并安装
在安装包目录下:
tar zxf ceres-solver-2.1.0.tar.gz
mkdir ceres-bin
cd ceres-bin
cmake ../ceres-solver-2.1.0
make -j4
make test
#Optionally install Ceres, it can also be exported using CMake which
#allows Ceres to be used without requiring installation, see the documentation
#for the EXPORT_BUILD_DIR option for more information.
sudo make install
(4)测试
ceres-bin目录下运行下面例子:
bin/simple_bundle_adjuster ../ceres-solver-2.1.0/data/problem-16-22106-pre.txt
#set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS "-std=c++14")
#find_package(OpenCV REQUIRED)
set(CMAKE_PREFIX_PATH "/usr/include/opencv4")
find_package(OpenCV 4.0 QUIET)
在原来的工作空间或新建工作空间下,将修改的源功能包移动到~/catkin_ws/src,编译:
cd ~/catkin_ws/src
cd ../
catkin_make
#可添加到 ~/.bashrc 文件中:
source ~/catkin_ws/devel/setup.bash
下载nsh_indooroutdoor.bag测试数据,打开终端输入下面代码开始运行:
roslaunch aloam_velodyne aloam_velodyne_VLP_16.launch
再打开一个终端记录地图
rosbag record -o bag_out /laser_cloud_map
在nsh_indooroutdoor.bag所在文件夹下打开终端,开始播放数据集:
rosbag play nsh_indoor_outdoor.bag
跑完之后ctrl+c关闭记录地图的终端会生成一个bag文件,将其转化为pcd格式
rosrun pcl_ros bag_to_pcd bag_out_xxxx.bag /laser_cloud_map pcd
在生成的文件夹pcd目录下,使用pcl_viewer工具打开点云,last.pcd为最后一个pcd文件名:
pcl_viewer last.pcd
A-LOAM运行KITTI数据集需要运行kittiHelper节点,首先要将KITTI数据转换成ROS 的 Topic 或者 rosbag,读取KITTI数据集的 图像\雷达\时间戳 并发布topic和保存bag,跑之前修改launch文件:
<launch>
<node name="kittiHelper" pkg="aloam_velodyne" type="kittiHelper" output="screen">
<param name="dataset_folder" type="string" value="/data/KITTI/odometry/" />
<param name="sequence_number" type="string" value="00" />
<param name="to_bag" type="bool" value="false" />
<param name="output_bag_file" type="string" value="/tmp/kitti.bag" />
<param name="publish_delay" type="int" value="1" />
node>
launch>
其中/data/KITTI/odometry/修改为kitti数据集的路径,to_bag的值可以为false或者true,选择是否将kitti数据集计算轨迹的同时打包成bag输出,输出路径为out_bag_file的值。以上文件夹路径部分需要根据自己的电脑路径进行修改,均使用绝对路径。publish_delay为发布延时。kitti 数据集的文件结构,注意这个和程序里面的路径设置有关,不一致则读不到数据(可修改源码读自己安排的路径):
—kitti_data
------poses
---------00.txt
------sequence
---------00
------------image_0
------------------000000.png
------------image_1
------------------000000.png
------------calib.txt
------------times.txt
------velodye
---------sequence
------------00
---------------velodye
------------------000000.bin
上述文件目录中,poses文件夹下存放的是路径真值,sequences文件夹下是00文件夹,00文件夹下是图片image_0、image_1和时间戳time.txt,veledyne存放的是64线激光雷达数据,为bin文件,在后面的计算中,只使用的velodyne的数据,其它的数据在rviz中用作显示。
修改好之后,运行launch文件,打开rviz逐帧显示KITTI数据集:
roslaunch aloam_velodyne kitti_helper.launch
roslaunch aloam_velodyne kitti_helper.launch
roslaunch aloam_velodyne aloam_velodyne_HDL_64.launch
将下载好的LeGO-LOAM源码放入建立好的ros工作空间下,接下来需要安装gtsam以及修改源码,使其能够在上述环境下运行(参考文章)
wget -O ~/Downloads/gtsam.zip https://github.com/borglab/gtsam/archive/4.0.0-alpha2.zip
cd ~/Downloads/ && unzip gtsam.zip -d ~/Downloads/
cd ~/Downloads/gtsam-4.0.0-alpha2/
mkdir build && cd build
cmake ..
make
sudo make install
与A-LOAM一样:
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")
set(CMAKE_CXX_FLAGS "-std=c++14")
#find_package(OpenCV REQUIRED QUIET)
set(CMAKE_PREFIX_PATH "/usr/include/opencv4")
find_package(OpenCV 4.0 QUIET)
-如果出现错误
/usr/bin/ld: cannot find -lBoost::serialization
/usr/bin/ld: cannot find -lBoost::thread
加入:
find_package(Boost REQUIRED COMPONENTS timer thread serialization chrono)
(1)找到utility.h中的:#include
#include
(2)将四个.cpp文件中的/camera_init修改为camera_init
cd ~/catkin_ws/src
git clone https://github.com/RobustFieldAutonomyLab/LeGO-LOAM.git
cd ..
catkin_make -j1
第一次编译代码时,需要在“catkin_make”后面加上“-j1”来生成一些消息类型。以后的编译不需要“-j1”
/usr/include/pcl-1.10/pcl/filters/voxel_grid.h:340:21: error: ‘Index’ is not a member of ‘Eigen’ 340 | for (Eigen::Index ni = 0; ni < relative_coordinates.cols (); ni++)
将voxel_grid.h中(340/669行)报错的 Eigen::Index 修改成int:
sudo gedit /usr/include/pcl-1.10/pcl/filters/voxel_grid.h
for (Eigen::Index ni = 0; ni < relative_coordinates.cols (); ni++)
-> for (int ni = 0; ni < relative_coordinates.cols (); ni++)
运行:
roslaunch lego_loam run.launch
播放数据集,虽然/imu/data 是可选的,但如果提供它可以大大提高估计精度:
rosbag play *.bag --clock --topic /velodyne_points /imu/data
[mapOptmization-7] process has died [pid 14493, exit code 127, cmd
/home/zard/catkin_ws/devel/lib/lego_loam/mapOptmization __name:=mapOptmization __log:
=/home/zard/.ros/log/922c7a94-0354-11ed-951b-8d0be314719f/mapOptmization-7.log].
原因是未安装 libmetis 库。通过安装libparmetis-dev修复它重新运行即可:
sudo apt-get install libparmetis-dev
roslaunch lego_loam run.launch
rosbag play nsh_indoor_outdoor.bag --clock --topic /velodyne_points
最后生成的点云及轨迹结果会默认保存到/tmp/文件夹下,如果需要更改保存位置,就修改头文件utility.h:
extern const string fileDirectory = "/tmp/";
将下载好的LIO-SAM源码放入建立好的ros工作空间下,需要的依赖上面都安装过了,接下来需要修改源码,使其能够在上述环境下运行
与上面一样,修改一下几项:
#set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS "-std=c++14")
#find_package(OpenCV REQUIRED QUIET)
set(CMAKE_PREFIX_PATH "/usr/include/opencv4")
find_package(OpenCV 4.0 QUIET)
# find_package(Boost REQUIRED COMPONENTS timer)
find_package(Boost REQUIRED COMPONENTS timer thread serialization chrono)
// #include
#include
cd ~/catkin_ws
catkin_make -j1
运行launch文件:
roslaunch lio_sam run.launch
播放数据包(根据电脑性能自行选择频率):
rosbag play park_dataset.bag -r 3
sudo apt-get install ros-noetic-fake-localization
sudo apt-get install ros-noetic-robot-localization
如果要保存点云及轨迹等结果,在参数文件params.yaml中打开并修改保存路径:
savePCD: true
savePCDDirectory: "/Downloads/LIOSAM/"
将下载好的LVI-SAM源码放入建立好的ros工作空间下,同样的,LVI-SAM依赖的gtsam和ceres上面都安装过了,接下来需要修改源码,使其能够在上述环境下运行
#set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS "-std=c++14")
#find_package(OpenCV REQUIRED QUIET)
set(CMAKE_PREFIX_PATH "/usr/include/opencv4")
find_package(OpenCV 4.0 QUIET)
# find_package(Boost REQUIRED COMPONENTS filesystem program_options system timer)
find_package(Boost REQUIRED COMPONENTS filesystem program_options system timer thread serialization chrono)
cd ~/catkin_ws
catkin_make -j1
error: ‘ScalarBinaryOpTraits’ is not a class template
出现这个问题的原因是当前版本ceres需要eigen版本>=3.3,但是我们安装的eigen明明是3.4.0啊!!?这里没有查到解决办法。我参考其他版本的ceres的jet.h文件,在其相应代码区域添加 #if–#endif 约束,不知道这样会不会对其他代码有影响,但总算是编译通过了
// file:/usr/local/include/ceres/jet.h
#if EIGEN_VERSION_AT_LEAST(3, 3, 0)
// Specifying the return type of binary operations between Jets and scalar types
// allows you to perform matrix/array operations with Eigen matrices and arrays
// such as addition, subtraction, multiplication, and division where one Eigen
// matrix/array is of type Jet and the other is a scalar type. This improves
// performance by using the optimized scalar-to-Jet binary operations but
// is only available on Eigen versions >= 3.3
template <typename BinaryOp, typename T, int N>
struct ScalarBinaryOpTraits<ceres::Jet<T, N>, T, BinaryOp> {
using ReturnType = ceres::Jet<T, N>;
};
template <typename BinaryOp, typename T, int N>
struct ScalarBinaryOpTraits<T, ceres::Jet<T, N>, BinaryOp> {
using ReturnType = ceres::Jet<T, N>;
};
#endif // EIGEN_VERSION_AT_LEAST(3, 3, 0)
error: ‘CV_RGB2GRAY’ was not declared in this scope
这是opencv2的用法,现在opencv3和4是COLOR_GARY2BGR,因此将代码中的CV_GRAY2BGR改成COLOR_GRAY2BGR:
// cv::cvtColor(image, aux, CV_RGB2GRAY);
cv::cvtColor(image, aux, cv::COLOR_GRAY2BGR);
运行launch文件:
roslaunch lvi_sam run.launch
播放数据包:
rosbag play handheld.bag
示例数据的传感器套件包括:
LiDAR: Velodyne VLP-16
Camera: FLIR BFS-U3-04S2M-CS
IMU: MicroStrain 3DM-GX5-25
GPS: Reach RS+
保存结果的方式与LIO-SAM一样,修改参数配置文件。