Reputation: 301
I'm using the WiiM+ gyro to calculate rotation.
I integrate the rates of turn along the yaw, pitch and roll axes and store it in a vector called angleSum
So for each reading, angleSum(reading) represents the y, p and r rotations from the initial orientation.
I then use quaternions (which I'm totally unfamiliar with) to represent like this:
q = Quaternion.createfromyawPitchRoll(angleSum.yaw, angleSum.pitch, angleSum.roll*(-1))
But when I turn my wiimote 90 degrees in a direction and print out q.x, q.y and q.z for the turn, ALL readings are affected by the turn (they all show a 90 degree turn and back, although magnitude is smaller for two of them)
My question is very basic: how exactly do I use this quaternion structure to represent orientation? I need an absolute (or atleast relative) orientation in terms of yaw, pitch and roll.
Thanks!
Upvotes: 1
Views: 1904
Reputation: 23886
A quaternion is a four-dimensional construct loosely defined as an axis and a rotational component around the defined axis (usually represented as {x, y, z, w}
). Having a look at the method you've referenced, I'll assume you're supplying yaw, pitch, and roll in radians instead of degrees. That'll remove the most common implementation mistake from the table.
Assuming your implementation is correct (and it seems to be), q.x
, q.y
, and q.z
will all expectedly change with any rotation. Remember, you're defining a four-dimensional object; quaternions are not the same as Euler angles.
If you'd like to get a readout in more human-friendly Euler notation, consider converting your quaternion back into yaw, pitch, and roll. Here's a discussion for doing so in XNA.
Upvotes: 1