In Depth Magnetometer Calibration Using Excel and Solver
( Best fit so far!)
The mathematical model
Given raw magnetometer readings X, Y , and Z,
For each reading calculate:
Let Xa= X-Xoffset, Ya=Y-Yoffset, and Za=Z-Zoffset, and
The calibrated values X1, Y1, Z1 are given by:
X1=Xa*gainXX + Ya*gainXY + Za*gainXZ,
Y1=Xa*gainYX + Ya*gainYY + Za*gainYZ,
Z1=Xa*gainZX + Ya*gainZY + Za*gainZZ.
Let R1= sqrt( X1^2+Y1^2+Z1^2), and
Error = R1-Rtarget, and Error Squared = Error^2
Take the sum of the Error Squared for all the samples = SES.
Set the X, Y, and Z offsets =0,
Set gainXX, gainYY and gainZZ =1, and the other 6 gains =0;
Use solver to minimize SES while changing the offsets, and all of the gains except gainZZ
Results
r1
stats
Mean
3117.206387
Standard Error
1.005167936
Median
3119.478578
Mode
#N/A
Standard Deviation
8.041343492
Sample Variance
64.66320515
Kurtosis
-0.864123021
Skewness
-0.291754939
Range
27.37080618
Minimum
3101.887692
Maximum
3129.258498
Sum
199501.2087
Count
64
cov
0.002579663
Magcal 4 Gauss 5 Hz 11Jan2017
error = 4129.637996
Offset
Value
Axis
xgain
ygain
zgain
xoffset
638.3171635
x
-0.005373179
0.092816827
0.084165352
yoffset
125.7515646
y
-0.004554252
-0.103490134
0.004828644
zoffset
3341.735388
z
-0.08843408
0.094803696
1
(Back to the drawing board because the X and Y gains are too small)
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
In Depth Magnetometer Calibration Using Excel and Solver
( Best fit so far!)
The mathematical model
Given raw magnetometer readings X, Y , and Z,
For each reading calculate:
Let Xa= X-Xoffset, Ya=Y-Yoffset, and Za=Z-Zoffset, and
The calibrated values X1, Y1, Z1 are given by:
X1=Xa*gainXX + Ya*gainXY + Za*gainXZ,
Y1=Xa*gainYX + Ya*gainYY + Za*gainYZ,
Z1=Xa*gainZX + Ya*gainZY + Za*gainZZ.
Let R1= sqrt( X1^2+Y1^2+Z1^2), and
Error = R1-Rtarget, and Error Squared = Error^2
Take the sum of the Error Squared for all the samples = SES.
Set the X, Y, and Z offsets =0,
Set gainXX, gainYY and gainZZ =1, and the other 6 gains =0;
Use solver to minimize SES while changing the offsets, and all of the gains except gainZZ
Results
Magcal 4 Gauss 5 Hz 11Jan2017
error = 4129.637996
(Back to the drawing board because the X and Y gains are too small)
http://diydrones.com/forum/topics/magnetometer-soft-and-hard-iron-calibration