We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Approach for a direction/speed calc. (Wiiremote)
Page Index Toggle Pages: 1
Approach for a direction/speed calc. (Wiiremote) (Read 740 times)
Approach for a direction/speed calc. (Wiiremote)
Aug 28th, 2008, 11:24pm
 
Hi

Finally things cleared a bit up at work and I invested in a Wiiremote:)
Using the Darwiinremote / oscP5 libraries I got my setup running.

I been trying for some hours to master the output from the Wiiremote, it is
really sensitive, which is good, but hard to filter.

I would like to just draw an arrow/vector (or such) in my sketch, that indicates the direction/ speed of the *jerk* Im preforming. This would be my little startup sketch to master the Wiiremote.

So my first approach was to interpolate a couple of readings over a certain threshold to obtain some sort of line. This turned out not to work as the acceleration data is circular in it's behavior: It starts out being very small, then accelerates and falls back to rest, which when drawing the points resembles a circle/ellipse... Hard to interpolate.

Then I tried writing a timer function that would try to detect a movement beginning, guess the speed and plot more sensible points to my interpolation.
This yields a slightly better result but is not very flexible as the speed of the movement must be within a certain velocity and time.

I saw a few Wii posts and thought maybe someone else had a few pointers
for my Wii adventure:)

Thanks

(I had the Wiimote sent to my work, and most people thought me an idiot for just buying the remote..)

Re: Approach for a direction/speed calc. (Wiiremot
Reply #1 - Aug 29th, 2008, 1:59am
 
Hi Ricky, acceleration is quite a tricky one to use because like you say, when you move your hand from left to right, the acceleration value goes up then down, then negative, then back to zero. just like a sine wave. what you want to do is essentially take its integral - and get your velocity, and integrate that and get position. Of course the values are fake and VERY rough... but still usable. I explain a bit more here
http://www.memo.tv/wiitomidi_modes_demonstration

that was using the wii2midi app (for mac osx). the app is opensource and you can get the source from http://mike.verdone.ca/wiitomidi/
all the stuff I was talking about above is in the AdvancedMath modules, written in C... its been a while since I wrote it and can't remember how clean it is Tongue but might give you some ideas hopefully Wink
Re: Approach for a direction/speed calc. (Wiiremot
Reply #2 - Aug 29th, 2008, 7:48pm
 
Hi Memo and thanks.

I have been pondering this during the day.

First I would write some "sensing" code that can catch the high and low peaks of the sine wave produced or constantly read and process the stream from the remote.. would probably result in a too sensitive program.

The values snatched from the (to start out simple) x and y acceleration could be (x,y) -5, -5 and the high peak be 5, 5. I then shift these points to 0, 0, ending up with a line between 0,0 and 10, 10 .. this is mostly for convenience, but also so, as in this case, the acceleration will not resolve to 0, ok.  this gives me a line with a slope of y/x = 1 so in this case y = ax + b, because of the shift, can be written y = ax, where a = 1.  

Ok I then find this lines integral, which is F(x) y = ax^2,  acc = F(x1, y1) - F(x2, y2)      this is my velocity, as it is the sum of all accelerations.

Ok so far so good, but how to couple this to a direction / position?
The double intergrale, in my mind, does not give hints to the position?

I took a quick look at the Wii2midi code, but will study it some more later.

This thread was also just to throw Wiimote related physics around and maybe get a little insight into how other out there has approached the gesture part.

Thanks again Memo

Ricki



Re: Approach for a direction/speed calc. (Wiiremot
Reply #3 - Aug 30th, 2008, 6:08am
 
some discussion exists in
http://www.wiili.org/forum/wiimote-accelerometer-hacking-f36.html

arround acc,vel,pos of wiiremote
Re: Approach for a direction/speed calc. (Wiiremot
Reply #4 - Aug 31st, 2008, 12:37am
 
Thanks Classicll!

They are, apparently, also having a hard time figuring it out over there :)

I was playing around with the traer physics library, which is a brilliant toolbox for all those formulas I always have to look up when I need them.

As I was pondering how to sum and integrate all the different acceleration values from the wiimote, without breaking my CPU, I remembered the addVelocity(x, y, z) method in the traer library and thought it would be as simple as just adding the vectors to a body.

I was a bit surprised to find it work brilliantly! The idea is basically the same as integrating it over and over again. The body just moves in the direction the sum of all the accelerations dictates.

Code:

import traer.physics.*;        // great stuff get it at! http://www.cs.princeton.edu/~traer/physics/

/**
* Author: Ricki G
* Test of the Darwinremote library
* mixed with the traer physics library
* the idea is to apply the jittery Wiimote
* readings directly to a particle instead of trying
*  to measure the position by interpolation and integration
*/

WiiController wiiController;
Particle p, center;
ParticleSystem physics;

float x0, y0, z0;
float factor = 0.2;

void setup()
{
 size( 400, 400, P3D );
 background( 0 );
 frameRate( 24 );
 ellipseMode( CENTER );
 noStroke();
 wiiController = new WiiController();
 physics = new ParticleSystem( 0, 0.1 );
 p = physics.makeParticle(1,  width * 0.5, height * 0.5, 0 );
 center = physics.makeParticle(1,  width * 0.5, height * 0.5, 0 );
 physics.makeAttraction( center, p, 1000, 10 );
}

void draw()
{
 x0 = ( wiiController.acc.x - 129 ) * factor;
 y0 = ( wiiController.acc.y - 129 ) * factor;
 z0 = ( wiiController.acc.z - 156 ) * factor;
 physics.tick();
 fill( 0, 50 );
 rect( 0, 0, width, height );
 center.moveTo( width * 0.5, height * 0.5, 0 );
 fill(255);
 p.addVelocity(x0, y0, z0);
 ellipse( p.position().x(), p.position().y(), 35, 35 );
 bounce();
}


void bounce()
{
 if(p.position().x() > width || p.position().x() < 0)
 {
   float tempX = p.velocity().x() * -1;
   p.setVelocity(tempX, p.velocity().y(), p.velocity().z());
 }
 if(p.position().y() > height  || p.position().y() < 0)
 {
   float tempY = p.velocity().y() * -1;
   p.setVelocity(p.velocity().x(), tempY, p.velocity().z());
 }
}



So this is a start to something that can be tuned to get more meaningful data from the Wiimote.

By the way the WiiController Class is from sojamo.de, also great stuff:)

Ricki
Re: Approach for a direction/speed calc. (Wiiremot
Reply #5 - Aug 31st, 2008, 12:41am
 
Hey Ricky, did you have a look at the app/source code I linked to? because there is working source code there Tongue in the video you can see me moving a circle around with the wiimote (not using orientation or the IR sensors)...
Re: Approach for a direction/speed calc. (Wiiremot
Reply #6 - Aug 31st, 2008, 1:02am
 
Hi memo

Thats cool, thought the IR sensor was used in some way to obtain that precision.
I looked at the code, I was having some trouble understanding parts of it and
put it aside for some trial and error processing Smiley

I will return to it, now that I got my small succes, think it takes a paper and pencil approach to decode your program, back into math.


Apparently Im very impatient when it comes to wiiremotes:)
Re: Approach for a direction/speed calc. (Wiiremot
Reply #7 - Aug 31st, 2008, 1:07am
 
This is brilliant, I've been trying to tackle the same problem with optical flow. I tried to create a rolling average of the values which helped somewhat, but I still got those 'negative peaks' that you are describing. I was planning to use a combination of rolling average and a threshold, but these ideas look much better.
Page Index Toggle Pages: 1