I need help. I'm out of my area and digging around
The internet is full of users and developers complaining about the compass being wrong on their phone. I've done a lot of experimenting and here is what i believe:
Android takes care of magnetic compass calibration of Hard Iron effects (biases)
under the hood.
The OS is continually looking for axes-calibration motion (such as spinning on all three axes) and I believe it is automatically updating the calibration
values. It is also looking at the metal effects nearby and for this
specific lat/long, and trying to compensate for the local area magnetic
fields. From the Developer-level API, I can see the SensorEvents and read the calibrated and uncalibrated magnetic field data. From this, I verify that the calibrated data is almost always good (gives a correct heading compared to a physical compass I reference). However, on start up, the Galaxy S5 gets the heading wrong. I notice the uncalibrated values (the hard iron biases), on start up, are all 0. After doing the spinning, they go back to good values. But for the initial start up, the compass readings are wrong.
It is not clear which versions of Android, or
which phones have this problem. In fact, finding which system configurations have the
problem is quite a headache - I know I've been Googling for days. Like I said, its a nightmare to try and Google for this answer and then have to sift through pages and pages of user complaints.
Here
is what we know: this problem affects the GS5. The problem does not
affect my Moto X, and it doesn't seem to be a problem on the GS3.
I've used multiple techniques to try and do my own magnetic calibration inside the app I'm writing. Here are some links for doing magnetic calibration:
10 parameter estimation4 parameter estimationWhat I find is that nothing performs as well as the Android OS bias values [
link]. I believe this makes sense because I am statically calibrating the device, in one location, whereas I think the bias values are calibrated online - constantly recomputed based on the local field. This is great, but like it says in the link, the bias values are only good after update. I'm in trouble right after start up. I confirmed this by printing the bias values on my Samsung GS5 and seeing zeros on start up, with real values after I moved the phone around a bit.
My question is this:
Where can I go to find the hardware/software algorithm calculating these bias values? Somewhere, either in Android, or a lower level, there is some auto-calibration going on to recompute the bias values. My theory is that at very least it will be insightful to see what they do. Perhaps I can store some values to carry over between power cycles that will give me a heading at least in the ballpark instead of effectively a random heading.
Thanks for your help!