ORB-SLAM3 ROS 运行

环境为:ROS Melodic 和 Ubuntu 18.04

编译

1、将源码中的 Examples/ROS/ORB_SLAM3 路径添加到ROS_PACKAGE_PATH环境变量中
打开 .bashrc file:

gedit ~/.bashrc

把下面这行加到最下面一行,把“PATH”换成你放ORB_SLAM3的路径

export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:“PATH”/ORB_SLAM3/Examples/ROS

2、执行ORB-SLAM3中打开终端,执行 build_ros.sh 文件

chmod +x build_ros.sh
./build_ros.sh

此处碰到第一个问题:会报一个类似如下的错误(我忘记截图了用了别人的例子,大差不差)

Building ROS nodes
mkdir: cannot create directory ‘build’: File exists
[rosbuild] Building package ORB_SLAM2
[rosbuild] Error from directory check: /opt/ros/kinetic/share/ros/core/rosbuild/bin/check_same_directories.py  /home/nvidia/ORBSLAM2/ORB_SLAM2/Examples/ROS/ORB_SLAM2
1
Traceback (most recent call last):
  File "/opt/ros/kinetic/share/ros/core/rosbuild/bin/check_same_directories.py", line 46, in 
    raise Exception
Exception
CMake Error at /opt/ros/kinetic/share/ros/core/rosbuild/private.cmake:102 (message):
  [rosbuild] rospack found package "ORB_SLAM2" at "", but the current
  directory is "/home/nvidia/ORBSLAM2/ORB_SLAM2/Examples/ROS/ORB_SLAM2".  You
  should double-check your ROS_PACKAGE_PATH to ensure that packages are found
  in the correct precedence order.
Call Stack (most recent call first):
  /opt/ros/kinetic/share/ros/core/rosbuild/public.cmake:177 (_rosbuild_check_package_location)
  CMakeLists.txt:4 (rosbuild_init)


-- Configuring incomplete, errors occurred!
See also "/home/nvidia/ORBSLAM2/ORB_SLAM2/Examples/ROS/ORB_SLAM2/build/CMakeFiles/CMakeOutput.log".
make: *** No targets specified and no makefile found.  Stop.

解决方法也很简单,大概就是 /ros/melodic/share 这个路径没有ORB_SLAM3的软连接,在命令行输入以下代码即可(“PATH”同上,Ubuntu18.04melodic16.04应该是kinetic)原贴连接

sudo ln -s "PATH"/ORB_SLAM3/Examples/ROS/ORB_SLAM3 /opt/ros/melodic/share/ORB_SLAM3

运行

去 EuRoC dataset 下载一个.bag文件,在ORB_SLAM文件夹打开终端,输入下面三行命令

roscore
rosrun ORB_SLAM3 Stereo_Inertial Vocabulary/ORBvoc.txt Examples/Stereo-Inertial/EuRoC.yaml true
rosbag play --pause “V1_02_medium.bag” /cam0/image_raw:=/camera/left/image_raw /cam1/image_raw:=/camera/right/image_raw /imu0:=/imu

其中第三行“V1_02_medium.bag”就是你下的文件的名字,第三行代码运行之后记得按下空格键开始播放bag文件
如果下载的是TUM数据,需要对数据进行一些处理,如下

rosrun rosbag fastrebag.py dataset-room1_512_16.bag dataset-room1_512_16_small_chunks.bag

最终运行结果

你可能感兴趣的:(linux,slam)