Playing Kinect 2 with ROS in Ubuntu 16.04: Hello World
OS: Ubuntu 16.04.02 x64
ROS: Kinetic
Device: Kinect 2
OpenCV: 2.4.13.3
USB 3.0 Controller is essential
Now we begin to talk about how to play kinect2 with ROS. Note that OpenCV 2.4.X is essential and OpenCV 3 will not work. You can check the verison of your OpenCV by type in:
pkg-config --modversion opencv
Install libfreenect2
There are some ways to drive kinect 2 in linux. Here we only talk about libfreenect2, which is very convenient. You can follow this instruction to install it if you want more details. However, if you would like to play with kinect 2 as soon as possible, just go ahead.
Download libfreenect2:
git clone https://github.com/OpenKinect/libfreenect2.git
cd libfreenect2
Install build tools:
sudo apt-get install build-essential cmake pkg-config
Install libusb: (version >= 1.0.20), TurboJPEG and OpenGL
sudo apt-get install libusb-1.0-0-dev
sudo apt-get install libturbojpeg libjpeg-turbo8-dev
sudo apt-get install libglfw3-dev
Build
mkdir build && cd build
cmake .. -DENABLE_CXX11=ON -DCMAKE_INSTALL_PREFIX=$HOME/freenect2
make
make install
A Test
Run a program: (Never forget to plug your Kinect 2)
./bin/Protonect
Then you will see the following window if nothing goes wrong.
Install IAI Kinect2
Now go to your catkin workspace. Let’s try to get the iai_kinect2 package and make it.
Follow this instruction if you want more details.
cd $YOUR_CATKIN_WORKSPACE_PATH/src
git clone https://github.com/code-iai/iai_kinect2.git
cd iai_kinect2
rosdep install -r --from-paths .
rosdep will output errors on not being able to locate [kinect2_bridge] and [depth_registration]. Never mind, that is fine because they are all part of the iai_kinect2 package and rosdep does not know these packages.
cd ~/YOUR_CATKIN_WORKSPACE_PATH
catkin_make -DCMAKE_BUILD_TYPE="Release"
Run kinect2_bridge :
roslaunch kinect2_bridge kinect2_bridge.launch
Then you can see that some nodes are running:
/kinect2
/kinect2_bridge
/kinect2_points_xyzrgb_hd
/kinect2_points_xyzrgb_qhd
/kinect2_points_xyzrgb_sd
/rosout
Go Ahead
Now you can use your kinect 2 in your ROS system to do some robotics research. Here are some references you may need:
- Calibrate your sensor using the kinect2_calibration.
- Add the calibration files to the kinect2_bridge/data.
- Restart kinect2_bridge and view the results using rosrun kinect2_viewer kinect2_viewer kinect2 sd cloud.