ubuntu22.04 ros2 fast_lio2 复现

源项目:

https://github.com/liangheming/FASTLIO2_ROS2https://github.com/liangheming/FASTLIO2_ROS2

项目依赖以下第三方库,

pcl

Eigen

sophus

gtsam

livox_ros_driver2

在我们编译完mid360的sdk和ros2驱动包(可以参考我之前的文章)后,我们只需编译sophus

gtsam即可,其他几个之前编译好了,反正缺啥编译啥

https://blog.csdn.net/m0_53931365/article/details/153976259?spm=1001.2014.3001.5502https://blog.csdn.net/m0_53931365/article/details/153976259?spm=1001.2014.3001.5502

1.sophus编译

https://github.com/strasdat/Sophushttps://github.com/strasdat/Sophus

bash 复制代码
git clone https://github.com/strasdat/Sophus.git
cd Sophus
git checkout 1.22.10 #旧版本
mkdir build && cd build
cmake .. -DSOPHUS_USE_BASIC_LOGGING=ON
make
sudo make install

原文说新的Sophus依赖fmt,可以在CMakeLists.txt中添加add_compile_definitions(SOPHUS_USE_BASIC_LOGGING)去除,否则会报错

2.gtsam编译

https://github.com/borglab/gtsamhttps://github.com/borglab/gtsam下载完项目,需要需要添加dllexport.h文件,不然编译会报错

bash 复制代码
git clone https://github.com/borglab/gtsam.git
# 进入 cephes 目录
cd gtsam/gtsam/3rdparty/cephes

# 创建 dllexport.h 文件
tee dllexport.h > /dev/null << 'EOF'
#ifndef DLLEXPORT_H
#define DLLEXPORT_H

/* Define DLLEXPORT for Windows, empty for other platforms */
#ifdef _WIN32
    #ifdef GTSAM_SHARED_LIB
        #define DLLEXPORT __declspec(dllexport)
    #else
        #define DLLEXPORT __declspec(dllimport)
    #endif
#else
    #define DLLEXPORT
#endif

#endif // DLLEXPORT_H
EOF
bash 复制代码
cd gtsam
#!bash
mkdir build
cd build
cmake ..
make check -j8 #多线程编译
sudo make install

编译有点久,编译完成,查看动态链接库的路径

bash 复制代码
# 找到 libgtsam.so.4 文件
find ~ -name "libgtsam.so.4" 2>/dev/null

如果后面保存地图出现找不到libgtsam.so.4,可以手动添加到路径到环境变量

bash 复制代码
# 临时解决方案(在当前终端生效)
export LD_LIBRARY_PATH=/path/to/your/gtsam/install/lib:$LD_LIBRARY_PATH


# 永久解决方案(添加到 ~/.bashrc)
echo 'export LD_LIBRARY_PATH=/path/to/your/gtsam/install/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc

例如

bash 复制代码
szz@szz:~/ws_livox$ find ~ -name "libgtsam.so.4" 2>/dev/null
/home/szz/gtsam-develop/build/gtsam/libgtsam.so.4
szz@szz:~/ws_livox$ export LD_LIBRARY_PATH=/home/szz/gtsam-develop/build/gtsam/libgtsam.so.4:$LD_LIBRARY_PATH

4.fast-lio2

将fast-lio2里面的包移动到自己src中编译即可使用

5.建图验证

5.1下载验证的pcd文件,也可以用自己的

http://链接: https://pan.baidu.com/s/1rTTUlVwxi1ZNo7ZmcpEZ7A?pwd=t6yb 提取码: t6yb

1.激光惯性里程计

bash 复制代码
ros2 launch fastlio2 lio_launch.py
ros2 bag play your_bag_file

2.里程计加回环

启动回环节点

bash 复制代码
ros2 launch pgo pgo_launch.py
ros2 bag play your_bag_file

保存地图

bash 复制代码
ros2 service call /pgo/save_maps interface/srv/SaveMaps "{file_path: 'your_save_dir', save_patches: true}"

预览pcd地图

bash 复制代码
sudo apt-get install pcl-tools
pcl_viewer xxx.pcd

3.里程计加重定位

启动重定位节点

bash 复制代码
ros2 launch localizer localizer_launch.py
ros2 bag play your_bag_file // 可选

设置重定位初始值

bash 复制代码
ros2 service call /localizer/relocalize interface/srv/Relocalize "{"pcd_path": "your_map.pcd", "x": 0.0, "y": 0.0, "z": 0.0, "yaw": 0.0, "pitch": 0.0, "roll": 0.0}"

检查重定位结果

bash 复制代码
ros2 service call /localizer/relocalize_check interface/srv/IsValid "{"code": 0}"

4.一致性地图优化

启动一致性地图优化节点

bash 复制代码
ros2 launch hba hba_launch.py

调用优化服务

bash 复制代码
ros2 service call /hba/refine_map interface/srv/RefineMap "{"maps_path": "your maps directory"}"

如果需要调用优化服务,保存地图时需要设置save_patches为true

原作者提到机器性能问题,TIPS:将timerCB改成用用一个单独线程去run就可以了。

相关推荐
-点灯-2 天前
【无标题】
ros2
General_G2 天前
irobot_benchmark的编译和使用
linux·中间件·机器人·ros2
阿豪只会阿巴4 天前
【多喝热水系列】从零开始的ROS2之旅——Day10 话题的订阅与发布1:Python
开发语言·c++·python·ubuntu·ros2
阿豪只会阿巴4 天前
【多喝热水系列】从零开始的ROS2之旅——Day9 初识话题通信:基本命令
c++·笔记·python·ubuntu·ros2
阿豪只会阿巴4 天前
项目心得——发布者和订阅者问题解决思路
linux·开发语言·笔记·python·ubuntu·ros2
Tipriest_6 天前
ROS 2 rosbag2 播放出现 “Message queue starved. Messages will be delayed.” 的处理步骤
消息队列·ros2·缓存机制
点云SLAM6 天前
SLAM文献之-A Quick Guide for the Iterated Extended Kalman Filter on Manifolds
人工智能·机器人·slam·三维重建·fast-lio·卡尔曼滤波算法·iekf
提伯斯6466 天前
Fast-LIO到MAVROS视觉定位转换
linux·ros·无人机·mid360·fasltlio
提伯斯6467 天前
解决 PX4 + ROS px4ctrl 「No odom!」自动起飞失败问题
linux·ros·px4·fastlio·mid360·egoplanner
大鹅同志7 天前
Ubuntu 20.04使用MB-System分析与可视化EM3000数据
数据库·3d·ros·slam·mb-system