i2cdevlib icon indicating copy to clipboard operation
i2cdevlib copied to clipboard

Gravity Z Component Difference

Open choolake opened this issue 14 years ago • 4 comments

In the EMBEDDED MOTIONAPPS V2.0 given by the Invensence they derive the Z component of the gravity by the following phrase that is being taken from the mlFIFO.c file

data[2] = (inv_q29_mult(quat[3], quat[3]) + inv_q29_mult(quat[0], quat[0])) - 1073741824L; and the
inv_q29_mult(long a, long b) function just multiply the arguments and divide it by 2^29

But in the code that you have implemented use a different equation like v -> z = q -> w_q -> w - q -> x_q -> x - q -> y_q -> y + q -> z_q -> z; can you please justify the reason to this change. since i'm using your code for my final year project can you please give me a quick reply!

choolake avatar Jul 20 '12 06:07 choolake

Hi choolake! I was unaware of the method InvenSense used in MotionApps to calculate the Z component of gravity. I used code that I came across as part of a different software IMU algorithm because it's what I had, and it worked. However, if the other method also works, there is no reason not to use it if you prefer. I'm not sure if one method has a performance gain over the other.

jrowberg avatar Jul 20 '12 16:07 jrowberg

Hello all,

They are actually same formula. The formula given by litterature is Jeff's : w^2-x^2-y^2+z^2. For a normalized quaternion, we have w^2+x^2+y^2+z^2 = 1. The z gravity can then be written (w^2^-x^2-y^2+z^2) -1 + (w^2+x^2+y^2+z^2) = 2w^2+2z^2 - 1, which is the formula used by Invensense (scaled by 2^30).

drastef avatar Aug 14 '12 07:08 drastef

Thanks, @drastef! That's great to know. I will mark this issue as closed and update the code, since it looks to be slightly less computationally intensive.

jrowberg avatar Aug 16 '12 19:08 jrowberg

I got your point and i am very grateful to jrowberg and drastef

choolake avatar Aug 17 '12 05:08 choolake