< >
Home » ROS2与VSLAM入门教程 » ROS2与VSLAM入门教程-ubuntu22.04下安装orbslamv3

ROS2与VSLAM入门教程-ubuntu22.04下安装orbslamv3

文章摘要

  • 本教程主要介绍如何在ubuntu22.04下安装orbslamv3和其对应的orbslam ros3包

  • 测试环境:Ubuntu 22.04 + ROS Humble + OpenCV 4.5.4

安装步骤

  • 安装Pangolin
$ mkdir ~/tools/
$ cd ~/tools/
$ git clone https://ghproxy.com/https://github.com/stevenlovegrove/Pangolin
$ cd ~/tools/Pangolin
$ git checkout 25159034e62011b3527228e476cec51f08e87602
$ sed -i '33a\#include <limits>' ~/tools/Pangolin/include/pangolin/gl/colour.h
$ mkdir build
$ cd build
$ cmake -DCPP11_NO_BOOST=1 ..
$ make

注意:如果PC上同时装有orbslam2,需要注释掉~/.bashrc中的两句

  • export LD_LIBRARY_PATH=~/tools/Pangolin/build/src/:~/vslam/ORB_SLAM2/Thirdparty/DBoW2/lib:~/vslam/ORB_SLAM2/Thirdparty/g2o/lib:~/vslam/ORB_SLAM2/lib:$LD_LIBRARY_PATH
  • export ORB_SLAM2_ROOT_DIR=~/tools/ORB_SLAM2
  • 安装orbslam3
$ cd ~/tools/
$ git clone https://ghproxy.com/https://github.com/EndlessLoops/ORB_SLAM3
$ cd ~/tools/ORB_SLAM3
$ sudo chmod +x build.sh
$ ./build.sh
$ cd ~/tools/ORB_SLAM3/Thirdparty/Sophus/build/
$ sudo make install

$ echo 'export LD_LIBRARY_PATH=~/tools/Pangolin/build/src/:~/tools/ORB_SLAM3/Thirdparty/DBoW2/lib:~/tools/ORB_SLAM3/Thirdparty/g2o/lib:~/tools/ORB_SLAM3/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
  • 安装orbslam3 ros2包
$ mkdir -p ~/ros2_orb_slamv3_ws/src
$ cd ~/ros2_orb_slamv3_ws/src
$ git clone https://ghproxy.com/https://github.com/EndlessLoops/ORB_SLAM3_ROS2.git orbslam3_ros2
$ cd ~/ros2_orb_slamv3_ws/
$ colcon build
$ echo 'source ~/ros2_orb_slamv3_ws/install/setup.bash' >> ~/.bashrc

测试步骤

1.数据集测试

$ cd 
$ wget -c http://robotics.ethz.ch/~asl-datasets/ijrr_euroc_mav_dataset/machine_hall/MH_01_easy/MH_01_easy.zip
$ unzip MH_01_easy.zip -d MH01/
  • 测试
$ cd ~/tools/ORB_SLAM3
$ ./Examples/Monocular/mono_euroc ./Vocabulary/ORBvoc.txt ./Examples/Monocular/EuRoC.yaml ~/MH01 ./Examples/Monocular/EuRoC_TimeStamps/MH01.txt dataset-MH01_mono

This is a alt text.

2.ROS2包测试

  • 本次测试使用的是D435i相机

  • 启动相机

# 安装相机驱动
$ sudo apt install ros-humble-realsense2-camera 
# 启动相机
$ ros2 launch realsense2_camera rs_launch.py rgb_camera.profile:='640x480x15' depth_module.profile:='640x480x15'
  • 启动ROS2节点
# Mono例程
$ ros2 run orbslam3 mono ~/tools/ORB_SLAM3/Vocabulary/ORBvoc.txt ~/tools/ORB_SLAM3/Examples/Monocular/RealSense_D435i.yaml
# RGBD例程
$ ros2 run orbslam3 rgbd ~/tools/ORB_SLAM3/Vocabulary/ORBvoc.txt ~/tools/ORB_SLAM3/Examples/RGB-D/RealSense_D435i.yaml

This is a alt text.

FAQ

Q1

  • orbslam3 ros2包编译报错
/usr/bin/ld: CMakeFiles/stereo.dir/src/stereo/stereo-slam-node.cpp.o: undefined reference to symbol '_ZN2cv23initUndistortRectifyMapERKNS_11_InputArrayES2_S2_S2_NS_5Size_IiEEiRKNS_12_OutputArrayES7_'
/usr/bin/ld: /lib/x86_64-linux-gnu/libopencv_calib3d.so.4.5d: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/stereo.dir/build.make:211: stereo] Error 1
make[1]: *** [CMakeFiles/Makefile2:195: CMakeFiles/stereo.dir/all] Error 2
make: *** [Makefile:146: all] Error 2
---
Failed   <<< orbslam3 [18min 59s, exited with code 2]
                                       
Summary: 0 packages finished [19min 0s]
  1 package failed: orbslam3
  1 package had stderr output: orbslam3

A1

  • 解决方案
$ vim ~/ros2_orb_slamv3_ws/src/orbslam3_ros2/CMakeLists.txt

# 添加OpenCV的查找语句
find_package(OpenCV 4.0 QUIET)
# 添加OpenCV再末尾
ament_target_dependencies(stereo rclcpp sensor_msgs cv_bridge message_filters ORB_SLAM3 Pangolin OpenCV)

# 编译
 $ cd ~/ros2_orb_slamv3_ws && colcon build

参考资料:https://github.com/zang09/ORB_SLAM3_ROS2/issues/5#issuecomment-1510905707

Q2

  • orbslam3 ros2包编译报错
/usr/bin/ld: /home/ubuntu/tools/ORB_SLAM3/lib/libORB_SLAM3.so: undefined reference to `g2o::OptimizationAlgorithmGaussNewton::OptimizationAlgorithmGaussNewton(g2o::Solver*)'
collect2: error: ld returned 1 exit status

A2

  • 经排查,原因来自此前同时安装了orbslam2,orbslam2的安装脚本将libg2o.so和libDBoW2.so复制到了/usr/local/lib/
# 将两个库文件移到其他地方
$ sudo mv /usr/local/lib/libDBoW2.so ~/.
$ sudo mv /usr/local/lib/libg2o.so ~/.
# 编译
$ cd ~/ros2_orb_slamv3_ws && colcon build

Q3

  • 启动ros2 rgbd示例时,程序启动启动后直接崩溃,不能正常显示图像
Loading ORB Vocabulary. This could take a while...
Vocabulary loaded!

Initialization of Atlas from scratch 
Creation of new map with id: 0
Creation of new map with last KF id: 0
Seq. Name: 
There are 1 cameras in the atlas
Camera 0 is pinhole
Shutdown

Saving keyframe trajectory to KeyFrameTrajectory.txt ...
double free or corruption (out)
[ros2run]: Aborted

A3

  • 可以尝试修改
$ vim ~/ros2_orb_slamv3_ws/src/orbslam3_ros2/src/rgbd/rgbd-slam-node.cpp

    //rgb_sub = std::make_shared<message_filters::Subscriber<ImageMsg> >(shared_ptr<rclcpp::Node>(this), "camera/color/image_raw"); // d435i topic
    //depth_sub = std::make_shared<message_filters::Subscriber<ImageMsg> >(shared_ptr<rclcpp::Node>(this), "camera/depth/image_rect_raw"); // d435i topic
    
    rgb_sub = std::make_shared<message_filters::Subscriber<ImageMsg> >(this, "camera/color/image_raw"); // d435i topic
    depth_sub = std::make_shared<message_filters::Subscriber<ImageMsg> >(this, "camera/depth/image_rect_raw"); // d435i topic

Q4

  • 进行数据集测试是,没有显示图像窗口,正常应该有Starting the Viewer语句
Loading ORB Vocabulary. This could take a while...
Vocabulary loaded!

Initialization of Atlas from scratch 
Creation of new map with id: 0
Creation of new map with last KF id: 0
Seq. Name: 
There are 1 cameras in the atlas
Camera 0 is pinhole
First KF:0; Map init KF:0
New Map created with 271 points

A4

  • 解决方案
$ vim ~/tools/ORB_SLAM3/Examples/Monocular/mono_euroc.cc

ORB_SLAM3::System SLAM(argv[1],argv[2],ORB_SLAM3::System::MONOCULAR,false);
# 第83行的`false`替换为`true`
ORB_SLAM3::System SLAM(argv[1],argv[2],ORB_SLAM3::System::MONOCULAR, true);
$ cd ~/tools/ORB_SLAM3
$ ./build.sh

Q5

  • orbslam3 ros2包编译卡死

A5

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: none