You can simply integrate the angular speed to get the angular position (like Euler angles), convert the Euler angles to Quaternion, and then multiply the Quaternion to copy the orientation.
Suppose your input is given by the three-dimensional angular velocity vector: omega = (alpha, beta, gamma), given in degrees per second. To get Euler angles, E, in degrees, multiply omega by the change in time we can call dt. This leads to:
Vector3D omega = new Vector3D(alpha, beta, gamma); Vector3D E = omega * dt;
You can get dt by subtracting the current time at the time of your previous update. After obtaining the three-dimensional Euler angles from the gyroscope data, convert it to Quaternion (w, x, y, z) through this equation (from Wikipedia ):
float w = cos(Ex/2) * cos(Ey/2) * cos(Ez/2) + sin(Ex/2) * sin(Ey/2) * sin(Ez/2); float x = sin(Ex/2) * cos(Ey/2) * cos(Ez/2) - cos(Ex/2) * sin(Ey/2) * sin(Ez/2); float y = cos(Ex/2) * sin(Ey/2) * cos(Ez/2) + sin(Ex/2) * cos(Ey/2) * sin(Ez/2); float z = cos(Ex/2) * cos(Ey/2) * sin(Ez/2) - sin(Ex/2) * sin(Ey/2) * cos(Ez/2); Quaternion q = new Quaternion(w, x, y, z);
Just copy the two code snippets above into your Q.update (), then return Quaternion. If you want to know how the equation works, just check out the Wiki link and read it.
Enrico tiongson
source share