Site icon JetsonHacks

Building OpenNI2 for the Structure Sensor

YouTube Poster
Porting to a new platform is rarely easy. The steps are pretty straightforward, but all the niggles add up to make it easy to fiddle away the better part of a couple days for even easy projects. For a new development board, this is especially true. In my case, I haven’t been around Linux recently enough to be entirely comfortable.

With that said, here’s all the tips and tricks I did to get OpenNI2 running on the Jetson to interface with the Occipital Structure Sensor. It might not be optimal, and it may not be absolutely correct, but it appears to work. We all know, to look good is to be good. Appearances are everything.

Remember this is all pretty low level stuff, drivers for the sensor, usb interface, etc. So there’s a lot of little stuff that needs to be done.

For the sake of the video, I installed the dependencies before going on camera. You should be able to install the dependencies without any issues. Here’s the steps I took (the steps should follow the steps in the video):


# Install the dependencies for OpenNI2
$ sudo apt-get install -y g++ python libusb-1.0-0-dev freeglut3-dev doxygen graphviz
# Added 6-15-2015; Sometimes libudev is missing, add it just to be sure
$ sudo apt-get install libudev-dev
# Navigtate to where you would like to build, then:
$ git clone https://github.com/occipital/OpenNI2.git
$ cd OpenNI2
# Set the compile flags to build for the Jetson
$ gedit ThirdParty/PSCommon/BuildSystem/Platform.Arm
Change:
CFLAGS += -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mfloat-abi=softfp #-mcpu=cortex-a8
to:
CFLAGS += -march=armv7-a -mtune=cortex-a15 -mfpu=neon-vfpv4 -mfloat-abi=hard
# Save the file
# You should also modify ThirdParty/PSCommon/BuildSystem/CommonCppMakefile
# to add the lpthread library.

$ gedit ThirdParty/PSCommon/BuildSystem/CommonCppMakefile

Here's the diff:

--- OpenNI2-2.2.0.30/ThirdParty/PSCommon/BuildSystem/CommonCppMakefile.old 2014-03-28 19:09:11.572263107 -0700
+++ OpenNI2-2.2.0.30/ThirdParty/PSCommon/BuildSystem/CommonCppMakefile 2014-03-28 19:09:55.600261937 -0700
@@ -95,6 +95,9 @@
OUTPUT_NAME = $(EXE_NAME)
# We want the executables to look for the .so's locally first:
LDFLAGS += -Wl,-rpath ./
+ ifneq ("$(OSTYPE)","Darwin")
+ LDFLAGS += -lpthread
+ endif
OUTPUT_COMMAND = $(CXX) -o $(OUTPUT_FILE) $(OBJ_FILES) $(LDFLAGS)
endif
ifneq "$(SLIB_NAME)" ""

# Save the file
# Add Samples and Tools to the build chain if desired
$ gedit Makefile
# Add these two lines to the end of the file:
core_samples: $(CORE_SAMPLES)
tools: $(ALL_TOOLS)
# Save the file
# You're ready to build!
$ make
$ make core_samples # this probably isn't necessary, they should already be built
#GLUT_SUPPORTED tells the make to compile NiViewer for OpenGL
$ GLUT_SUPPORTED=1 make tools

# Build and install libfreenect
$ sudo apt-get install cmake freeglut3-dev pkg-config build-essential libxmu-dev libxi-dev libusb-1.0-0-dev -y

$ git clone git://github.com/OpenKinect/libfreenect.git
$ cd libfreenect
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install
# Build the OpenNI2 driver
$ cmake .. -DBUILD_OPENNI2_DRIVER=ON
$ make
# Copy libfreenect to the OpenNI2 driver directory
$ Repository=../../Bin/Arm-Release/OpenNI2/Drivers
$ cp -L lib/OpenNI2-FreenectDriver/libFreenectDriver* ${Repository}
# You may have to set permissions to be able to use the Sensor
$ sudo usermod -a -G video ubuntu
# Switch back to OpenNI2 directory here
# Now copy the libraries and include files to /usr
$ sudo cp -r Include /usr/include/openni2
$ sudo cp -r Bin/Arm-Release/OpenNI2 /usr/lib/
$ sudo cp Bin/Arm-Release/libOpenNI2.* /usr/lib/
# Create a package config file
# this will enable ubuntu to find the location of the drivers, libraries and include files.
$ sudo gedit /usr/lib/pkgconfig/libopenni2.pc

and fill it with this:

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include/openni2

Name: OpenNI2
Description: A general purpose driver for all OpenNI cameras.
Version: 2.2.0.0
Cflags: -I${includedir}
Libs: -L${libdir} -lOpenNI2 -L${libdir}/OpenNI2/Drivers -lDummyDevice -lOniFile -lPS1080.so

# To make sure it is correctly found, run
$ pkg-config --modversion libopenni2

# which should give the same version as defined in the file above (2.2.0.0)

# Linux has used the udev system to handle devices such as USB connected peripherals.

$ cd Packaging/Linux
$ sudo cp primesense-usb.rules /etc/udev/rules.d/557-primesense-usb.rules

At this point, you should be good to go. Switch over to the Bin/Arm-Release directory and run NiViewer to make sure it works. I’ll point out that you’ll need to plug in the sensor and have it running before NiViewer will work. It might be embarrassing to try to figure out why it’s not working when it’s not plugged in. It’s even more embarrassing if you happen to be on camera when you’re trying to demo. Don’t ask me how I know that. Also, please see the note below.

Note on using ASUS XTION PRO

If you have an ASUS XTION Pro, Walter Lucetti has step by step instructions for installation of OpenNI2 here:

http://myzharbot.robot-home.it/blog/software/configuration-nvidia-jetson-tk1/asus-xtion-pro-live-openni2-compilation-install-instructions/

Note on USB Autosuspend

There is an issue with the default setting for USB ports being turned off when not in use. The Jetson does this to save energy. If this happens when the Structure is connected, the Jetson will not recognize the Structure. A solution is to execute commands automatically on every boot-up that alter this behavior. You can put your commands into the “/etc/rc.local” boot up script. For example, run this on your board:

$ sudo gedit /etc/rc.local

Then add this near the bottom of the file but before the “exit” line:

# Disable USB auto-suspend, since it disconnects some devices such as webcams on Jetson TK1.
echo -1 > /sys/module/usbcore/parameters/autosuspend

Save the file.

You then reboot the machine so that the changes take effect.

$ sudo reboot

NOTE: If you would like to do this more selectively, you can enter this command on the command line:

sudo bash -c ‘echo -1 > /sys/module/usbcore/parameters/autosuspend’

which will cause auto suspend to be turned off until the next boot cycle.

Note that you can also modify the kernel firmware. That’s beyond the scope of this article, but you can read more about it here: Installing Grinch LinuxForTegra (L4T) on NVIDIA Jetson TK1

Exit mobile version
Skip to toolbar