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就可以了。

相关推荐
winfreedoms5 天前
ROS2知识大白话
笔记·学习·ros2
LS_learner8 天前
RViz(ROS Visualization)显示传感器数据、机器人状态、路径规划结果等各种信息的强大图形界面
ros2
LS_learner8 天前
ROS2的jazzy版本的机器人3D仿真软件gazebo的安装和使用
ros2
LS_learner8 天前
Xacro 和 SDF 是进行复杂机器人系统开发与高级仿真的关键技能
ros2
LS_learner8 天前
URDF(Unified Robot Description Format)机器人领域中用于描述机器人模型的标准 XML 格式
ros2
LS_learner8 天前
机器人描述中的Xacro、SDF与URDF在实际项目中的协作流程
ros2
LS_learner9 天前
Gazebo 机器人三维物理仿真平台
ros2
github5actions11 天前
ROS开发实战:如何用rviz文件保存和加载你的SLAM可视化配置(附避坑指南)
ros·slam·rviz·机器人开发
REDcker11 天前
DDS 协议详解
机器人·ros·ros2·dds
LS_learner15 天前
ROS 2(Robot Operating System 2)通信机制
ros2