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: