一、安装ROS
ubuntu16.04对应的ROS版本为Kinetic,ROS Wiki传送门:http://wiki.ros.org/cn/kinetic/Installation/Ubuntu,有详细过程
二、创建并设置ROS工作空间
创建——打开终端(Ctrl+Alt+T),执行以下命令(catkin_ws是随意取的文件夹名称)
1 mkdir -p ~/catkin_ws/src
2 cd ~/catkin_ws/src
3 catkin_init_workspace
编译——在上一步的终端中接着操作
1 cd ~/catkin_ws
2 catkin_make
设置环境变量——接上一步,打开.bashrc文件,将source ~/catkin_ws/devel/setup.bash写入该文件最后一行,然后保存关闭文件,关闭终端
gedit ~/.bashrc
三、安装依赖
1.安装opencv(上文已有步骤,传送门:https://www.cnblogs.com/pgzhanglin/p/13232863.html)
2.安装Kinect 2驱动libfreenect2
1 cd catkin_ws/src
2 git clone https://github.com/OpenKinect/libfreenect2.git
3 cd libfreenect2
4 sudo apt-get install build-essential cmake pkg-config
5 sudo apt-get install libusb-1.0-0-dev
6 sudo apt-get install libturbojpeg libjpeg-turbo8-dev
7 sudo apt-get install libglfw3-dev
8 mkdir build && cd build
9 cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/freenect2
10 make
11 make install
PS:要找到libfreenect2,需要为基于cmake的第三方应用程序指定“cmake -Dfreenect2_DIR=$HOME/freenect2/lib/cmake/freenect2”(暂时没用)
3.设置udev规则,使得设备可以访问libfreenect2,并将设备接入电脑进行测试
1 sudo cp ../platform/linux/udev/90-kinect2.rules /etc/udev/rules.d/
2 ./bin/Protonect
4.安装Kinect驱动程序与ROS之间的桥——iai_kinect 2
1 cd ~/catkin_ws/src/
2 git clone https://github.com/code-iai/iai_kinect2.git
3 cd iai_kinect2
4 rosdep install -r --from-paths .
5 cd ~/catkin_ws
6 catkin_make -DCMAKE_BUILD_TYPE="Release"
四、ROS下测试Kinect V2设备
1.修改.bashrc文件,在最后一行添加代码 export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/zhanglin/catkin_ws/src/ORB_SLAM2/Examples/ROS 然后保存关闭文件
gedit ~/.bashrc
2.ROS启动kinect v2
roslaunch kinect2_bridge kinect2_bridge.launch
3.接上步,打开一个新的终端
rosrun kinect2_viewer kinect2_viewer
五、使用Kinect V2传感器,实时运行ORB_SLAM2
1.编译ROS环境下的ORB_SLAM2(开始各种报错,慢慢处理)
1 cd ~/catkin_ws/src/ORB_SLAM2/
2 chmod +x build_ros.sh
3 ./build_ros.sh
2.出现的错误及解决方案(这里只列出我制作教程时出现的一个错误及解决方案,其他错误视情况而定)
锁定两文件路径
locate boost_system
locate boost_filesystem
前往系统给出的路径中,将libboost_system.so、libboost_system.so.1.58.0等四个文件复制到/Home/catkin_ws/src/ORB_SLAM2/lib路径下,如下图。
打开ORB_SLAM2/Examples/ROS/ORB_SLAM2文件夹下的CmakeLists.txt文件,在图示位置添加两行代码:
${PROJECT_SOURCE_DIR}/../../../lib/libboost_filesystem.so
${PROJECT_SOURCE_DIR}/../../../lib/libboost_system.so
然后再次执行,成功!
1 cd ~/catkin_ws/src/ORB_SLAM2/
2 chmod +x build_ros.sh
3 ./build_ros.sh
3.在ROS中启动Kinect2
roslaunch kinect2_bridge kinect2_bridge.launch
4.打开新终端,键入rostopic list,查看Kinect2发布的话题
rostopic list
5.根据上一步发布的topic,更改ROS里面订阅的内容
将ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_rgbd.cc的内容更改为
message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "/kinect2/qhd/image_color_rect", 1);
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "/kinect2/qhd/image_depth_rect", 1);
6.重新编译工程
1 cd ~/catkin_ws/src/ORB_SLAM2/
2 chmod +x build_ros.sh
3 ./build_ros.sh
7.创建kinect2_qhd.yaml文件
在ORB_SLAM2/Examples/RGB_D文件夹下,复制一份TUM1.yaml文件,将其重命名为kinect2_qhd.yaml(里面是深度相机的内参,我们暂且用TUM1的参数,等以后我们可以自己实际标定一下该深度相机,届时可以使用我们标定好的参数)
8.运行
roslaunch kinect2_bridge kinect2_bridge.launch
打开新终端,接着输入
rosrun ORB_SLAM2 RGBD ~/catkin_ws/src/ORB_SLAM2/Vocabulary/ORBvoc.txt ~/catkin_ws/src/ORB_SLAM2/Examples/RGB-D/kinect2_qhd.yaml