首先克隆并编译:
参考:https://blog.csdn.net/qq_17232031/article/details/79519695
首先要安装一些依赖库,比如eigen opencv DBoW3 Pangolin…等等,在我之前的博客里面有写
或者安装依赖库这一部分百度其他博客,我就不展示了
当然,如果你是看完一整本slam十四讲过来的,那么没问题,这些库你都有
1.新建workspace
$ mkdir common_space
$ cd ./common_space
$ mkdir src
2.cd到src下,然后
$ catkin_init_workspace
3.cd回到common_space(cd …),然后
catkin_make
4.安装依赖项
sudo apt install autotools-dev ccache doxygen dh-autoreconf git liblapack-dev libblas-dev libgtest-dev libreadline-dev libssh2-1-dev pylint clang-format-3.8 python-autopep8 python-catkin-tools python-pip python-git python-setuptools python-termcolor python-wstool --yes
5.克隆一下源码(随便一个地方)
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
6.将克隆下来的ORB_SLAM2文件移入common_space/src下
7.安装ORB_SLAM2
cd ORB_SLAM2
chmod +x build.sh
./build.sh
8.编译ros版本的ORB_SLAM2, 同样是在ORB_SLAM2下
chmod +x build_ros.sh
./build_ros.sh
补充:chmod +x .sh的作用为sh文件增加可执行权限
在解决问题之前,让我们先进行:
在/.bashrc中加入:
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/mjy/dev/common_space/src/ORB_SLAM2/Examples/ROS
source /home/mjy/dev/common_space/devel/setup.sh
source /home/mjy/dev/common_space/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/build/devel/setup.bash
路径更为自己对应的路径即可.
然后在终端
$ source ~/.bashrc
下面列一些常见报错
(1) error: ‘usleep’ was not declared in this scope usleep(3000);
解决办法: 在报错的.cc文件中加入头文件:
#include
(2)下面一大串…具体错误显示在/stereo_euroc.cc.o’ failed
Please submit a full bug report,
with preprocessed source if appropriate.
See
CMakeFiles/stereo_euroc.dir/build.make:62: recipe for target ‘CMakeFiles/stereo_euroc.dir/Examples/Stereo/stereo_euroc.cc.o’ failed
make[2]: *** [CMakeFiles/stereo_euroc.dir/Examples/Stereo/stereo_euroc.cc.o] Error 4
CMakeFiles/Makefile2:289: recipe for target ‘CMakeFiles/stereo_euroc.dir/all’ failed
make[1]: *** [CMakeFiles/stereo_euroc.dir/all] Error 2
make[1]: *** 正在等待未完成的任务…
c++: internal compiler error: 已杀死 (program cc1plus)
Please submit a full bug report,
with preprocessed source if appropriate.
See
CMakeFiles/rgbd_tum.dir/build.make:62: recipe for target ‘CMakeFiles/rgbd_tum.dir/Examples/RGB-D/rgbd_tum.cc.o’ failed
make[2]: *** [CMakeFiles/rgbd_tum.dir/Examples/RGB-D/rgbd_tum.cc.o] Error 4
CMakeFiles/Makefile2:215: recipe for target ‘CMakeFiles/rgbd_tum.dir/all’ failed
make[1]: *** [CMakeFiles/rgbd_tum.dir/all] Error 2
解决办法: 在ORB_SLAM2文件下的CMakeLists.txt文件中(即:/home/mjy/dev/common_space/src/ORB_SLAM2/CMakeLists.txt)文件中,将eigen和opencv库的版本号改成自己电脑上的版本号.我的是:
# find_package(OpenCV 3.0 QUIET) 这是原先的
find_package(OpenCV 3.2.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()
# find_package(Eigen3 3.1.0 REQUIRED) 这是原先的
find_package(Eigen3 3.3.7 REQUIRED)
find_package(Pangolin REQUIRED)
(3) 未定义的标识----一串奇怪的东西
Undefined reference to symbol ‘_ZN5boost6system15system_categoryEv’
解决办法:
修改ORB_SLAM2/Examples/ROS/ORB_SLAM2中CMakelists.txt,在set那里添加-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
)
(4)虽然之前改变过opencv和eigen的版本,但是example中的版本没有改变,因此在这里:
打开/home/mjy/dev/common_space/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/CMakeLists.txt
注意,是两层ORB_SLAM2的第二层,ROS里面的.
依然是按照之前的方法,更改版本
ok,大致是这些错误.如果没有包含,一般都百度得到.
接下来安装usb_cam
git clone https://github.com/bosch-ros-pkg/usb_cam.git
# 然后将clone的文件夹移动到src之下(也不一定非要吧)
cd usb_cam
mkdir build
cd build
cmake ..
make
启动一下试试
$ roscore
$ roslaunch usb_cam usb_cam-test.launch
参考:https://www.jianshu.com/p/f39bf76cfc61
先编译一下
cd /home/mjy/dev/common_space/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/
mkdir build
cd build
cmake .. -DROS_BUILD_TYPE=Release
make -j4
由于需要订阅电脑摄像头usb_cam/image_raw的话题, 所以需要找到文件
/home/mjy/dev/common_space/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_mono.cc
再其64行的样子改为:
# 原先为ros::Subscriber sub = nodeHandler.subscribe("/camera/image_raw", 1, &ImageGrabber::GrabImage,&igb);
# 更改订阅话题
ros::Subscriber sub = nodeHandler.subscribe("/usb_cam/image_raw", 1, &ImageGrabber::GrabImage,&igb);
由于更改了文件,需要重新编译,首先回到最大的ORB_SLAM2之下:
cd /home/mjy/dev/common_space/src/ORB_SLAM2
./build.sh
./build_ros.sh
其实只用ros那一个build即可
让我们看看./build_ros.sh到底是什么内容:
echo "Building ROS nodes"
cd Examples/ROS/ORB_SLAM2
mkdir build
cd build
cmake .. -DROS_BUILD_TYPE=Release
make -j
奥!原来如此,这个.sh文件就是把需要在命令号一句一句编译的东西写成文件,然后一句话搞定
ok,这下编译成功(如果还报错的话见我上面写的报错类型)
接下来启动roscore和usb_cam:
roscore
roslaunch usb_cam usb_cam-test.launch
然后,由于需要用到字典文件和相机标定文件,因此:ORBvoc.txt 和Asus.yaml 要作为参数传入,并启动orbslam节点
rosrun ORB_SLAM2 Mono /home/mjy/dev/common_space/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/mjy/dev/common_space/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/Asus.yaml
然后就跑起来了
可能会存在一直初始化的问题:
这是由于标定参数不准导致的. 因为用的是Asus.yaml, 这是源码自带的标定文件,因此需要自己标定一下电脑上的摄像头
参考:https://blog.csdn.net/xyt723916/article/details/89374201
先看这个吧:https://www.jianshu.com/p/ad040b374b2f
在下载TUM数据集:TUM数据集 下载并解压一个序列,如:rgbd_dataset_freiburg1_desk1.tgz
下载官网链接:https://link.jianshu.com/?t=http%3A%2F%2Fvision.in.tum.de%2Fdata%2Fdatasets%2Frgbd-dataset%2Fdownload
找那个f1_desk啥的就可以
然后在ORB-SLAM2目录下(注意不是Example下的ORB-SLAM2哈)创建一个文件夹 Data 将数据集放置在该文件夹下,并进行解压。
cd ORB-SLAM2
mkdir Data
tar -zxvf rgbd_dataset_freiburg1_desk.tgz
接下来 在终端输入
./Examples/Monocular/mono_tum Vocabulary/ORBvoc.txt Examples/Monocular/TUM1.yaml Data/rgbd_dataset_freiburg1_desk
测试成功
TUM官网下载 rgbd_dataset_freiburg1_desk.bag
测试之前记得把usb_cam/image_raw改回camera/image_raw
然后重新回到最大的ORB_SLAM那里编译一下:
./build_ros.sh
然后开始测试:
roscore
rosrun ORB_SLAM2 Mono /home/mjy/dev/common_space/src/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/mjy/dev/common_space/src/ORB_SLAM2/Examples/ROS/ORB_SLAM2/Asus.yaml
rosbag play /home/mjy/文档/数据集/TUM/bag/rgbd_dataset_freiburg1_desk.bag /camera/rgb/image_color:=/camera/image_raw
注意有个重映射(remap),需要将bag中的单目图像image_color话题重映射为slam代码中订阅的/camera/image_raw,也就是让你改回去的地方