6DOF Arduino: Compass & Accelerometer
This Arduino library is a mixed bag containing a number of functions to facilitate rapid sensor
integration between a three axis compass and a three axis accelerometer. Where speed isrequired, function math is 8.8 fixed point, while non-performance functions use float or somecombination of both. The library contains detailed examples for each section. There are three main parts making up this library, for introductory purposes, these parts are:
Compass Hard Iron Offset Auto-Solver 2.
Accelerometer Yaw Pitch & Roll Calculator 3.
360° Compass Tilt Compensation
The first item, the hard iron offset solver is an independent group of functions designed tocapture a set of semi-arbitrary 3 axis magnetic data points around a sphere and then calculate thex, y & z hard iron offsets. It produces consistently repeatable results by way of outlier datarejection based on an established trust relationship with axial sensitivity. A closer look at theparts that make up this solver reveal four functions:deviantSpread()
Picks eight positions around a sphere where each combination is a sampling of positive and negative x, y, z positions. To improve solving, it prefers to pick combinations whereone of the x, y, z components is a low number.calOffsets()
This function calls the solver for 6 of the 8 position datasets and creates an inversetrust associated with the result. After which, it bubbles the two remaining datasets throughcomparing the inverse trust to reject poor solutions. The accepted results get averaged to makeup the x, y & z hard iron offsets.