ORB_SLAM3 + ROS采坑實錄(從零開始的畢設生活第一彈)

ORB-SLAM3配置

//github.com/UZ-SLAMLab/ORB_SLAM3

//github.com/shanpenghui/ORB_SLAM3_Fixed

EVO Evaluation of SLAM 4 — ORB-SLAM3 編譯和利用數據集運行_一個摩羯座的程式猿 的 知識筆記-CSDN部落格_orb_slam3數據集

1.ROS Melodic安裝

Wiki

採用中國源:

sudo sh -c '. /etc/lsb-release && echo "deb //mirrors.ustc.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'

#Set up your keys 官方Key有問題的時候
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654

sudo apt update
sudo apt install ros-melodic-desktop-full

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc

sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
sudo apt install python-rosdep

#sudo rosdep init出錯
sudo chmod 777 /etc
mkdir -p /etc/ros/rosdep/sources.list.d
gedit 20-default.list

#############################################
#填入一下內容
# os-specific listings first
yaml //raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml osx

# generic
yaml //raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
yaml //raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
yaml //raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
gbpdistro //raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml fuerte

# newer distributions (Groovy, Hydro, ...) must not be listed anymore, they are being fetched from the rosdistro index.yaml instead
#############################################

2.Pangolin安裝

//github.com/stevenlovegrove/Pangolin

#安裝依賴項:
sudo apt-get install libglew-dev
sudo apt-get install libpython2.7-dev
sudo apt-get install libxkbcommon-dev
sudo apt-get install wayland-protocols

#先轉到一個要存儲Pangolin的路徑下,例如~/Documents,然後
git clone //github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake ..
make –j8
sudo make install

報錯WARNING: Target "pango_python" has EXCLUDE_FROM_ALL set and will not be built by default but an install rule has been provided for it. CMake does not define behavior for this case.

#the error is due to the high c++ standard and you can add
set_property(TARGET ${COMPONENT} PROPERTY CXX_STANDARD 11)
#in the ~/Pangolin/compnents/pango_image/CMakeList.txt under the
get_filename_component(COMPONENT ${CMAKE_CURRENT_LIST_DIR} NAME)

3.安裝Eigen3

1.直接安裝
 sudo apt-get install libeigen3-dev
2.官網(//eigen.tuxfamily.org/index.php?title=Main_Page)下載最新源碼包
mkdir build
cd build
cmake ..
make -j8
sudo make install

Eigen頭文件的默認位置在 「usr/include/eigen3」
如果不確定,可以通過以下命令查找
sudo updatedb
locate eigen3

4.安裝opencv4.4

OpenCV4.4.0 安裝測試 Installation & Examination (Ubuntu18.04, Ubuntu 20.04)

# If you don't have cmake: 
# sudo apt-get install cmake 
sudo apt-get install libswscale-dev libtiff5-dev libgtk2.0-dev pkg-config 
sudo apt install build-essential 
sudo apt install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev 
sudo apt install libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev 
# If need to support python3: 
# sudo apt install python3-dev python3-numpy 
# If need ffmpeg: 
sudo apt install ffmpeg

#報錯安裝
sudo apt-get install gtk+-3.0

#生成 Makefile
cd opencv-4.4.0 
weget "//codeload.github.com/opencv/opencv_contrib/zip/4.4.0"
mkdir build 
cd build 
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_EXTRA_MODULES_PATH=/home/mr-mmm/SLAM/opencv-4.4.0/opencv_contrib-4.4.0/modules/ -D BUILD_opencv_world=YES -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=OFF -D WITH_OPENGL=ON -D WITH_EIGEN=ON -D BUILD_EXAMPLES=ON -D BUILD_DOCS=ON ..

#編譯安裝
make -j8 
sudo make install

#環境配置
sudo gedit /etc/ld.so.conf.d/opencv4.conf
#將以下內容寫入文件
# libc default configuration 
/usr/local/lib

#更新配置
sudo ldconfig

sudo gedit /etc/bash.bashrc
# Add in the end 
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig 
export PKG_CONFIG_PATH

#更新配置
source /etc/bash.bashrc 
sudo updatedb

#測試Opencv安裝
pkg-config --modversion opencv4

報錯E: Unable to locate package libjasper-dev

sudo add-apt-repository "deb //security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev

5.Building ORB-SLAM3 library and examples

git clone //github.com/UZ-SLAMLab/ORB_SLAM3.git ORB_SLAM3
cd ORB_SLAM3
chmod +x build.sh
./build.sh

6.ROS Examples

gedit ~/.bashrc
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM3/Examples/ROS

chmod +x build_ros.sh
./build_ros.sh

報錯1:fatal error: sophus/se3.hpp: No such file or directory #include <sophus/se3.hpp>

git clone //github.com/strasdat/Sophus.git
cd Sophus/
 
mkdir build
cd build
cmake ..
make
sudo make install

報錯2:error: conversion from 『Sophus::SE3f {aka Sophus::SE3}』 to non-scalar type 『cv::Mat』 requested

error: no matching function for call to 『std::vectorcv::Mat::push_back(Eigen::Vector3f)』

error: conversion from 『Eigen::Vector3f {aka Eigen::Matrix<float, 3, 1>}』 to non-scalar type 『cv::Mat』 requested

//github.com/UZ-SLAMLab/ORB_SLAM3/issues/442

報錯3:error: 『eigen2cv』 is not a member of 『cv』

//github.com/UZ-SLAMLab/ORB_SLAM3/issues/479

注釋掉cmakelist中關於AR的部分解決問題

# Node for monocular camera (Augmented Reality Demo)
#rosbuild_add_executable(MonoAR
#src/AR/ros_mono_ar.cc
#src/AR/ViewerAR.h
#src/AR/ViewerAR.cc
#)

#target_link_libraries(MonoAR
#${LIBS}
#)

報錯4 rosrun ORB_SLAM3 Mono Vocabulary/ORBvoc.txt Examples/ROS/ORB_SLAM3/Asus.yaml
/home/mr-mmm/SLAM/ORB_SLAM3/Examples/ROS/ORB_SLAM3/Mono: error while loading shared libraries: libDBoW2.so: cannot open shared object file: No such file or directory

error while loading shared libraries – ROS Answers: Open Source Q&A Forum

*.so 移動到 /usr/lib/ 解決問題

報錯5″Aborted (core dumped)” when running Ros example

run Mono_Inertial Segmentation fault (core dumped)

//github.com/UZ-SLAMLab/ORB_SLAM3/issues/333

7. ROS運行測試

#setp01
roscore

#step02
rosbag play Datasets/MH_01_easy.bag /cam0/image_raw:=/camera/image_raw /imu0:=/imu

#step03
rosrun ORB_SLAM3 Mono_Inertial Vocabulary/ORBvoc.txt Examples/Monocular-Inertial/EuRoC.yaml

Tags: