本文直接使用的github上的orb_slam_2_ros实现在ROS上运行ORB-SLAM2,这个ros包能够得到相机的位姿以及稀疏点云,而且删掉了对Pangolin的依赖,进行可视化时要用RViz。

运行环境
硬件环境:Intel Up2、Realsense D435i
软件环境:Ubuntu18.04、ROS melodic、librealsense2.29、realsense-ros2.2.9
安装依赖项
安装Eigen3
这是矩阵运算用到的库,下载地址: http://eigen.tuxfamily.org,最低版本要求为3.1.0,也可以使用sudo apt install libeigen3-dev安装

安装openCV
openCV3.2.0的下载地址:https://codeload.github.com/opencv/opencv/tar.gz/3.2.0

安装orb_slam2_ros
配置一个工作环境

mkdir -p ~/orbslam2_workspace/src
cd ~/orbslam2_workspace
source /opt/ros/melodic/setup.bash
catkin init
catkin config --extend /opt/ros/melodic
catkin config --cmake-args -DCMAKE_BUILD_TYPE=Release

使用catkin build进行编译

cd ~/orbslam2_workspace/src
git clone https://github.com/appliedAI-Initiative/orb_slam_2_ros.git
cd ~/orbslam2_workspace
catkin build

当然也可以使用catkin_make来编译

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src/
git clone https://github.com/appliedAI-Initiative/orb_slam_2_ros.git
catkin_init_workspace
cd ~/catkin_ws/
catkin_make

运行orb_slam2_ros首先需要执行

source ~/orbslam2_workspace/devel/setup.bash

依次运行

roslaunch realsense2_camera rs_rgbd.launch
roslaunch orb_slam2_ros orb_slam2_d435_rgbd.launch

运行rs_rgbd.launch时可能出错,解决方法:

sudo apt install ros-melodic-rgbd-launch

打开rviz

rviz

打开后,点击Add->By topic,选择orbslam2节点发布的pose、PointCloud2等话题,就可以显示相机位姿和稀疏点云。至于效果,如下图,在Up2上运行起来很流畅,但是似乎没有显示位姿的高度信息

保存地图程序运行时,会发布一个地图话题,使用如下命令保存地图

rosservice call /orb_slam2_rgbd/save_map map.bin

其中map.bin可以自己更改前缀名,这个文件将会保存在ROS_HOME,默认为~/.ros