(Found the error in the previous post, a copy and paste in Excel)
In Depth Magnetometer Calibration Using Excel and Solver
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
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.
(Found the error in the previous post, a copy and paste in Excel)
In Depth Magnetometer Calibration Using Excel and Solver
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
http://diydrones.com/forum/topics/magnetometer-soft-and-hard-iron-calibration