Monday, June 2, 2008

Little program for your wiimote (v. 0.2)

The Idea

I wrote a little program to experiment with the wiimote and the nunchuk of the Nintendo's Wii. I saw many commercials promise great things (as always), but when I tried out the wiimote I was a bit disappointed. "Can't we do any better with this kind of technology?" was the first thing I asked myself.
The answer is yes and no. As you know, the wiimote has an (infrared) camera and three accelerometers. The nunchuk also has three accelerometers. The problem with those accelerometers is that they are not very precise.

Anyway, I wanted to be able to play my favorite FPS like Call of Duty 4: Modern Warfare, Bioshock and Crysis with the wiimote and I was also wondering whether the accelerometers could be used to recognize complex gestures such as circles, rectangles, the letters of the alphabet, etc...

I know there are other programs like, for instance, GlovePie out there, but I think you should give my little program a try.

My little program does two things:
  1. it adds the support for an infinite number of infrared sources, and
  2. it supports the recording and recognition of complex gestures.
It wasn't my intention to release this program: it was just an experiment. But recently I've seen many people say that the wiimote is unsuitable for playing FPS. I disagree.

You can download the program here:
Version 0.2: (98 Kb) [see "Checking your lights"]
wiipc02.zip (on keepandshare)
wiipc02.zip (on mediafire)
Version 0.1: (98 Kb)
wiipc01.zip (on keepandshare)
wiipc01.zip (mediafire)
(Note: this program was tested only on Windows XP.)

Some videos

Simple recognition of circles and squares

High quality: (1.3 MB)
final_geom.avi (on keepandshare)
final_geom.avi (on mediafire)

Low quality:


Recognition of all the letters of the alphabet.

High quality:
(2.31 MB)
final_alpha.avi (on keepandshare)
final_alpha.avi (on mediafire)

Low quality:


Mouse Emulation

Do you have any Christmas tree lights? Cover the walls of your room with them and start playing! :-)
I assume your wiimote is already connected to your PC. You can find many guides about that. All you need to do is start my little program and press the key 'm'. My program should work even with wiimotes that keep blinking after they've been connected to the PC.
What do you do when your mouse reaches the edge of the table?
And with your wiimote?
Whenever you shake (gently!) your nunchuk, you have N ms to move your wiimote without affecting your in-game pointer. This choice might sound odd and absurd, but give it a try (well, you'll need some time to get used to it).
You can modify N by pressing '+', '-', 'd' or 't'.
These are the key bindings:

wiimotekeyboard
11
22
upv
downr
leftq
righte
-g
+4
homef

wiimotemouse
bleft
aright

nunchuckmouse
upw
downs
lefta
rightd
cspace
zclctrl

Gesture Recognition

I don't have time to write a manual, so here is some information.

Run the program and type the following:
c
lr:x
ud:z

fb:y

yyyyyy

Now move your nunchuck and
press SPACE to exit.

A few notes and guidelines:
  1. The analog stick must always be perpendicular to the ground.
  2. Do not rotate the nunchuck while you're performing a gesture.
  3. Points 1 and 2 are a consequence of my recordings, not of the algorithm per se.
  4. Perform the movements quickly and precisely.
  5. You can see the starting time, the ending time and the intensity of each recognized gesture.
  6. Since the recorded gestures may have many shapes, the name of the same gesture might appear more than once even if you performed the gesture just once.
  7. If the intensity of a gesture is very small, that gesture can be ignored (your gestures are never perfect, so, every time you move your nunchuck, you influence all the accelerometers).
  8. Gestures performed by different people may differ quite significantly. To cope with that, the same gesture should be recorded by many people (ten people should be enough). Unfortunately for you, the gestures were all recorded by me alone (it took me thirty minutes).
  9. I've almost forgotten: my program is not optimized, but, if optimized, it could handle thousands of gestures without any problem.
Run the program again and type the following:
c
geom:xz


Try to move the nunchuck in the following ways:
  1. right, up, left, down
  2. left, up, right, down
  3. Draw a circle by moving clockwise starting from its lowest point (i.e. the one closest to the ground).
  4. Do as in 3 but counterclockwise.
Don't worry if it doesn't work for you. I recorded the gestures in a hurry so the recognition is still quite strict.

To see the "shape" of the gestures, run the program and type:
g
geom:xz

l
n
circlecw


Now press '-' on the wiimote and try to draw a circle by moving clockwise.
Here are the other keys:

keyboardwiimotefunction
l
lists the gestures
n
asks for the name of the current gesture
c-clears the graph
phomepauses/resumes the recording session
AAupdates the current gesture by saving the current shape
RBsaves the changes to disk

Numpad keys:-,+,/,* = changes the tolerances (green rectangles)

Checking your lights

If you stay too far from the lights, the mouse pointer will become "unstable" and start moving by itself! Version 0.2 solves this issue. If you had this annoying problem and want to see if version 0.2 really solves it for you, do the following:
  1. Run the program (instance A)
  2. (in A) Press 'r'
  3. Run the program (instance B)
  4. (in B) Press 'm'
  5. (in A) Bring the "Graphic Test" window on top
  6. Check your lights!
That's it for now. I'm very lazy when it comes to writing documentation!