ORB_SLAM2的ROS入门1¶
编译ROS节点¶
首先编译以下节点:mono, monoAR, stereo and RGB-D
-
添加节点的源码路径到
ROS_PACKAGE_PATH
中,打开文件.bashrc
并将如下内容添加到末尾,这里要将其中的PATH/ORB_SLAM2
替换成你自己的源码路径,并确保以下内容在文件的source /opt/ros/melodic/setup.bash
之后,即编辑文件
gedit ~/.bashrc
追加以下内容
source /opt/ros/melodic/setup.bash export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM2/Examples/ROS
-
执行
source ~/.bashrc
使上述配置生效 -
执行源码目录下的
build_ros.sh
脚本chmod +x build_ros.sh ./build_ros.sh
在Ubuntu18.04之前的系统上没有问题,但是在Ubuntu18.04及以后的系统上,会出现编译报错,先解决保存问题,重新编译即可。
错误处理¶
如果运行 build_ros.sh
报出如下错误
/usr/bin/ld: CMakeFiles/Stereo.dir/src/ros_stereo.cc.o: undefined reference to symbol '_ZN5boost6system15system_categoryEv'
/usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
CMakeFiles/Stereo.dir/build.make:217: recipe for target '../Stereo' failed
make[2]: *** [../Stereo] Error 1
CMakeFiles/Makefile2:131: recipe for target 'CMakeFiles/Stereo.dir/all' failed
make[1]: *** [CMakeFiles/Stereo.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
- 确保boost环境已安装
sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
- 打开
Examples/ROS/ORB_SLAM2/CMakeLists.txt
并在如下位置添加一行lboost_system
set(LIBS
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_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
)
- 修改保存并重新编译即可
./build_ros.sh
运行节点¶
运行如下节点 之前,我们要先开启相机设备节点,保证有相机数据发布在 /camera/image_raw
话题,这样我们才能看到图像内容并进行建图和定位。
单目案例
rosrun ORB_SLAM2 Mono Vocabulary/ORBvoc.txt Examples/ROS/ORB_SLAM2/astra.yaml
单目AR案例
rosrun ORB_SLAM2 MonoAR Vocabulary/ORBvoc.txt Examples/ROS/ORB_SLAM2/astra.yaml
由于是我们实时获取的深度数据,此时深度数据缩放因数DepthMapFactor要确保为1.0。
则我们把原来的 ./Examples/ROS/ORB_SLAM2/Asus.yaml
复制一份为 ./Examples/ROS/ORB_SLAM2/astra.yaml
。并且主要要修改以下四个值
Camera.fx
Camera.fy
Camera.cx
Camera.cy
这四个值实际上是通过相机标定得来的,这个在相机相关章节会有原理讲解及实现。
Astra奥比中光相机的 astra.yaml
参考配置文件如下:
%YAML:1.0
#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------
# Camera calibration and distortion parameters (OpenCV)
Camera.fx: 577.54679
Camera.fy: 578.63325
Camera.cx: 310.24326
Camera.cy: 253.65539
Camera.k1: 0.0
Camera.k2: 0.0
Camera.p1: 0.0
Camera.p2: 0.0
Camera.width: 640
Camera.height: 480
# Camera frames per second
Camera.fps: 30.0
# IR projector baseline times fx (aprox.)
Camera.bf: 40.0
# Color order of the images (0: BGR, 1: RGB. It is ignored if images are grayscale)
Camera.RGB: 1
# Close/Far threshold. Baseline times.
ThDepth: 40.0
# Deptmap values factor
DepthMapFactor: 1.0
#--------------------------------------------------------------------------------------------
# ORB Parameters
#--------------------------------------------------------------------------------------------
# ORB Extractor: Number of features per image
ORBextractor.nFeatures: 1000
# ORB Extractor: Scale factor between levels in the scale pyramid
ORBextractor.scaleFactor: 1.2
# ORB Extractor: Number of levels in the scale pyramid
ORBextractor.nLevels: 8
# ORB Extractor: Fast threshold
# Image is divided in a grid. At each cell FAST are extracted imposing a minimum response.
# Firstly we impose iniThFAST. If no corners are detected we impose a lower value minThFAST
# You can lower these values if your images have low contrast
ORBextractor.iniThFAST: 20
ORBextractor.minThFAST: 7
#--------------------------------------------------------------------------------------------
# Viewer Parameters
#--------------------------------------------------------------------------------------------
Viewer.KeyFrameSize: 0.05
Viewer.KeyFrameLineWidth: 1
Viewer.GraphLineWidth: 0.9
Viewer.PointSize:2
Viewer.CameraSize: 0.08
Viewer.CameraLineWidth: 3
Viewer.ViewpointX: 0
Viewer.ViewpointY: -0.7
Viewer.ViewpointZ: -1.8
Viewer.ViewpointF: 500