DS-SLAM 編譯安裝運行全程記錄 RTX2060+CUDA10+CUDNN7

我自己的DS-SLAM安裝記錄

前言:我自己第一次裝得時候,編譯完成後,roslaunch xx.lauch運行的時候ros總是意外崩潰,使用的是作者的源代碼,考慮到可能是環境的問題,也許我之前某些步驟使用了make install,把某些庫直接裝在的系統中,導致ds找不到與其對應正確的版本,直接讀到系統中的庫。所以重新裝了一次系統,從頭開始,從週日下午到週二,總共花費了兩天多,在劉陽學弟和黃凱學長的大力幫助下,終於是跑通了原始DS-SLAM,研究學習的第一步復現,算是完成了,下面我將詳細的敘述一下這次環境配置過程。再次感謝劉陽和黃凱學長!!
大體流程 nvidia顯卡驅動->CUDA10+cudnn7->ros(包含opencv)->caffe-segnet-cudnn7->octomap_mapping+octomao_rviz->DS_SLAM源碼

系統版本&硬件

ubuntu 16.04
Intel® Core™ i7-8700 CPU @ 3.20GHz × 12
GeForce RTX 2060/PCIe/SSE2

CUDA & cudnn

一開始我安裝的是CUDA9.0,後面編譯caffe的時候提示我 cuda9.0不支持compute_75,然後我又重新安裝CUDA10.0 以及配套的Cudnn7.3.0 這些安裝教程網上比較多,只要注意與自己的顯卡算力版本對應即可。
安裝完成後,可以輸入以下指令,確認自己安裝的版本。

1、查看cuda版本

cat /usr/local/cuda/version.txt
#output:
CUDA Version 10.0.130

2、查看cudnn版本

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
#output:
MAJOR -A 2
#define CUDNN_MAJOR 7
#define CUDNN_MINOR 3
#define CUDNN_PATCHLEVEL 0
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)

#include "driver_types.h"

nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:01_CDT_2018
Cuda compilation tools, release 10.0, V10.0.130

ROS Kinetic

按照官方網站教程,網址在這:http://wiki.ros.org/kinetic/Installation/Ubuntu
還需要安裝這個catkin,http://wiki.ros.org/catkin ,記得選kinetic選項
裝好之後 http://wiki.ros.org/ROS/Tutorials/CreatingPackage

遇到的問題

問題1:在執行到這兩步的時候

# With the following, you can initialize rosdep.
sudo rosdep init
rosdep update

出現的問題

sudo rosdep init ERROR: cannot download default sources list

解決方法

#打開hosts文件
sudo gedit /etc/hosts
#在文件末尾添加
151.101.84.133  raw.githubusercontent.com
#保存後退出再嘗試

問題2 catkin_make時出現

The imported target “xxx” references the file “/usr/lib/x86_64-linux-gnu/libEGL.so” but this file does not exist. 

解決辦法:https://askubuntu.com/questions/616065/the-imported-target-qt5gui-references-the-file-usr-lib-x86-64-linux-gnu-li

opencv + caffe

這裏採用的黃凱學長的方法,不單獨安裝opencv,使用ros裏面自帶的opencv。
https://blog.csdn.net/abc039510/article/details/103032120

原版DS推薦下載caffe-segnet-cudnn5,我考慮到我自己安裝的cudnn版本,我下載的是 https://github.com/navganti/caffe-segnet-cudnn7,
安裝在/home/xxx/catkin_ws/src/DS-SLAM/Examples/ROS/ORB_SLAM2_PointMap_SegNetM/目錄下
需要注意的是,安裝caffe的時候 要用cmake,我當初使用make的時候一堆報錯,
不知道如何解決,但是使用cmake的時候就不出錯了,在caffe-segnet-cudnn7目錄下

mkdir build
cd build
cmake ..
# -jx根據自己電腦性能選擇,我這臺主機可以跑 make all -j12
make all -j12
#測試caffe安裝的時候,會跑蠻久
make runtest -j12

如果你安裝的是caffe-segnet-cudnn7的版本

記得改一下這幾個cmakelists.txt裏面的路經,所有跟cudnn5相關的都改成cudnn7

1./home/xxx/catkin_ws/src/DS-SLAM/Examples/ROS/ORB_SLAM2_PointMap_SegNetM/CMakeLists.txt 
2./home/xxx/catkin_ws/src/DS-SLAM/Examples/ROS/ORB_SLAM2_PointMap_SegNetM/libsegmentation/CMakeLists.txt
3./home/xxx/catkin_ws/src/DS-SLAM/CMakeLists.txt

#舉個例子 ./home/xxx/catkin_ws/src/DS-SLAM/Examples/ROS/ORB_SLAM2_PointMap_SegNetM/CMakeLists.txt
#54行左右 
${PROJECT_SOURCE_DIR}/../../../Examples/ROS/ORB_SLAM2_PointMap_SegNetM/caffe-segnet-cudnn5/include 
${PROJECT_SOURCE_DIR}/../../../Examples/ROS/ORB_SLAM2_PointMap_SegNetM/caffe-segnet-cudnn5/build/include
#更改爲
${PROJECT_SOURCE_DIR}/../../../Examples/ROS/ORB_SLAM2_PointMap_SegNetM/caffe-segnet-cudnn7/include 
${PROJECT_SOURCE_DIR}/../../../Examples/ROS/ORB_SLAM2_PointMap_SegNetM/caffe-segnet-cudnn7/build/include
#也就是把5改成7即可。

如果你安裝的是caffe-segnet-cudnn5的版本,你可能會遇到如下問題,caffe 與cudnn版本不匹配

報錯信息如下

 ./include/caffe/util/cudnn.hpp:127:41: error: too few arguments to function

解決辦法:

 1.將./include/caffe/util/cudnn.hpp 換成最新版的caffe裏的cudnn的實現,即相應的cudnn.hpp.
 
 2將./include/caffe/layers裏的,所有以cudnn開頭的文件,例如cudnn_conv_layer.hpp。   都替換成最新版的caffe裏的相應的同名文件。
 
 3.將./src/caffe/layer裏的,所有以cudnn開頭的文件,例如cudnn_lrn_layer.cu,cudnn_pooling_layer.cpp,cudnn_sigmoid_layer.cu。都替換成最新版的caffe裏的相應的同名文件。

詳細的caffe安裝步驟可以參考
https://blog.csdn.net/yhaolpz/article/details/71375762
中的第9步安裝 caffe。

make runtest 可能出現的問題

F0608 21:45:54.079473  3250 cudnn_softmax_layer.cu:20] Check failed: status == CUDNN_STATUS_SUCCESS (32 vs. 0)  CUDNN_STATUS_EXECUTION_FAILED
Aborted (core dumped)
src/caffe/test/CMakeFiles/runtest.dir/build.make:57: recipe for target 'src/caffe/test/CMakeFiles/runtest' failed
make[3]: *** [src/caffe/test/CMakeFiles/runtest] Error 134
CMakeFiles/Makefile2:328: recipe for target 'src/caffe/test/CMakeFiles/runtest.dir/all' failed
make[2]: *** [src/caffe/test/CMakeFiles/runtest.dir/all] Error 2
CMakeFiles/Makefile2:335: recipe for target 'src/caffe/test/CMakeFiles/runtest.dir/rule' failed
make[1]: *** [src/caffe/test/CMakeFiles/runtest.dir/rule] Error 2
Makefile:240: recipe for target 'runtest' failed
make: *** [runtest] Error 2

解決辦法

我一開始安裝cunn7.6.4遇到的,修改cudnn 從7.6.4 改成7.5解決,我第二次裝得是cudnn7.3.6,也沒遇到過這個問題

其他我遇到的問題

問題1

/usr/bin/ld: .build_release/lib/libcaffe.so: undefined reference to symbol '_ZNK2cv9Exception4whatEv'
/usr/lib/x86_64-linux-gnu/libopencv_core.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:637: recipe for target '.build_release/tools/upgrade_net_proto_binary.bin' failed
make: *** [.build_release/tools/upgrade_net_proto_binary.bin] Error 1

解決辦法,使用cmake即可。

問題2

In file included from /home/xxx/ds-slam/DS-SLAM/Examples/ROS/ORB_SLAM2_PointMap_SegNetM/libsegmentation/libsegmentation.cpp:34:0:
/home/xxx/ds-slam/DS-SLAM/Examples/ROS/ORB_SLAM2_PointMap_SegNetM/libsegmentation/libsegmentation.hpp:37:27: fatal error: caffe/caffe.hpp: No such file or directory
compilation terminated.
CMakeFiles/segmentation.dir/build.make:62: recipe for target 'CMakeFiles/segmentation.dir/libsegmentation.cpp.o' failed

解決辦法:https://blog.csdn.net/yinghuaxuan/article/details/89969197

OctoMap and RVIZ

安裝官方要求,先下載 https://github.com/OctoMap/octomap_mapping and https://github.com/OctoMap/octomap_rviz_plugins.
下載到 catkin_ws/src下,
然後

sudo apt-get install ros-kinetic-octomap  ros-kinetic-octomap-msgs ros-kinetic-octomap-ros ros-kinetic-octomap-rviz-plugins 
#注意,有兩個包不用裝,ros-kinetic-octomap-mapping 和ros-kinetic-octomap-server,這兩個包我們已經手動下載到,catkin_ws/src下

然後參考黃凱學長的方法,(原作者沒寫2)

1.打開頭文件開關#define COLOR_OCTOMAP_SERVER,文件路徑(catkin_ws/src/octomap_mapping/octomap_server/include/octomap_server/octomapServer.h)
2.彩色八叉地圖參數設置:<param name="colored_map" type="bool" value="True" />,文件路徑
(/catkin_ws/src/DS-SLAM/Examples/ROS/ORB_SLAM2_PointMap_SegNetM/launch/Octomap.launch)

然後catkin_make即可

遇到的問題

問題1
運行ds的時候報錯

Error:cannot launch node of type [map_server/map_server]: can't locate node [map_server]  類似的錯誤

解決辦法,切換工作空間

source ~/catkin_ws/devel/setup.bash 

問題2
運行ds如果報錯

Colored map requested in launch file - node not running/compiled to support colors, please define COLOR_OCTOMAP_SERVER and recompile or launch the octomap_color_server node this is line 127"

解決辦法,要麼是忘記打開頭文件開關#define COLOR_OCTOMAP_SERVER,要麼是使用sudo apt-get install ros-kinetic-octomap-server,導致ros找到了系統裏的 octomap-server, 卸載掉 sudo apt-get remove ros-kinetic-octomap-server。 讓ros找到我們裝在catkin_ws/src下的octomap_mapping包。

ORB-SLAM2 & DS-SLAM

需按照github提供的鏈接下載Thirdparty and Vocabulary(provided at https://pan.baidu.com/s/1-zWXlzOn-X0tjoEF9XI6qA, extract code: 8t7x)。如果用自己的,可能會出現後綴名不同的情況。這裏直接編譯會出現orb詞典錯誤,需按照TemplatedVocabulary.h或者TemplatedVocabulary.h(高翔)替換第三方庫中的DBoW2庫中相對應的文件,因爲DS-SLAM給的第三方庫中的該文件下定義的類中沒有對應的loadFromBinaryFile(strVocFile)成員函數。
原文鏈接:https://blog.csdn.net/weixin_43823054/java/article/details/104611324

我在裝DS-slam 之前,忘記安裝pangolin ,記得不要把這個裝在catkin_ws/src 裏,不然每次安裝的時候就需要 catkin_make_isolated,雖然不影響,但是編譯輸出挺多的。
這部分就是在上面的安裝步驟都完成之後,運行

cd DS-SLAM
chmod +x DS_SLAM_BUILD.sh
./DS_SLAM_BUILD.sh

TUM生成之後,修改 PATH_TO_SEQUENCE & PATH_TO_SEQUENCE/associate.txt in the DS_SLAM_TUM.launch,然後運行

cd DS-SLAM
roslaunch DS_SLAM_TUM.launch 

會有一個RVIz的程序運行,選擇左下角的add,選擇by topic,選擇occupied_cells_vis_array下的MarkerArray,就可以復現成功啦。
結果長這樣
在這裏插入圖片描述

遇到的其它問題

  1. Anaconda與ROS不兼容問題解決辦法
    https://www.cnblogs.com/hgl0417/p/11562580.html
  2. 問題如下
  [rosbuild] Building package ORB_SLAM2_PointMap_SegNetM
Failed to invoke /opt/ros/kinetic/bin/rospack deps-manifests ORB_SLAM2_PointMap_SegNetM
ImportError: No module named rosdep2.rospack
[rospack] Error: could not find python module 'rosdep2.rospack'. is rosdep up-to-date (at least 0.10.4)?

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_PointMap_SegNetM'.  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)

使用批處理 DS_SLAM_BUILD.sh 可解決。

Traceback (most recent call last):
  File "/opt/ros/kinetic/share/ros/core/rosbuild/bin/check_same_directories.py", line 46, in <module>
    raise Exception
Exception
CMake Error at /opt/ros/kinetic/share/ros/core/rosbuild/private.cmake:102 (message):
  [rosbuild] rospack found package "ORB_SLAM2_PointMap_SegNetM" at "", but
  the current directory is
  "/home/xxx/catkin_ws/src/DS-SLAM/Examples/ROS/ORB_SLAM2_PointMap_SegNetM".
  You should double-check your ROS_PACKAGE_PATH to ensure that packages are
  found in the correct precedence order.

解決辦法:export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:PATH/DS-SLAM/Examples/ROS/ORB_SLAM2_PointMap_SegNetM
PATH爲catkin_ws/src的路經。

寫的還是有點亂的,希望能對大家有所幫助,有問題可以問我,如果我還記得:)。20200617

參考資料

有些我已經在上面列過了,下面是我主要的參考資料。

  1. https://blog.csdn.net/yinghuaxuan/article/details/89969197
  2. https://blog.csdn.net/yhaolpz/article/details/71375762
  3. https://blog.csdn.net/abc039510/article/details/103032120
  4. https://blog.csdn.net/weixin_43823054/java/article/details/104611324
  5. https://blog.csdn.net/u013468614/article/details/102917569
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章