当前位置: 首页 > news >正文

使用ros2跑mid360的fastlio2算法详细教程

1、ROS2-Humble系统要求使用Ubuntu 22.04版本,所以需要先安装虚拟机。ubuntu镜像可以从这里下载:ubuntu-releases-22.04安装包下载_开源镜像站-阿里云

2、安装完Ubuntu后进入系统,按照ROS2的官方文档安装Humble版本:Ubuntu (deb packages) — ROS 2 Documentation: Humble documentation

3、编译并安装Livox-mid360的驱动库:Livox-SDK/Livox-SDK2: Drivers for receiving LiDAR data and controlling lidar, support Lidar HAP and Mid-360.

第一步:

  • 先安装CMAKE库$ sudo apt install cmake
  •  然后$ gcc -v 确认一下gcc版本大于4.8.1
  • 执行如下命令克隆、编译、安装库,安装完成后 .a和.so库在 /usr/local/lib目录下,头文件在/usr/local/include目录下。
$ git clone https://github.com/Livox-SDK/Livox-SDK2.git
$ cd ./Livox-SDK2/
$ mkdir build
$ cd build
$ cmake .. && make -j
$ sudo make install
  •  cmake .. && make -j:这一步如果报错

    CMake Error at CMakeLists.txt:1 (cmake_minimum_required):Compatibility with CMake < 3.5 has been removed from CMake.Update the VERSION argument <min> value.  Or, use the <min>...<max> syntaxto tell CMake that the project requires at least <min> but has been updatedto work with policies introduced by <max> or earlier.Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.
    

    解决办法:cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 .. && make -j
    运行上面的指令,因为cmake版本过高

第二步

安装ROS2系统的编译工具colcon$ sudo apt install python3-colcon-common-extensions

第三步

新建ros_ws文件夹作为ROS2的工作目录,并在目录下新建src文件存放套件源码

$ mkdir -p ros_ws/src/
$ cd ros_ws/src/

4.克隆livox_ros_driver2 到src目录

git clone https://github.com/Livox-SDK/livox_ros_driver2.git

5编译驱动

source /opt/ros/humble/setup.sh
./build.sh humble

~/mid360/ros_ws/src/livox_ros_driver2一般在这个目录下可以找到build.sh

6.修改ros_ws/install/livox_ros_driver2/share/livox_ros_driver2/config/MID360_config.json中的本机ip和设备ip,然后执行下命令运行测试程序,成功后会在右侧显示雷达扫描的点云图。!!!!!!!!非常重要,参考下图的来修改

{"lidar_summary_info" : {"lidar_type": 8},"MID360": {"lidar_net_info" : {"cmd_data_port": 56100,"push_msg_port": 56200,"point_data_port": 56300,"imu_data_port": 56400,"log_data_port": 56500},"host_net_info" : {"cmd_data_ip" : "192.168.1.50",//全部改成这个"cmd_data_port": 56101,"push_msg_ip": "192.168.1.50","push_msg_port": 56201,"point_data_ip": "192.168.1.50","point_data_port": 56301,"imu_data_ip" : "192.168.1.50","imu_data_port": 56401,"log_data_ip" : "","log_data_port": 56501}},"lidar_configs" : [{"ip" : "192.168.1.188",//最后俩位查看雷达的sn码来修改"pcl_data_type" : 1,"pattern_mode" : 0,"extrinsic_parameter" : {"roll": 0.0,"pitch": 0.0,"yaw": 0.0,"x": 0,"y": 0,"z": 0}}]
}
source ../../install/setup.sh
ros2 launch livox_ros_driver2 rviz_MID360_launch.py

运行之后就可以得到点云图

  • 将soruce命令加入到用户目录的.bashrc文件末尾,这样就不用每次运行ros launch都要source了source ~/ros_ws/install/setup.bash

跑fastlio2算法包

    cd ros_ws/src # cd into a ros2 workspace foldergit clone https://github.com/Ericsii/FAST_LIO.git --recursivecd ..rosdep install --from-paths src --ignore-src -ycolcon build --symlink-install     //务必使用这个来编译,其他指令很容易报错. ./install/setup.bash # use setup.zsh if use zsh

注意在    colcon build --symlink-install这个步骤,可能会产生一个编译错误

sky@sky:~/mid360/ros_ws$ colcon build --symlink-install
Starting >>> livox_ros_driver2
--- stderr: livox_ros_driver2                         
CMake Warning (dev) at /usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:146 (find_package):Policy CMP0144 is not set: find_package uses upper-case <PACKAGENAME>_ROOTvariables.  Run "cmake --help-policy CMP0144" for policy details.  Use thecmake_policy command to set the policy and suppress this warning.CMake variable EIGEN_ROOT is set to:/usr/include/eigen3For compatibility, find_package is ignoring the variable, but code in a.cmake module might still use it.
Call Stack (most recent call first):/usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:299 (find_eigen)/usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:543 (find_external_library)/opt/ros/humble/share/pcl_conversions/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package)/opt/ros/humble/share/pcl_conversions/cmake/pcl_conversionsConfig.cmake:41 (include)/opt/ros/humble/share/ament_cmake_auto/cmake/ament_auto_find_build_dependencies.cmake:67 (find_package)CMakeLists.txt:225 (ament_auto_find_build_dependencies)
This warning is for project developers.  Use -Wno-dev to suppress it.CMake Warning (dev) at /usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:128 (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 toset the policy and suppress this warning.Call Stack (most recent call first):/usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:297 (find_boost)/usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:543 (find_external_library)/opt/ros/humble/share/pcl_conversions/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package)/opt/ros/humble/share/pcl_conversions/cmake/pcl_conversionsConfig.cmake:41 (include)/opt/ros/humble/share/ament_cmake_auto/cmake/ament_auto_find_build_dependencies.cmake:67 (find_package)CMakeLists.txt:225 (ament_auto_find_build_dependencies)
This warning is for project developers.  Use -Wno-dev to suppress it.CMake Warning (dev) at /usr/lib/x86_64-linux-gnu/cmake/pcl/Modules/FindFLANN.cmake:44 (find_package):Policy CMP0144 is not set: find_package uses upper-case <PACKAGENAME>_ROOTvariables.  Run "cmake --help-policy CMP0144" for policy details.  Use thecmake_policy command to set the policy and suppress this warning.CMake variable FLANN_ROOT is set to:/usrFor compatibility, find_package is ignoring the variable, but code in a.cmake module might still use it.
Call Stack (most recent call first):/usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:256 (find_package)/usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:301 (find_flann)/usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:543 (find_external_library)/opt/ros/humble/share/pcl_conversions/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package)/opt/ros/humble/share/pcl_conversions/cmake/pcl_conversionsConfig.cmake:41 (include)/opt/ros/humble/share/ament_cmake_auto/cmake/ament_auto_find_build_dependencies.cmake:67 (find_package)CMakeLists.txt:225 (ament_auto_find_build_dependencies)
This warning is for project developers.  Use -Wno-dev to suppress it.CMake Warning (dev) at /usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:128 (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 toset the policy and suppress this warning.Call Stack (most recent call first):/usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:297 (find_boost)/usr/lib/x86_64-linux-gnu/cmake/pcl/PCLConfig.cmake:543 (find_external_library)/opt/ros/humble/share/pcl_conversions/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package)/opt/ros/humble/share/pcl_conversions/cmake/pcl_conversionsConfig.cmake:41 (include)/opt/ros/humble/share/ament_cmake_auto/cmake/ament_auto_find_build_dependencies.cmake:67 (find_package)CMakeLists.txt:225 (ament_auto_find_build_dependencies)
This warning is for project developers.  Use -Wno-dev to suppress it./usr/include/apr-1.0
apr-1
CMake Warning (dev) at /opt/ros/humble/share/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake:20 (find_package):Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modulesare removed.  Run "cmake --help-policy CMP0148" for policy details.  Usethe cmake_policy command to set the policy and suppress this warning.Call Stack (most recent call first):/opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)/opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:286 (ament_execute_extensions)CMakeLists.txt:241 (rosidl_generate_interfaces)
This warning is for project developers.  Use -Wno-dev to suppress it.CMake Warning (dev) at /opt/ros/humble/share/python_cmake_module/cmake/Modules/FindPythonExtra.cmake:52 (find_package):Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modulesare removed.  Run "cmake --help-policy CMP0148" for policy details.  Usethe cmake_policy command to set the policy and suppress this warning.Call Stack (most recent call first):/opt/ros/humble/share/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake:23 (find_package)/opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)/opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:286 (ament_execute_extensions)CMakeLists.txt:241 (rosidl_generate_interfaces)
This warning is for project developers.  Use -Wno-dev to suppress it.CMake Warning (dev) at /opt/ros/humble/share/python_cmake_module/cmake/Modules/FindPythonExtra.cmake:140 (find_package):Policy CMP0148 is not set: The FindPythonInterp and FindPythonLibs modulesare removed.  Run "cmake --help-policy CMP0148" for policy details.  Usethe cmake_policy command to set the policy and suppress this warning.Call Stack (most recent call first):/opt/ros/humble/share/rosidl_generator_py/cmake/rosidl_generator_py_generate_interfaces.cmake:23 (find_package)/opt/ros/humble/share/ament_cmake_core/cmake/core/ament_execute_extensions.cmake:48 (include)/opt/ros/humble/share/rosidl_cmake/cmake/rosidl_generate_interfaces.cmake:286 (ament_execute_extensions)CMakeLists.txt:241 (rosidl_generate_interfaces)
This warning is for project developers.  Use -Wno-dev to suppress it.failed to create symbolic link '/home/sky/mid360/ros_ws/build/livox_ros_driver2/ament_cmake_python/livox_ros_driver2/livox_ros_driver2' because existing path cannot be removed: Is a directory
gmake[2]: *** [CMakeFiles/ament_cmake_python_symlink_livox_ros_driver2.dir/build.make:70:CMakeFiles/ament_cmake_python_symlink_livox_ros_driver2] 错误 1
gmake[1]: *** [CMakeFiles/Makefile2:520:CMakeFiles/ament_cmake_python_symlink_livox_ros_driver2.dir/all] 错误 2
gmake[1]: *** 正在等待未完成的任务....
gmake: *** [Makefile:146:all] 错误 2
---
Failed   <<< livox_ros_driver2 [2.74s, exited with code 2]Summary: 0 packages finished [2.91s]1 package failed: livox_ros_driver21 package had stderr output: livox_ros_driver21 package not processed

解决办法:这意味着 CMake 尝试创建一个符号链接,但目标路径已经存在并且是一个目录。你可以手动删除它:
rm -rf /home/sky/mid360/ros_ws/build/livox_ros_driver2/ament_cmake_python/livox_ros_driver2/livox_ros_driver2
把这个文件下的这个包删除就行

然后就可以运行fastlio2的算法包了


###下面三个是使用ros2启动mid360驱动包的,在同一个终端按顺序启动即可cd ~/mid360/ros_wssource ~/mid360/ros_ws/install/setup.bashros2 launch livox_ros_driver2 rviz_MID360_launch.py###下面步骤是启动fastlio2算法包的(重新打开一个终端)cd ros_ws/srcsource ~/mid360/ros_ws/install/setup.bashros2 launch fast_lio mapping.launch.py

其他报错:运行雷达驱动包有点云数据,但是fastlio2算法包运行之后,显示黑屏,并且没有数据显示,这个问题是运行fastliio算法包崩溃了,大概率是包的冲突,

sky@sky:~/mid360/ros_ws$ source install/setup.bash
sky@sky:~/mid360/ros_ws$ ros2 launch fast_lio mapping.launch.py
[INFO] [launch]: All log files can be found below /home/sky/.ros/log/2025-08-18-21-27-52-585647-sky-144534
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [fastlio_mapping-1]: process started with pid [144535]
[INFO] [rviz2-2]: process started with pid [144537]
[rviz2-2] Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
[fastlio_mapping-1] /home/sky/mid360/ros_ws/install/fast_lio/lib/fast_lio/fastlio_mapping: symbol lookup error: /lib/x86_64-linux-gnu/libpcl_io.so.1.12: undefined symbol: libusb_set_option
[ERROR] [fastlio_mapping-1]: process has died [pid 144535, exit code 127, cmd '/home/sky/mid360/ros_ws/install/fast_lio/lib/fast_lio/fastlio_mapping --ros-args --params-file /home/sky/mid360/ros_ws/install/fast_lio/share/fast_lio/config/mid360.yaml --params-file /tmp/launch_params_v46jnbq_'].
[rviz2-2] [INFO] [1755523673.190659466] [rviz2]: Stereo is NOT SUPPORTED
[rviz2-2] [INFO] [1755523673.190715080] [rviz2]: OpenGl version: 4.6 (GLSL 4.6)
[rviz2-2] [INFO] [1755523673.201940923] [rviz2]: Stereo is NOT SUPPORTE

解决办法:

1. 修复 FAST-LIO 的库依赖问题错误 undefined symbol: libusb_set_option 表明 libpcl_io 和 libusb 版本不兼容。尝试以下步骤:
方法 1:降级 libpcl
bashsudo apt remove libpcl-dev
sudo apt install libpcl-dev=1.12.1+dfsg-5ubuntu0.1  # Ubuntu 22.04 默认版本
sudo ldconfig方法 2:更新 libusb
bashsudo apt install libusb-1.0-0-dev
sudo apt upgrade libusb-1.0-0方法 3:手动编译 PCL如果问题仍然存在,从源码编译 PCL:
bashgit clone https://github.com/PointCloudLibrary/pcl.git
cd pcl && mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j$(nproc)
sudo make install

报错:

sky@sky:~/mid360/ros_ws$ ros2 launch fast_lio mapping.launch.py
[INFO] [launch]: All log files can be found below /home/sky/.ros/log/2025-08-19-01-18-35-837053-sky-190899
[INFO] [launch]: Default logging verbosity is set to INFO
[INFO] [fastlio_mapping-1]: process started with pid [190901]
[INFO] [rviz2-2]: process started with pid [190903]
[rviz2-2] Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
[fastlio_mapping-1] [INFO] [1755537515.950811500] [laser_mapping]: p_pre->lidar_type 2
[fastlio_mapping-1] Multi thread started 
[fastlio_mapping-1] ~~~~/home/sky/mid360/ros_ws/src/FAST_LIO/ file opened
[fastlio_mapping-1] [INFO] [1755537515.955457193] [laser_mapping]: Node init finished.
[fastlio_mapping-1] Failed to find match for field 'time'.
[fastlio_mapping-1] Failed to find match for field 'ring'.
[fastlio_mapping-1] Failed to find match for field 'time'.
[fastlio_mapping-1] Failed to find match for field 'ring'.
[rviz2-2] [INFO] [1755537516.123347654] [rviz2]: Stereo is NOT SUPPORTED
[rviz2-2] [INFO] [1755537516.123411995] [rviz2]: OpenGl version: 4.6 (GLSL 4.6)
[rviz2-2] [INFO] [1755537516.135036306] [rviz2]: Stereo is NOT SUPPORTED
[fastlio_mapping-1] IMU Initial Done
[fastlio_mapping-1] [WARN] [1755537516.165249588] [laser_mapping]: No point, skip this scan!
[fastlio_mapping-1] 
[fastlio_mapping-1] Failed to find match for field 'time'.
[fastlio_mapping-1] Failed to find match for field 'ring'.
[fastlio_mapping-1] [INFO] [1755537516.266224533] [laser_mapping]: Initialize the map kdtree
[fastlio_mapping-1] Failed to find match for field 'time'.
[fastlio_mapping-1] Failed to find match for field 'ring'.

原因:你贴出的代码正是 FAST-LIO 的 preprocess.cpp
问题的根源是:当 lidar_type = 2(PointCloud2)时,默认的 default_handler 不会给点云里的每个点填充 curvature(即时间信息),于是 Fast-LIO 直接丢弃整帧,rviz 黑屏。

解决方法:


--------------------------------------------------
1 分钟补丁(改 `mid360_handler()`)打开文件  
```bash
gedit ~/mid360/ros_ws/src/FAST_LIO/src/preprocess.cpp
```找到 `mid360_handler()` 函数,把下面 3 行替换进去:- 找到  ```cppadded_pt.curvature = 0.;```替换为  ```cpp/* 用整帧 header.stamp 作为统一时间戳 (ms) */added_pt.curvature = rclcpp::Time(msg->header.stamp).seconds() * 1000.0;```(其余代码不动,只需改这一处。)保存后:```bash
cd ~/mid360/ros_ws
colcon build --packages-select fast_lio
source install/setup.bash
ros2 launch fast_lio mapping.launch.py
```日志立即不再出现  
`Failed to find match for field 'time'`,`/cloud_registered` 10 Hz 正常输出,rviz 即可看到实时点云。

http://www.dtcms.com/a/339059.html

相关文章:

  • 【数据结构】用堆解决TOPK问题
  • 算法训练营day56 图论⑥ 108. 109.冗余连接系列
  • C++---为什么迭代器常用auto类型?
  • 强、软、弱、虚引用
  • 在 Qt C++ 中利用 OpenCV 实现视频处理技术详解
  • 尝试Claude Code的安装
  • 学习笔记分享——基于STM32的平衡车项目
  • Mac调试ios的safari浏览器打开的页面
  • 电子电气架构 --- 软件项目成本估算
  • 技术攻坚全链铸盾 锁定12月济南第26届食品农产品安全高峰论坛
  • 任务十二 我的页面及添加歌曲功能开发
  • Typescript入门-对象讲解
  • Python量化交易:结合爬虫与TA-Lib技术指标分析
  • Matplotlib数据可视化实战:Matplotlib子图布局与管理入门
  • Ansible 角色管理指南
  • Pandas数据处理与分析实战:Pandas数据处理与Matplotlib可视化入门
  • 0819 使用IP多路复用实现TCP并发服务器
  • Tomcat 的核心脚本catalina.sh 和 startup.sh的关系
  • 陪诊小程序系统开发:开启智慧就医新时代
  • CNN 在故障诊断中的应用:原理、案例与优势
  • BEV:隐式相机视角转换-----BEVFormer
  • 简单实现监听redis的Key过期事件
  • Shopee本土店账号安全运营:规避封禁风险的多维策略
  • 微服务-08.微服务拆分-拆分商品服务
  • 什么是强化学习
  • JMeter高级性能测试训练营 – 从入门到企业级实战
  • pytest高级用法之插件开发
  • Quartus Prime 18.1网盘资源下载与安装指南
  • 从线性回归到神经网络到自注意力机制 —— 激活函数与参数的演进
  • Berry Material React TypeScript 管理后台使用教程 v0.1.0