Can anyone tell me whether gravity sensor is as a tilt sensor to improve heading accuracy?
Asked Answered
B

1

1

X and Y axis of magnetometer can be used to calculate the heading of north when phone is level to the local ground. But when rolling or pitching the phone, we should use roll and pitch degree to eliminate the tilt error.

Now, I want to know whether the gravity sensor is used as tilt sensor to get the roll and pitch to help improve the accuracy of heading to the north?

Brainwashing answered 6/11, 2011 at 13:30 Comment(0)
G
3

Here I describe how to get the orientation of the device with respect to the horizontal plane and the magnetic North. It is just 1 line of code to get the magnetic heading from the orientation (rotation matrix).

Take the accelerometer and magnetometer readings a and m as 3 dimensional vectors. The a x m cross-product points to either East or West regardless of the orientation of the phone. Whether the cross product points to East or West depends on your sign conventions (upwards is positive or negative) and the handedness of your coordinate system (left- or right-handed).

You might want to apply at least a simple moving average to your data before computing the cross-product.

In general, it is not a good idea to use roll, pitch and yaw, so please don't. Anyway, you do not need it.

The accelerometer reading a, the cross-product a x m, and the cross-product of accelerometer reading and the cross-product a x (a x m) gives you 3 pair-wise perpendicular vectors. Make them unit vectors by multiplying them with the reciprocal of their respective length. These 3 unit vectors will given you a rotation matrix.

The rotation matrix is equivalent to the orientation of the device. In my application, the magnetic heading was atan2(R[Y][Y], R[Y][X]) where R is the rotation matrix. You might have to take different elements of the rotation matrix and perhaps change signs, depending on the conventions you follow.

If the API of the device provides the rotation matrix then it is just on line of code to get the magnetic heading.

Galan answered 6/11, 2011 at 14:58 Comment(2)
Typically I can get the roll and pitch from accelerometer when phone is static. However when the phone is in motion, the roll and pitch I get are not accurate. Your method is also inaccurate when phone is not steady. And I think your method is much like the following method(f and q are roll and pitch). XH = Xcos(f) + Ysin(q)*sin(f) - Zcos(q)*sin(f) YH = Ycos(q) + Z*sin(q) Azimuth = arcTan (YH / XH)Brainwashing
Well, you only mentioned the accelerometers. If you have gyros too, you can make it pretty accurate. The workaround is a moving average filtering if you do not have gyros, it improves a bit. I do not use roll and pitch. In my application I use the gyros and rotation matrices, it works like a charm :)Galan

© 2022 - 2024 — McMap. All rights reserved.