Welcome! Log In Create A New Profile

Advanced

IR & calculating yaw

Posted by Kovacs 
IR & calculating yaw
February 07, 2010 04:05PM
Is calculating yaw from the IR data as straightforward as obtaining pitch & roll (i.e. running it through some formulas) from the accelerometer data?

I want to take a shot at it, but I can't seem to find any useful data on the topic (been checking wiibrew, wiili.org (or what's left of it) and other sites, but no dice).
Re: IR & calculating yaw
February 07, 2010 09:48PM
I don't understand your question. If you are already getting pitch and roll data you are already getting yaw data too. The IR requeriment means you must be pointing to your sensor bar, if you point anywhere else the accelerometers won't be able to calculate yaw because they use gravity to measure force and it doesn't matter how much you yaw your wiimote the gravity will push it downwards with the same strength in every point, that's why yaw must be calculated using trigonometry/IR (imagine a triangle between your sensor bar and your wiimote).

Basically, you are already getting yaw values but you must be pointing to the sensor bar to see them and this won't allow you to calculate a really usable value (around 52 of 360 degrees).

I read your post again and you're probably calculating pitch and roll using gforce, you can use the orient_t sructure which has pitch, roll and yaw members (it does the math for you). And no, accelerometers aren't used to calculate yaw at all (the function that does it is in ir.c)

float calc_yaw(struct ir_t* ir) {
	float x;

	x = ir->ax - 512;
	x *= WIIMOTE_FOV_COEFFICIENT / 512.0;

	return RAD_TO_DEGREE( atanf(x) );
}

As I said I didn't understand your question and I don't know if this is useful at all but I hope it is.



Edited 1 time(s). Last edit at 02/07/2010 09:49PM by Aruskano.
Re: IR & calculating yaw
February 07, 2010 11:09PM
Yeah you're right, I should have described my problem a bit more, but you already helped me out a great deal I think.
See I'm a psychology student trying to get the wiimote to work with LabVIEW in order to run an experiment with it, but I hardly have any programming skills.
With the help of some examples I figured out how to obtain pitch and roll using (indeed) the accelerometer data. After reading online that the accelerometers can't give you yaw I was hoping I could use the IR data, but you already pointed out that it's pretty hard to calculate a really usable value (it's vital that it remains pointed at the sensor bar, right?)

Then there's the problem of trigonometry that you brought up. See with the accelerometer data I could just run it through a formula (using LabVIEW again) and it would give me pitch and roll.. now it's starting to look like it won't be that easy with the IR data.

Edit/ However, if the trig. isn't that much more complicated I only have to dig up the right formula(s) and run the IR data through it like I did with the accelerometer data, right?

However, what I've got so far is prolly enough to do some testing, I'm just attempting to get the most out of it.
Thanks for the swift reply, I really appreciate the help!



Edited 1 time(s). Last edit at 02/08/2010 03:19PM by Kovacs.
Re: IR & calculating yaw
February 09, 2010 04:34AM
Yes, you must point to a couple infrared LEDs (sensor bar) and yes you could dig up the right formula (actually I quoted it in my last post). But, as I already stated, it's pretty limited because the distance between the 2 LEDs in the sensor bar let us calculate a yaw value ranging around from -26 to 26 degrees which is around 1/7 of a full circumference.

If your experiment worth it you could get a wiimotion plus which is an extension using gyros to measure movement, you could get yaw off it. I've initialized my wiimotion plus correctly using wiiuse (are you using this library?) but I didn't do anything with it so I can't give my opinion about how accurate the wiimotion+ works. There's only 1 homebrew application using wiimotion+ at the moment. Link.
Re: IR & calculating yaw
February 09, 2010 08:19PM
Ah yes, now I see!
Now I only have to translate it a bit to make it work with LabVIEW. You see, LabVIEW is much more of a visual language, here's how you get roll and pitch using the accelerometer (XYZ) data:


The structure should be similar, so I just have to apply this formula to x (since y is prolly the vertical axe here so I guess you don't need it) I suppose.

Hmm, so I divide x by 512 and then I apply atan to it.. kinda like this?



It definitely gives me something when I run the program, but I'm not too sure if I read your code right.

About Wiimotion Plus, it's a great idea but LabView doesn't support it (yet). I got all my info from this site,
[decibel.ni.com]
The person behind it also supplied it with a lot of examples which really helped me out so far. It has made me excited about programming so I've downloaded C# Visual Express, but I've got a lot to learn before I can really code something.
Re: IR & calculating yaw
February 10, 2010 03:31AM
float calc_yaw(struct ir_t* ir) {
	float x;

	x = ir->ax - 512;
	x *= WIIMOTE_FOV_COEFFICIENT / 512.0;

	return RAD_TO_DEGREE( atanf(x) );
}
It's using the x member which is marked as bounded X value (in wiiuse) so you may have to use the "X values" value (raw X is ax in wiiuse and it's using x here, you may have to test it). You have to substract 512 off that number and then multiply it by 0.39f (WIIMOTE_FOV_COEFFICIENT value) and divide that by 512, then apply atanf() (floating's atan)over that value and you will have the yaw in radians. Convert it to degrees and you are done. Try to fit that to your programming language.
Re: IR & calculating yaw
February 10, 2010 10:24PM
I think it works! =D

I had to use the raw X values because the "regular" X values didn't really give me anything (and looking at your code again it does start with "ax - 512" so I suppose this is correct). I found the value of FOV on a couple of (wiimote) sites (Pi/4) and to convert radians to degrees I had to multiply with 180/Pi.
This is what it looks like:


I've been getting a yaw value ranging from -20 to 20 degrees (give or take) when I run it which comes pretty close to the values you mentioned earlier.

You just made my day, thanks man!
Re: IR & calculating yaw
February 17, 2010 02:46AM
Why do you need to calculate the Yaw?

Use the WPAD_Orientation function (or WPAD_Data function) which returns a orient_t structure.

This structure has pitch, roll and yaw.

For example,

orient_t *orient;

WPAD_Orientation(WPAD_CHAN_0,orient);

printf("pitch %2.3f, roll %2.3f, yaw %2.3f",(float)orient.pitch,(float)orient.roll,(float)orient.yaw);


(I am writing this without a compiler handy so there may be some small errors above...I think the WPAD_orientation call might need be "WPAD_Orientation(WPAD_CHAN_0,&orient);" instead)
Re: IR & calculating yaw
March 04, 2010 04:55PM
Well I wish I could do it like that, but I couldn't code to save my life so I have to do this with the use of LabVIEW (which makes life a lot easier with the graphical interface and everything).
(Feel free to point and laugh at me now if you like.)

So anyway, turned out that I was celebrating a little bit too early, so I'm going to go over this piece of code once more.
float calc_yaw(struct ir_t* ir) {
	float x;

	x = ir->ax - 512;
	x *= WIIMOTE_FOV_COEFFICIENT / 512.0;

	return RAD_TO_DEGREE( atanf(x) );
}

So it's

Raw X Values (ax) - 512 = X
X * ((Pi/4)/512) = X
atan(X)

And convert that answer to degrees.

This is how it looks:



Any errors?
Re: IR & calculating yaw
March 12, 2010 05:54PM
Okay, one last try.
Perhaps someone can tell me if this piece of code (meant to calculate Yaw from the IR data),

float calc_yaw(struct ir_t* ir) {
	float x;

	x = ir->ax - 512;
	x *= WIIMOTE_FOV_COEFFICIENT / 512.0;

	return RAD_TO_DEGREE( atanf(x) );
}

is indeed accurate, since I've been over this a lot of times but I can't seem to find any real errors (but the yaw data that it's giving isn't quite what it should be).

So if you have some code lying around which calculates Yaw, but looks (quite) different than this one I'd love to hear it. =)
Sorry, only registered users may post in this forum.

Click here to login