ROS下使用 Realsense D435i 运行ORBSLAM2_with_pointcloud_map
程序员文章站
2022-04-16 21:25:38
...
- 首先clone高博的代码
git clone https://github.com/gaoxiang12/ORBSLAM2_with_pointcloud_map.git
- 此时应该有以下几个文件,具体的步骤也可以在README.md中看到:
- 解压 orbslam2_modified.zip文件,将这个文件夹下的ORB_SLAM2_modified文件夹拖出来覆盖到根目录下的ORB_SLAM2_modified,把这个文件夹下的g2o_with_orbslam2文件夹也拖到根目录,之后这个文件夹内就没东西了,删了吧,如下:
- 原包ROS不友好,可以下载另外一个包
git clone https://github.com/wylnii/ORBSLAM2_with_pointcloud_map.git
替换原包中的ORB_SLAM2_modified文件夹下的所有文件
- 保证你的eigen版本在Eigen3.2.x至少不低:
下载: Eigen3.2.10
cd eigen-eigen-b9cd8366d4e8
mkdir build
cd build
cmake ..
make
sudo make install
- 编译g2o_with_orbslam2包:
cd g2o_with_orbslam2
mkdir build
cmake ..
make
sudo make install
- 安装Pangolin
git clone https://github.com/stevenlovegrove/Pangolin.git
cd Pangolin
mkdir build
cd build
cmake ..
make
sudo make install
- 准备编译ORB_SLAM2_modified
cd ORB_SLAM2_modified/
rm -rf Thirdparty/DBoW2/build/
rm -rf Thirdparty/g2o/build/
- 下载ORBvoc.txt.tar.gz放置于Vocabulary文件夹下
ORBvoc.txt.tar.gz - 如果你github下载不下来,就试试我上传的
ORBvoc.txt.tar.gz - 保证opencv版本的一致,修改ORB_SLAM2_modified下以及ORB_SLAM2_modified/Examples/ROS/ORB_SLAM2目录下的CMakeLists.txt,这里统一修改为你电脑里的opencv版本
find_package(OpenCV 3.0 QUIET)
# find_package(OpenCV 3.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()
- 如果你的电脑很渣,修改ORB_SLAM2_modified文件夹下的build.sh,将所有make -j中的-j去掉
echo "Configuring and building Thirdparty/DBoW2 ..."
cd Thirdparty/DBoW2
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
cd ../../g2o
echo "Configuring and building Thirdparty/g2o ..."
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
cd ../../../
echo "Uncompress vocabulary ..."
cd Vocabulary
tar -xf ORBvoc.txt.tar.gz
cd ..
echo "Configuring and building ORB_SLAM2 ..."
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
cd ..
echo "Converting vocabulary to binary"
./tools/bin_vocabulary
- 开始编译ORB_SLAM2_modified
chmod +x build.sh
./build.sh
- 修改ORB_SLAM2_modified/Examples/ROS/ORB_SLAM2/文件夹下的cmakelist,注意你电脑里应该安装了pcl库,如果没有请自行安装,-lboost_system一句加上
find_package(Pangolin REQUIRED)
find_package(PCL 1.7 REQUIRED)
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/../../../
${PROJECT_SOURCE_DIR}/../../../include
${Pangolin_INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
)
add_definitions(${PCL_DEFINITIONS})
link_directories(${PCL_LIBRARY_DIRS})
set(LIBS
${OpenCV_LIBS}
${EIGEN3_LIBS}
${Pangolin_LIBRARIES}
${PCL_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
)
- 修改ORB_SLAM2_modified/Examples/ROS/ORB_SLAM2/src/ros_rgbd.cc文件,把rgb_topic和depth_topic订阅话题修改为
"/camera/color/image_raw";
"/camera/aligned_depth_to_color/image_raw";
- 回到ORB_SLAM2_modified
- 渣电脑请修改build_ros.sh
echo "Building ROS nodes"
cd Examples/ROS/ORB_SLAM2
mkdir build
cd build
cmake .. -DROS_BUILD_TYPE=Release
make
- 修改ROS_PACKAGE_PATH
gedit ~/.bashrc
在最下面添加
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/你的目录/ORB_SLAM2_modified/Examples/ROS
source ~/.bashrc
- 开始编译ros接口
chmod +x build_ros.sh
./build_ros.sh
- 确定电脑已经安装好Realsense D435i 的sdk,如果没有安装如下安装:
sudo apt-key adv --keyserver keys.gnupg.net --recv-key C8B3A55A6F3EFCDE || sudo apt-key adv --keyserver
Ubuntu 16 LTS:
sudo add-apt-repository "deb http://realsense-hw-public.s3.amazonaws.com/Debian/apt-repo xenial main" -u
sudo apt-get update
sudo apt-get install librealsense2-dkms
sudo apt-get install librealsense2-utils
- 编译ROS Wrapper
mkdir realsense
cd realsense
mkdir src
cd src
git https://github.com/intel-ros/realsense.git
cd ..
catkin_make
source devel/setup.bash
- 至此,如果一切没有问题了,请运行
roslaunch realsense2_camera rs_rgbd.launch
- 新开终端,回到ORB_SLAM2_modified文件夹下,运行
rosrun ORB_SLAM2 RGBD Vocabulary/ORBvoc.bin Examples/RGB-D/TUM1.yaml
这里TUM1.yaml是我随便写的,请自行去ORB_SLAM2上下载realsense的yaml