views:

374

answers:

2

I need a way to get euler angles for rotation in global frame of reference from a local. I am using c#, wpf 3d and a gyroscope. I have a globe on the screen that should move in the same way as the gyro. Since the gyro sends movement relative to itself I need to use quaternions to keep the state of the object and update it but I'm stuck. If i do the following:

                var qu=eulerToQ(Gyro.X,Gyro.Y,Gyro.Z);
                GlobalQu = Quaternion.Multiply(qu, GlobalQu);

IT rotates correctly on one axis. When I rotate by A in one direction and then by B in another the rotations of the object and the gyro are no longer in the same direction because the above works for absolute rotations (relative to the world).

For example:

                    var qu=eulerToQ(KeyboardValue1,KeyboardValue2,KeyboardValue3);
                    GlobalQu = qu;

This works because I am increasing the roll,pitch,yaw ie keyboard values via keyboard always on the global axis. Gyro send rotations on LOCAL axis.

Switching the order of quaternion rotation doesn't help

                    var qu=eulerToQ(Giro.X,Giro.Y,Giro.Z);
                    GlobalQu = Quaternion.Multiply(GlobalQu,qu);
A: 

This actually is the proper way. If you multiply globalQuaternion * newQuaternion you get global rotation and newQuaternion * globalQuaternion then you get local rotation. I simply had a mistake in generating my quaternion.

tomato
A: 

You say you have a gyro. Is it a physical gyro? A gyro, in and of itself, can only generate angular rate information. Is there electronics attached to it that produces angles, not angular rates? There are twelve possible Euler angle rotation sequences; each has a different mathematical conversion to quaternion. You only have a one in twelve chance that the order of angles coming from your gyro is the same as the order that your eulertoQ function. Here is a link to an euler to quaternion white paper I wrote several years ago.

http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/Euler%20to%20quat.pdf

contact me at [email protected] if you have an

noel hughes