ubuntu16.04+realsense D435I +ros kinetic+ ORB-SLAM2

參考鏈接:

https://blog.csdn.net/qq_41839222/article/details/86503113

https://blog.csdn.net/qq_42393859/article/details/85257685

https://blog.csdn.net/Carminljm/article/details/86353775

https://blog.csdn.net/subiluo/article/details/88975979

ORBSLAM原始代碼及論文地址:http://webdiis.unizar.es/~raulmur/orbslam/

安裝環境

系统:ubuntu 16.04 内核 4.15.0-50-generic
ROS: Kinetic
传感器:intel realsense d435i
(ros-kinetic安裝參考官網http://wiki.ros.org/kinetic/Installation/Ubuntu )

 

前期安裝了:VTK7.1.1,opencv3.4.0,Eigen3.3,PCL1.8,ROS-kinetic

安装Realsense d435i SDK

github:https://github.com/IntelRealSense/librealsense

建議直接參照官網教程:

sudo apt-key adv --keyserver keys.gnupg.net --recv-key C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver
  • Ubuntu 16 LTS:
sudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial main" -u

sudo apt-get update
sudo apt-get install librealsense2-dkms
sudo apt-get install librealsense2-utils

 

博主才開始安装参考了文档:https://github.com/IntelRealSense/librealsense/blob/master/doc/installation.md

     1、下载source

git clone https://github.com/IntelRealSense/librealsense
cd librealsense

     2、安装依赖项

sudo apt-get install libudev-dev pkg-config libgtk-3-dev
sudo apt-get install libusb-1.0-0-dev pkg-config
sudo apt-get install libglfw3-dev
sudo apt-get install libssl-dev

3、Install Intel Realsense permission scripts located in librealsense source directory:

sudo cp config/99-realsense-libusb.rules /etc/udev/rules.d/
sudo udevadm control --reload-rules && udevadm trigger

4、这边需要注意把realsense拔下来
Build and apply patched kernel modules for:
根据不同的ubuntu版本安装:对于Ubuntu 14/16/18 LTS

./scripts/patch-realsense-ubuntu-lts.sh
sudo dmesg | tail -n 50

在./scripts/patch-realsense-ubuntu-lts.sh過程中遇到提示:

Replacing videodev : Module videodev is used by videobuf2_core 
Unloading dependency videobuf2_core modprobe: 
FATAL: Module videobuf2_core is in use. Failed to unload module videobuf2_core. error type 1 . 
Operation is aborted

解決辦法:


$ lsmod | grep videobuf2_core

videobuf2_core         40960  2 videobuf2_v4l2,uvcvideo
videodev              180224  3 videobuf2_core,videobuf2_v4l2,uvcvideo

$ sudo modprobe -r uvcvideo
$ lsmod | grep videobuf2_core

之後再./scripts/patch-realsense-ubuntu-lts.sh即可成功。

5、基于cmake的编译

mkdir build
cd build
cmake ../ -DBUILD_EXAMPLES=true
make
sudo make install

-DBUILD_EXAMPLES=true 这个选项表示带演示和教程的

6、进入/librealsense/build/examples/capture,试一下效果

./rs-capture

才開始不知道爲什麼無法鏈接相機,參照官網或https://blog.csdn.net/qq_42393859/article/details/85257685又進行了一系列安裝,後成功。

 

安装ROS Wrapper(基於Ros使用realsense包)

https://github.com/intel-ros/realsense

直接按照github上的教程即可,主要參考github,博主期間參考很多文章,結果差點把系統搞崩。。。。

1、建立workspace,已经有的可以跳过

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src/
catkin_init_workspace
cd ..
catkin_make
catkin_make install

echo "source ~/catkin_ws/devel/setup.bash" >> ~/basher
source ~/.bashrc

要catkin_make install一下,不install的話,相機結點無法啓動。

2、在catkin_ws/src/下载源程序

cd src
git clone https://github.com/intel-ros/realsense.git

3、catkin_make

cd ..
catkin_make

4、如果没有错误说明,已经装好了,启动相机节点

roslaunch realsense2_camera rs_rgbd.launch

在這裏出現了一些小插曲,似乎很不穩定,但卻是有時候是可以啓動的,最後又不能啓動了,提示

ResourceNotFound:rgbd_launch

最後:

sudo apt-get install ros-indigo-rgbd-launch

而後節點啓動。

5、看一下发布的topic

rostopic list

6、rviz查看結果

cd catkin_ws

source devel/setup.bash

roslaunch realsense2_camera rs_rgbd.launch

再打开一个终端,输入rviz運行,没有安装的话就安装一下
sudo apt-get install rviz
此时并不能看到什么结果.
左上角 Displays 中 Fixed Frame 选项中,下拉菜单选择 camera_link
这是主要到Global Status变成了绿色
点击该框中的Add -> 上方点击 By topic -> /depth_registered 下的 /points 下的/PointCloud2
点击该框中的Add -> 上方点击 By topic -> /color 下的 /image_raw 下的image

看到圖片,此塊即成功完成。

(內參獲取及標定此處暫未研究)

配置ORB-SLAM

(查看各安裝軟件版本的指令參考鏈接:

https://blog.csdn.net/qq_36501182/article/details/79044750 )

運行orb-slam需保证你的eigen版本在Eigen3.2.x至少不低,我的版本是3.3~beta1-2;

我的opencv是3.4.0版本;

ORB-SLAM文件夾下的Thirdparty下有DBoW2、g2o與Pangolin,建議把源碼中編譯過的文件build刪掉重新編譯。

分別進行編譯。

 

安裝一些庫

sudo apt-get install libblas-dev

sudo apt-get install libblas-dev liblapack-dev

sudo apt-get install libglew-dev
sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
sudo apt-get install libpython2.7-dev
sudo apt-get install build-essential

(以下庫的手動安裝方式,其實build.sh有將庫的編譯寫入,並不需要手動安裝,可省略。直接運行build.sh即可)



g2o安裝

cd g2o
mkdir build
cmake ..
make 
sudo make install(我這裏沒有make install,沒有影響代碼運行,查詢應該是源碼自帶的g2o版本不需要install)

Pangolin安裝

若Thirdparty文件夾下沒有,可下載:

git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake ..
make
sudo make install(我這裏沒有install)

DBoW2安裝

cd DBoW2
mkdir build
cd build
cmake ..
make
sudo make install


準備編譯ORB_SLAM2_modified

使用過的代碼較爲混亂,最終編譯過得代碼上傳至github:

  • 建議將裏面的build文件刪除,重新編譯:
cd ORB_SLAM2_modified/
rm -rf Thirdparty/DBoW2/build/
rm -rf Thirdparty/g2o/build/

做過的部分更改參考:https://blog.csdn.net/subiluo/article/details/88975979 中的【准备编译ORB_SLAM2_modified】至【回到ORB_SLAM2_modified】部分,如下:

  •      保证opencv版本的一致,修改ORB_SLAM2_modified下以及ORB_SLAM2_modified/Examples/ROS/ORB_SLAM2目录下的  CMakeLists.txt,这里统一修改为你电脑里的opencv版本
find_package(OpenCV 3.4.0 QUIET)
 find_package(OpenCV 3.4.0 QUIET)
 if(NOT OpenCV_FOUND)
    find_package(OpenCV 2.4.3 QUIET)
    if(NOT OpenCV_FOUND)
       message(FATAL_ERROR "OpenCV > 2.4.3 not found.")
    endif()
 endif()
  •       如果你的电脑很渣,修改ORB_SLAM2_modified文件夹下的build.sh,将所有make -j中的-j去掉
echo "Configuring and building Thirdparty/DBoW2 ..."

cd Thirdparty/DBoW2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make

cd ../../g2o

echo "Configuring and building Thirdparty/g2o ..."

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make

cd ../../../

echo "Uncompress vocabulary ..."

cd Vocabulary
tar -xf ORBvoc.txt.tar.gz
cd ..

echo "Configuring and building ORB_SLAM2 ..."

mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make

cd ..

echo "Converting vocabulary to binary"
./tools/bin_vocabulary
  •     开始编译ORB_SLAM2_modified
chmod +x build.sh
./build.sh
  •     修改ORB_SLAM2_modified/Examples/ROS/ORB_SLAM2/文件夹下的cmakelist,注意你电脑里应该安装了pcl库,如果没有请自行安装,-lboost_system一句加上
find_package(Pangolin REQUIRED)
find_package(PCL 1.8 REQUIRED)

include_directories(
        ${PROJECT_SOURCE_DIR}
        ${PROJECT_SOURCE_DIR}/../../../
        ${PROJECT_SOURCE_DIR}/../../../include
        ${Pangolin_INCLUDE_DIRS}
        ${PCL_INCLUDE_DIRS}
)
add_definitions(${PCL_DEFINITIONS})
link_directories(${PCL_LIBRARY_DIRS})

set(LIBS
        ${OpenCV_LIBS}
        ${EIGEN3_LIBS}
        ${Pangolin_LIBRARIES}
        ${PCL_LIBRARIES}
        ${PROJECT_SOURCE_DIR}/../../../Thirdparty/DBoW2/lib/libDBoW2.so
        ${PROJECT_SOURCE_DIR}/../../../Thirdparty/g2o/lib/libg2o.so
        ${PROJECT_SOURCE_DIR}/../../../lib/libORB_SLAM2.so
        -lboost_system
        )

 

  •     修改ORB_SLAM2_modified/Examples/ROS/ORB_SLAM2/src/ros_rgbd.cc文件,把rgb_topic和depth_topic订阅话题修改为:
 "/camera/color/image_raw";
 "/camera/aligned_depth_to_color/image_raw";

topic修改好後,一定記得編譯ROS接口,博主可能就是因爲這裏忘記了,導致後面無法獲取圖片,一直是黑屏的狀態。  

  •     回到ORB_SLAM2_modified
  •     渣电脑请修改build_ros.sh
echo "Building ROS nodes"

cd Examples/ROS/ORB_SLAM2
mkdir build
cd build
cmake .. -DROS_BUILD_TYPE=Release
make
  •     修改ROS_PACKAGE_PATH
gedit ~/.bashrc

在最下面添加
 

export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/你的目录/ORB_SLAM2_modified/Examples/ROS

source ~/.bashrc
  •     开始编译ros接口
chmod +x build_ros.sh
./build_ros.sh

博主編譯時需要將CMakeLists.txt中的find_package( OpenCV 3.4  QUIET)版本3.4去掉,原因是:我安裝的opencv版本不在系統目錄下,也可以保留版本號,同時設置一下路徑,例如:set(OpenCV_DIR "/home/angel/opencv-3.4.0/build)   find_package(OpenCV 3.4 REQUIRED);

  • Realsense D435i 的sdk及ROS Wrapper之前已安裝編譯好

前面的一切都沒有問題了,準備運行跑一下ORB-SLAM代碼。

開三個終端:其中roscore開不開都行。

終端1:(不需要,用roslaunch是不需要roscore的)

roscore

終端2:啓動realsense相機節點

roslaunch realsense2_camera rs_rgbd.launch

終端3:回到ORB_SLAM2_modified文件夹下,运行

rosrun ORB_SLAM2 RGBD Vocabulary/ORBvoc.bin Examples/RGB-D/TUM1.yaml

其中,RGBD Vocabulary/ORBvoc.bin 是詞典路徑,Examples/RGB-D/TUM1.yaml是內參文件路徑。

这里TUM1.yaml是需要更改的,可自行去ORB_SLAM2上下载realsense的yaml,也可自己標定獲得。

 

ubuntu16.04+realsense D435I +ros kinetic+ ORB-SLAM2_第1张图片

 

 

你可能感兴趣的:(学习,SLAM)