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

    r1 stats
    Mean 2792.675963
    Standard Error 27.03157384
    Median 2784.500715
    Mode #N/A
    Standard Deviation 216.2525907
    Sample Variance 46765.18298
    Kurtosis -0.287108248
    Skewness -0.366464619
    Range 848.6523987
    Minimum 2329.127457
    Maximum 3177.779856
    Sum 178731.2617
    Count 64
    COV 0.077435619
    COV% 7.74%

    Magcal 4 Gauss 5 Hz 11Jan2017

    offset value axis xgain ygain zgain
    xoffset 1741.458318 x 0.863257581 -0.3926702 0.358295402
    yoffset 150.0131291 y 0.399463789 0.673246386 0.034881236
    zoffset 1234.272835 z 3.12226E-06 -3.2123E-06 1
    N x y z r x1 y1 z1 r1 error error^2
    0 3453 -1701 -1738 4223.417337 738.0793342 -1918.249765 -2423.600946 3177.779856 -385.1038923 148305.0078
    1 3381 -1643 -1723 4135.134702 699.0937349 -1850.929269 -2432.375103 3135.461665 -342.7857013 117502.037
    2 3355 -1693 -1711 4129.139741 656.6758859 -1874.382201 -2431.434845 3139.491561 -346.815598 120281.059
    3 3407 -1633 -1731 4155.803051 725.5330449 -1854.406204 -2430.71061 3142.224473 -349.5485101 122184.1609
    4 4665 -757 1189 4873.29406 2161.450477 -1758.630861 970.5809689 2950.708066 -158.0321025 24974.14542
    5 4673 -815 1151 4881.18377 2145.18752 -1800.820391 933.4242204 2952.298147 -159.6221841 25479.24165
    6 4697 -829 1165 4909.814151 2160.313252 -1819.669971 955.5349728 2981.811401 -189.135438 35772.21392
    7 4643 -819 1181 4860.346798 2117.692031 -1791.733367 952.5358334 2932.959684 -140.283721 19679.52238
    8 715 -815 4223 4359.95172 -1271.576393 -246.6416096 2587.291018 2893.408616 -100.7326523 10147.06725
    9 727 -813 4177 4317.039147 -1260.418518 -250.0070114 2545.660325 2851.586372 -58.91040867 3470.436249
    10 749 -785 4243 4379.529084 -1230.241659 -239.795069 2620.519498 2904.843999 -112.1680354 12581.66817
    11 611 -807 4179 4299.838485 -1358.159609 -200.4177964 2506.307346 2857.68111 -65.00514671 4225.669099
    12 -657 -1013 833 1466.869797 -2535.070208 158.8100096 -1301.196759 2853.929675 -61.25371127 3752.017145
    13 -711 -989 817 1466.673447 -2572.099037 196.172165 -1335.707561 2904.873778 -112.1978142 12588.34951
    14 -701 -999 844 1483.825461 -2567.461015 185.5129124 -1305.47342 2886.266092 -93.59012836 8759.112126
    15 -711 -995 795 1458.619553 -2574.495888 192.1327573 -1357.916849 2916.998842 -124.3228786 15456.17813
    16 3613 481 -1543 3958.02716 1747.831143 -512.0540098 -2095.162824 2776.116041 16.55992257 274.2310357
    17 3611 525 -1540 3960.624446 1763.681044 -481.6458381 -2091.34464 2777.818558 14.85740514 220.7424876
    18 3653 569 -1572 4017.381485 1817.514169 -468.5150427 -2106.761459 2821.578981 -28.90301747 835.3844188
    19 3631 489 -1555 3980.113943 1766.565452 -513.7360638 -2100.434457 2792.221901 0.454061814 0.206172131
    20 3597 565 2639 4496.882809 1767.587037 -449.232024 2084.034473 2769.36329 23.31267347 543.4807445
    21 3593 599 2606 4478.804081 1777.715672 -424.7708601 2050.787254 2747.076929 45.5990339 2079.271892
    22 3631 577 2604 4505.319744 1801.731251 -454.5037418 2061.635092 2775.45463 17.22133316 296.5743156
    23 3617 549 2634 4507.998004 1778.460752 -467.8573541 2085.642282 2780.596497 12.07946639 145.9135084
    24 -185 2581 2177 3381.584688 -691.9355777 2393.112869 337.2818337 2513.866162 278.8098011 77734.90521
    25 -145 2557 2207 3380.846492 -666.9923117 2361.248051 380.7765001 2483.014669 309.6612945 95890.11729
    26 -153 2599 2220 3421.492364 -657.1208526 2392.665719 392.3751488 2512.093811 280.5821522 78726.34413
    27 -157 2557 2228 3395.126213 -677.3513371 2365.960026 397.4769552 2492.901845 299.7741183 89864.52203
    28 431 -7 -767 879.8289607 -1193.990385 408.8758362 -2476.280838 2779.345116 13.33084684 177.7114774
    29 463 -83 -736 873.4723808 -1196.725294 345.1435649 -2436.466359 2736.355939 56.32002402 3171.945106
    30 429 17 -746 860.7241138 -1186.129704 425.8190224 -2455.160279 2759.716926 32.95903781 1086.298173
    31 427 -9 -638 767.7590768 -1198.24194 409.0996099 -2348.783782 2668.319976 124.3559878 15464.4117
    32 1387 3417 2378 4387.999772 999.057694 2338.668648 1130.68292 2783.151305 9.524658502 90.71911958
    33 1377 3429 2382 4396.372823 995.2186962 2350.674294 1131.518541 2792.214909 0.461054752 0.212571485
    34 1457 3355 2349 4347.030596 1034.718879 2269.440551 1124.600961 2736.006377 56.66958609 3211.441988
    35 1373 3445 2338 4383.993385 998.1569491 2363.017058 1086.643459 2785.850125 6.825838565 46.59207212
    36 3471 2883 1405 4725.839079 2584.769791 1160.833507 885.7439583 2968.688543 -176.0125795 30980.42815
    37 3345 2939 1448 4682.248392 2498.369442 1248.011612 885.5520868 2929.775649 -137.0996855 18796.32378
    38 3405 2909 1461 4710.714065 2538.181024 1204.253967 919.0033738 2955.868354 -163.1923911 26631.75652
    39 3393 2931 1484 4722.866291 2536.610208 1223.777356 938.4712162 2968.627728 -175.9517649 30959.02358
    40 3143 2419 -178 3970.099999 2116.265164 977.248095 -830.9618274 2474.689807 317.986156 101115.1954
    41 3147 2451 -205 3994.125061 2132.500951 997.2213852 -855.4124462 2504.74375 287.9322136 82904.9596
    42 3135 2411 -161 3958.1646 2106.163446 975.0034309 -817.1072405 2460.532543 332.1434204 110319.2517
    43 3103 2383 -179 3916.546821 2067.354161 968.7180363 -847.549368 2435.304456 357.3715073 127714.3942
    44 185 3641 713 3714.764461 50.89677217 2961.470767 -957.1747571 3112.729204 -320.0532409 102434.077
    45 181 3667 707 3738.916822 57.82978161 2980.545873 -963.7010265 3133.004573 -340.3286093 115823.5623
    46 143 3653 733 3728.5583 19.43358169 2986.041807 -951.8045891 3134.127521 -341.4515573 116589.166
    47 153 3623 712 3695.467765 16.08217827 2961.917781 -970.2680722 3116.831037 -324.1550734 105076.5116
    48 2099 -3223 2501 4587.867805 -1038.742081 -2411.268931 1277.177838 2919.655151 -126.9791875 16123.71405
    49 2087 -3223 2526 4596.082462 -1049.101094 -2406.556969 1297.878293 2928.586283 -135.9103193 18471.6149
    50 2079 -3203 2573 4604.538956 -1048.017732 -2389.950831 1342.709554 2934.804097 -142.1281338 20200.40643
    51 2129 -3179 2505 4573.150664 -995.2679345 -2393.426209 1293.461474 2896.9104 -104.2344367 10864.81779
    52 -109 -2125 1255 2470.33014 -2506.20747 -805.0245965 -721.6388134 2729.451055 63.2249088 3997.389092
    53 -97 -2101 1269 2456.414257 -2486.261204 -793.5787706 -702.5021189 2702.734036 89.94192774 8089.550366
    54 -173 -2103 1319 2488.433041 -2552.667552 -765.0824888 -679.802332 2750.198912 42.4770515 1804.299904
    55 -153 -2117 1301 2489.517825 -2540.994949 -782.3612844 -691.1247612 2747.070794 45.60516933 2079.831469
    56 333 -831 -375 970.6054811 -1607.746566 -107.3987654 -2148.135926 2685.306588 107.3693755 11528.18279
    57 285 -829 -326 935.2764297 -1648.383849 -87.20426041 -2116.264343 2683.905487 108.7704759 11831.01643
    58 309 -877 -348 992.8313049 -1646.839998 -128.944101 -2131.339552 2696.537937 96.13802609 9242.520061
    59 253 -877 -315 965.5894573 -1695.182319 -106.9546759 -2118.404095 2715.274997 77.40096666 5990.909641
    60 3419 -2285 710 4173.114664 475.4493671 -2298.082732 -8.153631469 2346.764331 445.9116326 198837.1841
    61 3395 -2277 684 4144.708675 457.9268143 -2283.272592 -42.47367124 2329.127457 463.5485064 214877.2178
    62 3429 -2275 693 4172.998323 488.0765277 -2295.276915 -21.22186508 2346.692392 445.9835715 198901.3461
    63 3451 -2273 697 4190.672858 507.8671346 -2302.56918 -9.269603757 2357.93125 434.7447135 189002.9659

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

About