How to calculate Heading using Gyro and magnetometer
How to calculate Heading using Gyro and magnetometer
I have raw data of Gyroscope and magnetometer. on basis of this data, i have to calculate Heading information with an accuracy of 1Deg.
I would like to know, is there any algorithm which can help me to get heading info using available information with mentioned accuracy?
Any article or any link also will be helpful.
Thanks
The question is too broad in its current form. What algorithm(s) did you try, and where exactly did you get stuck? Note that requests for off-site resources are considered off-topic here.
– njuffa
Jan 28 '16 at 20:38
Check out yaw returned by Phone's motion API
– nbsrujan
Jan 29 '16 at 9:03
1 Answer
1
I am assuming you are using phone to collect gyroscope+magnetometer
data.
gyroscope+magnetometer
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' or
yaw` component from Motion sensor API of Android/IOS device.
Gyro+Magnetometer
Accelerometer+Magnetometer
rotation-matrix' or
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
.
accelerometer
magnetometer
accelerometer
magnetometer
Accelerometer
Magnetometer
accelerometer+magnetometer
Tilt compensation algorithm
Let accelerometer
and magnetometer
give you
accelerometer
magnetometer
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.
accelerometer+magentomete
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.
sensor-fusion
Accelerometers
Magnetometer
gyroscope
There are numerous algorithms to estimate accurate heading values. Some of them are
thank you for your detailed answer. I forgot to mention about my application in my question. My application is related to aviation field. My magnetometer will be located on aircraft vertical fin. I will try this approach also
– Pratik
Jan 29 '16 at 11:26
@Pratik If magnetometer is located on aircraft fin, check out Magnetometer readings once. You have to calibrate keeping magnetometer before you use it, if sensor doesn't calibrate by itself.
– nbsrujan
Feb 1 '16 at 15:33
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy
stackoverflow isn't about searching/writing code for you, it's about fixing issues you have in your [existing] code. Show us what you have tried so far and programmers here would be able to help you, otherwise I only can suggest you to search with google (or just look at the sidebar under the Related section) and stop wasting our time doing searching for you
– ankhzet
Jan 28 '16 at 12:31