(25.08)Ubuntu20.04+ROS1复现LIO-SAM
参考大佬文章:IMU+激光雷达融合使用LIO-SAM建图学习笔记——详细、长文、多图、全流程_liosam-CSDN博客
编译
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws/
catkin_make
echo "source ~/catkin_ws/devel/setup.sh" >> ~/.bashrc
编译部分报错记录:
按照上面的文章,编译时也遇见了2.4中的错误,按他的方法来就好。最讨厌的是下面这个,遇到了我就重装了一下ROS..
卸载重装参考:
【ROS】在 Ubuntu 20.04 安装 ROS 的详细教程_ubuntu20.04安装ros-CSDN博客
【详细一次成功】Ubuntu 20.04 安装 ROS 详细教程_ubuntu20.04安装ros-CSDN博客
编译LIO-SAM中catkin_make时遇到的其他报错:(有的忘记截图了。。
1、Cmake版本问题
uang@huang-System-Product-Name:~/catkin_ws$ ls -l ~/catkin_ws/CMakeLists.txt
ls: 无法访问 '/home/huang/catkin_ws/CMakeLists.txt': 没有那个文件或目录
huang@huang-System-Product-Name:~/catkin_ws$ ls -l ~/catkin_ws/src/CMakeLists.txt
lrwxrwxrwx 1 huang huang 49 8月 11 17:25 /home/huang/catkin_ws/src/CMakeLists.txt -> /opt/ros/noetic/share/catkin/cmake/toplevel.cmake
huang@huang-System-Product-Name:~/catkin_ws$ ls -l ~/catkin_ws/src
总用量 0
lrwxrwxrwx 1 huang huang 49 8月 11 17:25 CMakeLists.txt -> /opt/ros/noetic/share/catkin/cmake/toplevel.cmake
huang@huang-System-Product-Name:~/catkin_ws$ catkin_make
Base path: /home/huang/catkin_ws
Source space: /home/huang/catkin_ws/src
Build space: /home/huang/catkin_ws/build
Devel space: /home/huang/catkin_ws/devel
Install space: /home/huang/catkin_ws/install
####
#### Running command: "cmake /home/huang/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/huang/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/huang/catkin_ws/install -G Unix Makefiles" in "/home/huang/catkin_ws/build"
####
CMake Error at CMakeLists.txt:4 (cmake_minimum_required):
Compatibility with CMake < 3.5 has been removed from CMake.Update the VERSION argument <min> value. Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
-- Configuring incomplete, errors occurred!
Invoking "cmake" failed
解决方案:
临时绕过
强制 CMake 接受旧版本语法,通过添加参数:
cd ~/catkin_ws
catkin_make -DCMAKE_POLICY_VERSION_MINIMUM=3.5
这个参数告诉 CMake:“我知道语法旧,但请继续配置。”
2、找不到 ROS 包 tf
的 CMake 配置文件
huang@huang-System-Product-Name:~/catkin_ws$ catkin_make
Base path: /home/huang/catkin_ws
Source space: /home/huang/catkin_ws/src
Build space: /home/huang/catkin_ws/build
Devel space: /home/huang/catkin_ws/devel
Install space: /home/huang/catkin_ws/install
####
#### Running command: "cmake /home/huang/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/huang/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/huang/catkin_ws/install -G Unix Makefiles" in "/home/huang/catkin_ws/build"
####
CMake Deprecation Warning at CMakeLists.txt:4 (cmake_minimum_required):
Compatibility with CMake < 3.10 will be removed from a future version of
CMake.Update the VERSION argument <min> value. Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.
-- Using CATKIN_DEVEL_PREFIX: /home/huang/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /opt/ros/noetic
-- This workspace overlays: /opt/ros/noetic
CMake Warning (dev) at /opt/ros/noetic/share/catkin/cmake/python.cmake:4 (find_package):
Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
are removed. Run "cmake --help-policy CMP0148" for policy details. Use
the cmake_policy command to set the policy and suppress this warning.Call Stack (most recent call first):
/opt/ros/noetic/share/catkin/cmake/all.cmake:164 (include)
/opt/ros/noetic/share/catkin/cmake/catkinConfig.cmake:20 (include)
CMakeLists.txt:58 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.10", minimum required is "3")
-- Using PYTHON_EXECUTABLE: /usr/bin/python3
-- Using Debian Python package layout
-- Using empy: /usr/lib/python3/dist-packages/em.py
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/huang/catkin_ws/build/test_results
-- Forcing gtest/gmock from source, though one was otherwise available.
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
CMake Deprecation Warning at /usr/src/googletest/CMakeLists.txt:4 (cmake_minimum_required):
Compatibility with CMake < 3.10 will be removed from a future version of
CMake.Update the VERSION argument <min> value. Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.
CMake Deprecation Warning at /usr/src/googletest/googlemock/CMakeLists.txt:45 (cmake_minimum_required):
Compatibility with CMake < 3.10 will be removed from a future version of
CMake.Update the VERSION argument <min> value. Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.
CMake Deprecation Warning at /usr/src/googletest/googletest/CMakeLists.txt:56 (cmake_minimum_required):
Compatibility with CMake < 3.10 will be removed from a future version of
CMake.Update the VERSION argument <min> value. Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.
CMake Warning (dev) at /usr/src/googletest/googletest/cmake/internal_utils.cmake:249 (find_package):
Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modules
are removed. Run "cmake --help-policy CMP0148" for policy details. Use
the cmake_policy command to set the policy and suppress this warning.Call Stack (most recent call first):
/usr/src/googletest/googletest/CMakeLists.txt:91 (include)
This warning is for project developers. Use -Wno-dev to suppress it.-- Found PythonInterp: /usr/bin/python3 (found version "3.8.10")
-- Using Python nosetests: /usr/bin/nosetests3
-- catkin 0.8.12
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 1 packages in topological order:
-- ~~ - lio_sam
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'lio_sam'
-- ==> add_subdirectory(LIO-SAM)
CMake Deprecation Warning at LIO-SAM/CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 3.10 will be removed from a future version of
CMake.Update the VERSION argument <min> value. Or, use the <min>...<max> syntax
to tell CMake that the project requires at least <min> but has been updated
to work with policies introduced by <max> or earlier.
CMake Warning (dev) at LIO-SAM/CMakeLists.txt:4 (find_package):
Policy CMP0167 is not set: The FindBoost module is removed. Run "cmake
--help-policy CMP0167" for policy details. Use the cmake_policy command to
set the policy and suppress this warning.This warning is for project developers. Use -Wno-dev to suppress it.
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0") found components: timer thread serialization chrono
-- Could NOT find tf (missing: tf_DIR)
-- Could not find the required component 'tf'. The following CMake error indicates that you either need to install the package with the same name or change your environment so that it can be found.
CMake Error at /opt/ros/noetic/share/catkin/cmake/catkinConfig.cmake:83 (find_package):
Could not find a package configuration file provided by "tf" with any of
the following names:tfConfig.cmake
tf-config.cmakeAdd the installation prefix of "tf" to CMAKE_PREFIX_PATH or set "tf_DIR" to
a directory containing one of the above files. If "tf" provides a separate
development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
LIO-SAM/CMakeLists.txt:10 (find_package)
-- Configuring incomplete, errors occurred!
Invoking "cmake" failed
错误核心
CMake Error at ... catkinConfig.cmake:83 (find_package):Could not find a package configuration file provided by "tf"
原因
你正在编译的
lio_sam
包依赖tf
,但你的系统中没有安装tf
对应的 ROS 包。解决方法
在 ROS Noetic 中,
tf
功能由tf
包提供(ROS 1 中),需要安装:sudo apt update sudo apt install ros-noetic-tf
验证安装是否成功
安装完后,你可以运行:
rospack find tf
如果输出路径如
/opt/ros/noetic/share/tf
,就说明安装成功。重新编译即可
3、PCL 与 C++17 不兼容导致的编译错误
CMakeLists.txt
中并没有显式设置CMAKE_CXX_STANDARD
,但默认使用了 C++11,这在 Ubuntu 20.04 + PCL 1.10 下仍然可能触发 C++17 不兼容问题(尤其是模板元编程部分)。
解决方法
在
CMakeLists.txt
顶部添加一行:(放这也行?)set(CMAKE_CXX_STANDARD 14)
放在
project(lio_sam)
之后即可:cmake_minimum_required(VERSION 2.8.3) project(lio_sam)set(CMAKE_CXX_STANDARD 14) # 添加这一行
然后重新编译
4、链接失败,而不是编译失败:
找不到
LZ4_resetStreamHC
、LZ4_compress_HC_continue
等符号
这些是 liblz4-dev 提供的函数,没有被正确链接
解决方法
需要安装并链接 liblz4:
安装 liblz4-dev
sudo apt update sudo apt install liblz4-dev
在
CMakeLists.txt
中显式链接 lz4找到
lio_sam_mapOptmization
的target_link_libraries
行,加上lz4
:target_link_libraries(${PROJECT_NAME}_mapOptmizationBoost::timer${catkin_LIBRARIES}${PCL_LIBRARIES}${OpenCV_LIBRARIES}${OpenMP_CXX_FLAGS}gtsamlz4 # 添加这一行 )
重新编译
TIPS:
一定要看清楚!!!!是map..的大括号里面,我一开始看错了,放到最后i一个大括号里,然后一直报错,仍然报错,还是以为liblz4 没有被正确链接,或者链接顺序不对,还换了以下两种指定的方式,还是不行,最后才发现是位置看错了。。。。
强制指定链接库名
${LZ4_LIBRARY}
手动链接 liblz4.so,直接显式指定库路径
/usr/lib/x86_64-linux-gnu/liblz4.so
编译成功!!!
运行
roslaunch lio_sam run.launch
报错:
1、缺少xacro
包
launch 文件里用到了
xacro
,但你的系统里没有安装这个包。解决方法
sudo apt update sudo apt install ros-noetic-xacro
安装完成后,再次运行:
roslaunch lio_sam run.launch
即可正常启动。
2、缺少包
启动日志显示:
LIO-SAM 的核心节点都已正常启动
lio_sam_imuPreintegration lio_sam_imageProjection lio_sam_featureExtraction lio_sam_mapOptmization
缺失两个可选节点
robot_state_publisher rviz
解决方法:
安装缺失包
这两个节点不是 LIO-SAM 算法的必需组件,但可视化/机器人模型需要:
sudo apt update sudo apt install ros-noetic-robot-state-publisher ros-noetic-rviz
继续运行
节点已经在跑,算法已经开始处理数据。
如果想看可视化,再开一个终端:
rviz
或
roslaunch lio_sam rviz.launch # 如果包里提供了
运行成功,弹出空的RVIZ窗口!!!
运行示例数据集
数据集:https://drive.google.com/drive/folders/1gJHwfdHCRdjP7vuT556pv8atqrCJPbUq
另开一个终端:
# (替换为你的文件名)
rosbag play ~/catkin_ws/datasets/lio_sam_dataset/livox_horizon.bag
红色报错参考文章中出现了。
黄色警告是因为数据集的问题,一开始想下个小一点的,下了livox_horizon.bag,但是
LIO-SAM 官方默认参数是针对 Velodyne 16/32/64 线 激光雷达调好的,
而用的是Livox Horizon(固态 96°×25° FOV),两者之间差异很大:
扫描方式:Velodyne 是 旋转式,Livox 是 固态花瓣式 → 点云密度分布完全不同
线数:Horizon 非均匀线束,边缘点极少 → 日志里 “Only 4 edge …” 正是因此
时间戳:Livox 自带 0.1 s 的扫描周期,需要 自定义时间偏移
换一个数据集walking_dataset.bag:
rosbag play ~/catkin_ws/datasets/lio_sam_dataset/walking_dataset.bag
可视化
按照置顶文章修改配置文件等后,运行(按需修改文件名)
pcl_viewer GlobalMap.pcd