How to calculate Heading using Gyro and magnetometer

强颜欢笑 提交于 2019-12-03 16:14:58

I am assuming you are using phone to collect gyroscope+magnetometer data.

You cannot calculate Heading with Gyro+Magnetometer unless you know initial state of device. You have to try Accelerometer+Magnetometer. You can get heading values from rotation-matrix' oryaw` component from Motion sensor API of Android/IOS device.

If you want to implement of your own try tilt-compensation algorithm. All you have to do is implement tilt- compensated ecompass using accelerometer and magnetometer. You get accelerometer and magnetometer readings in device frame. Accelerometer and Magnetometer gives readings as a function of rotation of device. This rotation contains information of Roll, Pitch and Heading of device. Following is explanation and derivation of heading estimation using accelerometer+magnetometer.


Tilt compensation algorithm

Let accelerometer and magnetometer give you

readings respectively. They are in device frame, and device is rotated through

.

Where

is heading you are looking for. So rotation matrix of device will be

We have to solve for

. So step by step solving for

.

From above, equating to zero we get

Having

from above

This is basic method of obtaining Heading value from accelerometer+magentomete. Yaw/Heading value is provided by Motion sensor APIs present in mobile phones.

You have to look at few things while implementing sensor-fusion algorithms. Accelerometers doesn't always gravity direction, it gives direction of ovarall acceleration experienced by the sensor eg, devices under linear accelerations. Magnetometer readings are subjected distortion due to ferromagnetic substances in vicinity. Accuracy depends on systematic bias component in gyroscope sensor too.

There are numerous algorithms to estimate accurate heading values. Some of them are

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!