Wednesday, May 16, 2012

Programming for FTIR - A Starting Point

I recently finished a large project which involved creating a sizable touch surface. The results surprised a lot of people, and what we accomplished was no small feat.
It's no Microsoft Surface, but it cost us less than $800 to build and we ended up with a lot of spare parts. All the applications shown were written by me or my teammates in this project.

I utilized a lot of amazing open-source software to get to this end, including UbuntureacTIVision, and TUIO. When I first started researching the technology I'd be using, I had no idea what I was getting myself into. It all started with this article by Maximum PC.

All applications were written in C++ using the SDL and TUIO libraries. For SDL, I started by following the tutorials found here and expanded to fit my needs. The reacTIVision software was used to track touches from a modified Playstation Eye and send them to TUIO.

To get all these tools working on your machine may not be easy. For my build, I started with a fresh install of 32-bit Ubuntu 10.04.2. I used this version for its stability and the Linux kernel was still within version 2.6.x which has a patch available to allow the Playstation Eye to run at maximum speed. The steps to patch the Linux kernel for optimal use of the Eye are detailed on many websites, but the one I followed (several times for several fresh installs) was found in a blog post of Multitouch Dev.

Many people use touch-tracking software called CCV on their hobbyist FTIR projects. CCV (also known as tBeta) is an open-source touch-tracking program. The UI was slick, but this application did not fit my computational needs. I was running on an Intel Atom board, and CCV used up 100% of one of my hyperthreaded cores no matter what I tried to do, forcing me to search for alternatives.

This was when I found reacTIVision. reacTIVision was a more mature IR touch-tracking software that achieved very similar goals to CCV. The best part about reacTIVision was that it used much less of my CPU: somewhere around 20-30% as opposed to 100%. With this software, I was able to run my modified Playstation Eye at 60 FPS with a 640x480 resolution. Fortunately for Ubuntu users, a .deb package is available for easy installation of reacTIVision.

The SDL packages can be found in the Synaptic Package Manager. Additionally, I used SDL_image to load .png images and SDL_mixer to load sounds into my applications. One should also have the build-essential packages installed on their machine for programming.

Finally comes interpreting of the tracked data from the reacTIVision software. For this, I used libTUIO. TUIO is a wonderful library with client implementations in many modern languages, including C++, Java, C#, and Flash. You can download these libraries from the TUIO website. For my purposes, I used the C++ libraries. Once downloaded, I performed a make on these files and got some build errors. These build errors tend to occur for some of the sample applications included with the library. Luckily, the library itself was already built, and so I moved the .so, .a, and header files to appropriate locations in my filesystem.

From there, one can start making their own touch programs and use the TUIO simulator to perform testing. To actually get touches to work, you should follow the MaximumPC article's section on setting up the LED array. We packed the LEDs in about 3/4" apart on all sides of our 34"x26" screen and were able to get relatively accurate touches. Be warned that the bigger the screen, the less accurate the touches tend to be. Due to our projector size, we also had to use an angled mirror to get the image size we desired, which caused some slight distortion in our display.

In the future, I'd like to go over actually writing a C++ touch application using TUIO.