操作系统:Ubuntu16.04
ROS版本: Kinetic
1.ROS的安装,可以参考http://blog.csdn.net/qq_17232031/article/details/79519308 ,这里不再叙述。
2.新建一个WorkSpace
$ mkdir catkin_ws
$ cd ./catkin_ws
$ mkdir src
3.设定src为工作空间,在src目录下:
$ catkin_init_workspace
4.回到catkin_ws目录下执行:
$ catkin_make
第3,4步若出现Not Found the Command错误,则要安装catkin,输入一下的命令:
$ git clone https://github.com/ros/catkin.git
$ cd catkin
$ mkdir build
$ cd build
$ cmake ..
$ make -j8 && make install
$ cd ..
$ python2 setup.py install
$ python3 setup.py install
切记,Python 中一定要安装catkin_pkg模块
pip install catkin_pkg
或
pip3 install catkin_pkg
安装一些依赖项:
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.下载ORB_SLAM2源码:
git clone https://github.com/raulmur/ORB_SLAM2.git ORB_SLAM2
6.将ORB_SLAM2文件移入catkin_ws/src下
$ sudo mv ORB_SLAM2 ./catkin_ws/src
7.安装ORB_SLAM2,Ranul Mur-Artal大神的github(https://github.com/raulmur/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
此时就开始有坑了,可能会出现一下错误:
CMake Error at /opt/ros/kinetic/share/ros/core/rosbuild/public.cmake:129 (message):
Failed to invoke rospack to get compile flags for package 'ORB_SLAM2'.
Look above for errors from rospack itself. Aborting. Please fix the
broken dependency!
Call Stack (most recent call first):
/opt/ros/kinetic/share/ros/core/rosbuild/public.cmake:207 (rosbuild_invoke_rospack)
CMakeLists.txt:4 (rosbuild_init)
-- Configuring incomplete, errors occurred!
此时记得在 ~/.bashrc末尾添加:
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/ORB_SLAM2/Examples/ROS
其中PATH是自己的工作空间路径(/home/(user名)/catkin_ws/src),然后记得:
$ source ~/.bashrc
还没解决的话,使用以下命令:
$ sudo rosdep fix-permissions
$ rosdep update
然后继续编译,可能又会出现一个坑,心累~:
MakeFiles/Makefile2:718: recipe for target 'CMakeFiles/Mono.dir/all' failed
make[1]: *** [CMakeFiles/Mono.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make[2]: *** No rule to make target '/opt/ros/kinetic/lib/libopencv_calib3d3.so.3.2.0', needed by '../RGBD'. Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/RGBD.dir/all' failed
make[1]: *** [CMakeFiles/RGBD.dir/all] Error 2
make[2]: *** No rule to make target '/opt/ros/kinetic/lib/libopencv_calib3d3.so.3.2.0', needed by '../Stereo'. Stop.
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/Stereo.dir/all' failed
make[1]: *** [CMakeFiles/Stereo.dir/all] Error 2
解决办法:修改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
)
然后在编译,就能够成功了.
如果要在ROS下利用自己的摄像头跑ORB_SLAM2,那麽还需要安装usb_cam
下载链接(https://github.com/ros-drivers/usb_cam),下载下来,一样的移到src下
或这在src下利用git命令
git clone https://github.com/bosch-ros-pkg/usb_cam.git
编译usb_cam:
$ mkdir build
$ cd build
$ cmake ..
$ make
打开摄像头,需要启动ros,在两个不同的终端分别执行以下命令:
$ roscore
$ roslaunch usb_cam usb_cam-test.launch
这样,就能启动摄像头了,其中,我们可以打开位于usb_cam/launch下的launch文件:
<launch>
<node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
<param name="video_device" value="/dev/video1" />
<param name="image_width" value="1280" />
<param name="image_height" value="480" />
<param name="pixel_format" value="yuyv" />
<param name="camera_frame_id" value="usb_cam" />
<param name="io_method" value="mmap"/>
</node>
<node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">
<remap from="image" to="/usb_cam/image_raw"/>
<param name="autosize" value="true" />
</node>
</launch>
其中value="/dev/video0"为笔记本摄像头,这里为video1,当然读者可以去/dev目录下查看自己的摄像头对应的value是多少。