作業系統: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是多少。