• 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)

    N x y z r x1 y1 z1 r1 error error^2
    0 3453 -1701 -1738 4223.417337 442.4174201 59.33861037 -3079.535366 3111.718547 4.553628065 20.73552856
    1 3381 -1643 -1723 4135.134702 441.2136312 54.80011423 -3079.90296 3111.828203 4.443971966 19.74888684
    2 3355 -1693 -1711 4129.139741 440.5198375 48.34904687 -3079.615717 3111.338671 4.933504364 24.33946531
    3 3407 -1633 -1731 4155.803051 441.7358587 58.51563949 -3079.954256 3112.020705 4.251470614 18.07500238
    4 4665 -757 1189 4873.29406 172.7593596 -94.34721157 -3099.703419 3105.947276 10.32489947 106.6035491
    5 4673 -815 1151 4881.18377 176.3410159 -95.04998877 -3099.28195 3105.749387 10.52278769 110.7290608
    6 4697 -829 1165 4909.814151 175.037742 -95.08402029 -3099.268663 3105.663444 10.60873144 112.5451828
    7 4643 -819 1181 4860.346798 173.8674059 -100.501382 -3099.331213 3105.830706 10.4414693 109.0242812
    8 715 -815 4223 4359.95172 -74.06143648 -462.3864042 -3093.645286 3128.885974 -12.6137993 159.1079327
    9 727 -813 4177 4317.039147 -70.06705543 -461.5084948 -3093.729721 3128.747844 -12.47566864 155.6423081
    10 749 -785 4243 4379.529084 -76.14943373 -459.8156956 -3093.955444 3128.863932 -12.59175646 158.5523309
    11 611 -807 4179 4299.838485 -69.64796033 -462.7892605 -3093.225351 3128.428969 -12.15679335 147.7876245
    12 -657 -1013 833 1466.869797 234.0038399 -404.2074408 -3084.870216 3120.026554 -3.754379313 14.09536403
    13 -711 -989 817 1466.673447 235.5996348 -400.3426095 -3084.622015 3119.402886 -3.130710964 9.801351141
    14 -701 -999 844 1483.825461 233.2037254 -402.438937 -3084.662639 3119.532765 -3.260589446 10.63144353
    15 -711 -995 795 1458.619553 237.5725101 -399.3862665 -3084.539666 3119.348496 -3.076321134 9.46375172
    16 3613 481 -1543 3958.02716 414.3756879 216.5243802 -3092.44633 3127.589219 -11.31704349 128.0754734
    17 3611 525 -1540 3960.624446 413.9207449 220.5440825 -3092.636235 3127.997596 -11.72542068 137.48549
    18 3653 569 -1572 4017.381485 416.3245748 233.3204843 -3092.651637 3129.258498 -12.98632299 168.6445848
    19 3631 489 -1555 3980.113943 415.3037456 220.6027051 -3092.421607 3127.97285 -11.70067486 136.9057922
    20 3597 565 2639 4496.882809 44.24777705 -157.3892385 -3107.992798 3112.289908 3.982267156 15.8584517
    21 3593 599 2606 4478.804081 47.03274985 -152.5322222 -3108.072578 3112.168586 4.103589344 16.8394455
    22 3631 577 2604 4505.319744 47.10563075 -151.8534292 -3108.039993 3112.103951 4.16822427 17.37409356
    23 3617 549 2634 4507.998004 44.6553519 -157.3030955 -3107.952379 3112.251011 4.021164599 16.16976474
    24 -185 2581 2177 3381.584688 96.24431343 -28.19245814 -3100.266032 3101.887692 14.38448319 206.9133566
    25 -145 2557 2207 3380.846492 93.4856659 -33.5947497 -3100.503284 3102.094259 14.1779165 201.0133163
    26 -153 2599 2220 3421.492364 92.1877297 -27.18843576 -3100.510806 3102.000169 14.27200652 203.6901701
    27 -157 2557 2228 3395.126213 91.69302836 -34.41427218 -3100.459497 3102.005972 14.26620361 203.5245653
    28 431 -7 -767 879.8289607 365.0707723 -200.9031402 -3091.302457 3119.26107 -2.988894959 8.933493078
    29 463 -83 -736 873.4723808 362.5034972 -211.7680404 -3091.2913 3119.669276 -3.397100785 11.54029375
    30 429 17 -746 860.7241138 363.1151009 -202.6600393 -3091.582907 3119.424392 -3.152216975 9.936471856
    31 427 -9 -638 767.7590768 353.6933771 -225.0636403 -3092.363668 3120.651487 -4.379311514 19.17836934
    32 1387 3417 2378 4387.999772 66.21507103 124.0127614 -3108.518418 3111.695737 4.576438419 20.94378861
    33 1377 3429 2382 4396.372823 65.86041548 125.5063989 -3108.495982 3111.725682 4.546493018 20.67059876
    34 1457 3355 2349 4347.030596 68.68590046 117.3753027 -3108.68621 3111.659471 4.612703873 21.27703702
    35 1373 3445 2338 4383.993385 69.7001397 130.3714175 -3108.419309 3111.932746 4.339428815 18.83064244
    36 3471 2883 1405 4725.839079 143.4956967 207.1728909 -3111.499374 3121.688642 -5.416466456 29.33810886
    37 3345 2939 1448 4682.248392 140.1150137 203.7879992 -3111.471431 3121.284388 -5.012212653 25.12227568
    38 3405 2909 1461 4710.714065 138.7796075 202.3567737 -3111.575237 3121.235092 -4.962916449 24.63053968
    39 3393 2931 1484 4722.866291 136.7099082 203.1705467 -3111.650454 3121.271603 -4.999427663 24.99427696
    40 3143 2419 -178 3970.099999 287.3624218 256.2839073 -3104.515596 3128.302365 -12.0301897 144.7254642
    41 3147 2451 -205 3994.125061 289.5829131 264.325944 -3104.45156 3129.112647 -12.84047192 164.877719
    42 3135 2411 -161 3958.1646 285.9384618 252.6505205 -3104.566376 3127.926705 -11.65453029 135.8280762
    43 3103 2383 -179 3916.546821 287.8297361 247.9689525 -3104.391036 3127.55148 -11.27930518 127.2227254
    44 185 3641 713 3714.764461 218.8962238 253.2896075 -3099.22339 3117.251482 -0.979306912 0.959042028
    45 181 3667 707 3738.916822 219.3299105 258.6135189 -3099.178072 3117.674018 -1.401843218 1.965164408
    46 143 3653 733 3728.5583 217.2985647 253.6413137 -3099.071136 3117.016922 -0.744746647 0.554647569
    47 153 3623 712 3695.467765 219.2385762 249.8929967 -3099.05838 3116.837324 -0.565148844 0.319393216
    48 2099 -3223 2501 4587.867805 81.75220912 -486.072025 -3081.66385 3120.833466 -4.561291068 20.80537621
    49 2087 -3223 2526 4596.082462 79.60583526 -487.8804985 -3081.666425 3121.062707 -4.790532247 22.94919921
    50 2079 -3203 2573 4604.538956 75.40133387 -490.0864914 -3081.874321 3121.509164 -5.236989049 27.4260543
    51 2129 -3179 2505 4573.150664 81.03689034 -483.7972845 -3082.113572 3120.905455 -4.633279728 21.46728104
    52 -109 -2125 1255 2470.33014 198.8044841 -455.9608393 -3079.70644 3119.617808 -3.34563262 11.19325763
    53 -97 -2101 1269 2456.414257 197.3926267 -456.5013745 -3080.007177 3119.904096 -3.631920504 13.19084655
    54 -173 -2103 1319 2488.433041 193.3883928 -458.8260158 -3079.648536 3119.640282 -3.368107032 11.34414498
    55 -153 -2117 1301 2489.517825 194.9365022 -458.1597874 -3079.610165 3119.60084 -3.328664726 11.08000886
    56 333 -831 -375 970.6054811 334.6838879 -309.346388 -3088.258196 3121.705813 -5.433637378 29.52441515
    57 285 -829 -326 935.2764297 330.5994221 -317.5810956 -3088.389151 3122.226975 -5.954799411 35.45963602
    58 309 -877 -348 992.8313049 332.6346197 -314.3031054 -3087.92768 3121.654944 -5.382768361 28.97419523
    59 253 -877 -315 965.5894573 330.017193 -320.3009077 -3087.899191 3121.958589 -5.686413856 32.33530255
    60 3419 -2285 710 4173.114664 228.7731624 -252.9791429 -3087.385737 3106.169071 10.10310436 102.0727176
    61 3395 -2277 684 4144.708675 231.1649708 -252.2388575 -3087.31939 3106.220002 10.05217284 101.0461788
    62 3429 -2275 693 4172.998323 230.1772675 -250.3026719 -3087.413005 3106.083074 10.18910087 103.8177765
    63 3451 -2273 697 4190.672858 229.6962127 -248.8553876 -3087.472054 3105.989865 10.28231054 105.72591

    http://diydrones.com/forum/topics/magnet­ometer-soft-and-hard-iron-calibration

About