This is a continuation of work by Merlin from sailboatintruments1 who developed the code for this. Previously a tool called Magneto was distributed however it is no longer available. The math library used mymathlib.com also no longer exists.
With the help of wayback and some other sources I have been able to recover the code and make it available here.
The test data is from Michael Wronas and is available . Also see for more information on implementation.
Build and run. You will be prompted for field magnitude and file name.
You can include relative path names to the data files. Data files should be three column comma delineated with x y z data. See example data from Michael Wronas.
For accelerometer readings measured in G it would be 1 for field magnitude.
This technique was originally developed for calibrating Magnetometers, but has been adapted for use with accelerometers.
Magnetic measurements have two types of error hard iron and soft iron distortions.
Hard iron distortions are caused by objects that generate magnetic fields, like speakers or magnetized iron. If such objects are physically attached to the same reference frame as the sensor, they can permanently bias the sensor's output.
On the other hand, soft iron distortions involve alterations in the existing magnetic field, causing it to stretch or distort based on the sensor's orientation relative to the field.
It's worth noting that, in most cases, hard iron distortions have a more substantial impact on the overall measurement error compared to soft iron distortions.
To translate this theory to accelerometer. Hard Iron becomes bias and soft iron is replaced with axis-nonorthoganality.
Calibration model is based off of the following equation:
This model works on the basis of elipsoid curve fitting. By taking a number of measurements at various angles and orientations, the elipsoid can be fit to the data. The calibration matrix is then calculated from the elipsoid parameters. By taking the inverse of this elipsoid it is possible to calibrate the accelerometer data by correcting a given measurement for the elipsoid.
This equation that is then implemented in software is as follows:
Where
Full general equation of an ellipsoid:
Using the matrix form of the quadratic surface.
Where
By defining the following matrices
The centre of the ellipsoid can by calculated as the vector
This is a 1x3 matrix with ellipsoid offsets. (Hard iron compensation)
The ellipsoids semi-axis' a, b, c are give by:
Where
- Translate the ellipsoid to the origin.
- Align the principal axis of the ellipsoid with the coordinate axis.
- Scale the pricipal axis of the ellipsoid to the unit sphere.
- Rotate back the sphere to the original orientation of the ellipsoid.
- Scale the sphere to the unit sphere. i.e. scale to magnitude of 1. Can also be used to scale to a different radius
$R$ .
For any point
Where
Step 2. The principal axis of the ellipsoid are alligned with the
Step 3. The semi-axis a, b, c are scaled to the length of the semi-axis a, transforming the ellipsoid into a sphere of radius a.
Step 4. Rotate the sphere back to the original orientation of the ellipsoid. This corresponds to applying the rotation matrix V.
Step 5. Scale the sphere to the unit sphere. i.e. scale to magnitude of 1.
The final equation is then in various forms:
Footnotes
-
This is because the rotation matrix is a square orthogonal matrix, that is $
V^{-1} = V^T
$c ↩