sunnuntai 20. joulukuuta 2009

Headtracking (with Wiimote) in linux

Alrighty then. Being an avid simflyer and linux user, I wanted to come up with some solution for headtracking. Naturalpoint, the creator of TrackIR, hasn't shown much interest supporting their hardware, and although Wiimote is quite nice tool for this, I wasn't too fond of porting Freetrack to linux because of the language. So I wrote neccessary parts of Freetrack in python about an year ago and got it to work, but never bothered to clean the code enough to make it available for others, just enjoyed it myself :) Anyhow, some very nice people have begun project linux-track, which supports TrackIR and Wiimote - and its future looks nice. So here's pretty much copy-paste ready stuff to try it out yourself. This is what I did on Ubuntu 9.04, pretty much based on linux-track howto, but some differences because of wiimote and wine support:

Install neccessary packages. This includes at least build-essential, svn, libusb-dev (for TrackIR hardware?), libcwiid1-dev (for wiimote) and liblo0-dev (for wine). I presume the dev-packages take the libraries as dependency, if not, also Some others might be needed, unfortunately I've been compiling software so long on this box that I can't be sure.

Get linux-track, X-Plane SDK, GlovePIE and my patch & script:

mkdir XLinuxTracker; cd XLinuxTracker
svn checkout http://linux-track.googlecode.com/svn/trunk/ linux-track-read-only
wget http://www.xsquawkbox.net/xpsdk/XPSDK200.zip
unzip XPSDK200.zip
wget http://jusu.is-a-geek.net/GlovePIE030.zip
mkdir gpie; cd gpie
unzip ../GlovePIE030.zip
cd ..
wget jusu.is-a-geek.net/ltrack-gpie-patch.tar.gz
tar zxvf ltrack-gpie-patch.tar.gz


And for TrackIR hardware this binary blob:

wget http://media.naturalpoint.com/software/external/bulk_config_data.tgz
tar zxvf bulk_config_data.tgz


Ready to compile:

cd linux-track-read-only
./configure
make
cd ..


Copy src/.linuxtrack (the dot makes it a hidden file!) to your home directory

cp linux-track-read-only/src/.linuxtrack ~

and remember to edit according to your setup! Guess if I forgot it, luckily X-Plane plugin, when run from terminal, whined about missing hardware..

TrackIR hardware needs a rule in udev to make the device accessible to normal users:

sudo echo 'SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device",SYSFS{idVendor}=="131d" , SYSFS{idProduct}=="0156", MODE="0666"' > /lib/udev/rules.d/51-TIR4.rules

For X-Plane:
X-Plane plugin linux-track-read-only/src/xlinuxtrack.xpl goes in X-Plane/Resources/plugins, and bulk_config_data.bin in upper directory goes in X-Plane directory. If using wiimote, press 1+2 on wiimote right away when starting X-Plane to make it visible to PC.

For Wine applications, eg. IL-2:

wine gpie/GlovePIE.exe -gpie/tir-osc.pie &
linux-track-read-only/src/ltlib_test


..and again, wiimote has to be bluetooth-visible (press 1+2) when running ltlib_test. GlovePIE starts running the script right away, and doesn't quit nicely unless it's receiving OSC data, and in every case throws an error message when closing. And ltlib_test doesn't shut down, just ctrl-c it. :)

Ok, that's about it, more hacks (maybe) and rants (bii suur!) later.

Edit: added link to linux-track. If anybody knows how to force blogger not to wrap lines (in blockquotes), please let me know.

Edit2: One stupid mistake in ltlib_test.c (send yaw as roll), and changed multipliers in gpie/tir-osc.pie so that things work (6dof) reasonably in Silent Wings.