One, ubuntu16.04 install kinect2 and iai-kinect2
You can refer to this article kinetic2 installation and iai-kinect2
iai-kinect2
2. KInetic+Ros runs ORBSLAM2
Step:
Open Terminal 1
git clone http://github.com/raulmur/ORB_SLAM2.git
cd ORB_SLAM2
chmod +x build.sh
./build.sh #可自动编译好g2o与DBoW2并且把Vocabulary自动解压
Open a new terminal 2
gedit ~/.bashrc
在打开的文件的最后一行写入:
export ROS_PACKAGE_PATH=${
ROS_PACKAGE_PATH}:/home/wenbo/ORB_SLAM2/Examples/ROS
上面这个一定要做,否则会出错说找不到路径和包
Go back to terminal 1 and
compile the ros node:
chmod +x build_ros.sh
Ensure that the original program can be compiled:
./build_ros.sh
Open a terminal 3 from the workspace with iai-kinect2 and run:
source devel/setup.sh
roslaunch kinect2_bridge kinect2_bridge.launch
Open another terminal 4 and enter:
rostopic list #查看此时Kinect2发布的topic
Then modify the content of ros subscription in ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/ros_rgbd.cc according to the topic 3 above
message_filters::Subscriber<sensor_msgs::Image> rgb_sub(nh, "/kinect2/qhd/image_color_rect", 1); //改ros的发布
message_filters::Subscriber<sensor_msgs::Image> depth_sub(nh, "/kinect2/qhd/image_depth_rect", 1); //改ros的发布
Go back to Terminal 1
and recompile the project:
chmod +x build_ros.sh
./build_ros.sh
Open a terminal 5 and enter:
rqt_graph #查看话题是否接上
Similar to the figure below:
Finally, open terminal 6 in ORB_SLAM2/Examples/Ros and enter
rosrun ORB_SLAM2 RGBD /home/wenbo/ORB_SLAM2/Vocabulary/ORBvoc.txt /home/wenbo/ORB_SLAM2/Examples/RGB-D/kinect2_qhd.yaml
Note: Real-time online trajectory can be obtained (To solve the waiting for image, you need to recompile ROS/ORB_SLAM2 after modifying ros_rgbd.cc and publishing. Here, even if ros_rgbd.cc has been opened, but the content inside has not been modified, it is recommended to recompile again )
Problems that may be encountered during the above compilation process:
Problem 1: libboost_system.so and libboost_filesystem.so cannot find the link directory.
Solution:
locate boost_system
Find the directory
/usr/lib/x86_64-linux-gnu/libboost_system.a
/usr/lib/x86_64-linux-gnu/libboost_system.so
/usr/lib/x86_64-linux-gnu/libboost_system.so.1.58.0
Copy libboost_system.a, libboost_system.so to ORB_SLAM2/lib
Question 2: ORB_SLAM2 is executed when compiling. /build_ros.sh error:'usleep' was not declared in this scope.
Solution:
Add the header file #include< in ORB_SLAM2/Examples/ROS/ORB_SLAM2/src/AR/ViewerAR.cc unistd.h>
Reference blog: kinect+Ros+ORBSLAM2
The final running result: