Introduction

Since Android is not really the best friend of the structure sensor and we want to use ROS for further development we are now trying to use the structure sensor on a Raspberry Pi 3. This is still a very portable solution but gives us more freedom with the development tools we can use.

Prerequisites

  • Raspberry Pi 3
  • 32 GB micro SD card
  • Raspberry Pi Image with ROS from (http://www.german-robot.com/2016/05/26/raspberry-pi-sd-card-image/)

Install the required packages with

sudo apt-get install libc6-dev
sudo apt-get install g++-multilib
sudo apt-get install libusb-1.0-0-dev
sudo apt-get install libudev-dev
sudo apt-get install freeglut3-dev
sudo apt-get install doxygen
sudo apt-get install default-jdk

Unpack image to sdcard

I am assuming that you are working on linux and that the sdcard is at /dev/mmcblk0

unzip -p ubuntu-mate-16.04-armhf-ROS-Kinetic-raspberry-pi.img.zip > /dev/mmcblk0 

Beware: This will take a very long time.

If you try to mount the filesystem and you get an error it is most likely because your sdcard was a few blocks too small. Then run

sudo e2fsck -f /dev/mmcblk0p2 

If it asks to abort press ‘N’ and then run

sudo resize2fs /dev/mmcblk0p2 correct_size 

where correct_size is the actual number of blocks in your partition.

OpenNI2 Installation

Get the OpenNI2 from Occipital’s github repo

git clone https://github.com/occipital/openni2 

Edit the file OpenNI2/ThirdParty/PSCommon/BuildSystem/Platform.Arm

change the first line that starts with CFLAGS to

CFLAGS += -march=armv7-a -mtune=cortex-a53 -mfpu=neon-fp-armv8 

and comment or delete the line

#DEFINES += XN_NEON 

After this is finished run make inside the OpenNI2 directory and it should compile without errors

The last thing you need to do is to install a udev rule to give everyone write permissions to the sensor device (otherwise you will onle be able to access the sensor as root, if you have security concerns then you probably also know how to limit the permissions to a certain group)

sudo su
echo '# Make primesense device mount with writing permissions (default is read only for unknown devices)' > /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="0200", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="0300", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="0401", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="0500", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="0600", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="0601", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="0609", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="1250", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="1260", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="1270", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="1280", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="1290", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules
echo 'SUBSYSTEM=="usb", ATTR{idProduct}=="f9db", ATTR{idVendor}=="1d27", MODE:="0666", OWNER:="root", GROUP:="video"' >> /etc/udev/rules.d/557-primesense-usb.rules

Then either reload the rules or reboot you Raspberry Pi.

Testing

If your structure sensor is connected go to the directory Bin/Arm-Release and run

export LD_LIBRARY_PATH=$(pwd):$LD_LIBRARY_PATH
./SimpleRead

It should continuously print a list of numbers which is the depth value of the center pixel.