-
From some testing I did with an LSM303 here, I could get the same behavior of poor tilt compensation (i.e. the reported heading changing when the board is rolled or pitched) when the calibration constants were not set well, and I was able to improve it by calibrating more carefully. The
heading()function should give perfect results if given perfect data, so I would say that’s as good as it gets unless you can improve the quality of your magnetometer data (or unless there’s a bug in the code that we haven’t noticed). A tip for calibrating with our method is that you should try to point the sensor in as many directions as possible - imagine painting the inside of a sphere with it. -
Out of curiosity, I tried implementing a heading calculation using those equations and found that it gave the exact same result when given the same data (as expected). Here’s my sketch if you want to look at or try it: Heading2.ino (2.3 KB) You can see how to calculate pitch and roll in the code.
Kevin
