• If 12 factor calibration is used on both accelerometer and magnetometer data, and the Rodrigues formula is applied do the magnetic dip statistics improve?

    Code to apply 12 factor calibrations ( Using a LSM9DS1 IMU )

    //Use 12 element calibration on raw count magnetometer data
    function cal8G(S){
     var i;
     var mm=[0,0,0];
     var scale=8;
     var mres=[
         [0.970972836,0.171154738,-0.000344029],
         [-0.095223453,0.956653319,-0.000125418],
         [0.017179224,0.005190024,1],
         ];
     var moff=[1057.176483,120.7727841,549.551664];
     for(i=0;i<3;i++) S.m[i] -=moff[i];
     for(i=0;i<3;i++)
      mm[i]=S.m[0]*mres[i][0]+S.m[1]*mres[i][1]+S.m[2]*mres[i][2];
      for(i=0;i<3;i++)S.m[i]=mm[i]*scale/32768;
    }//end cal8G(S)
    //Use 12 element calibration on raw count accelerometer data
    function calA2(S){
     var i;
     var mm=[0,0,0];
     var scale=2;
     var mres=[
       [1.005708319,-0.007635345,-1.55429E-05],
       [0.001530038,1.006717582,-9.04159E-05],
       [0.017299441,0.097632586,1]
       ];
     var moff=[-126.0318135,-350.2409885,730.2274842];
    
     for(i=0;i<3;i++) S.a[i] -=moff[i];
     for(i=0;i<3;i++)
      mm[i]=S.a[0]*mres[i][0]+S.a[1]*mres[i][1]+S.a[2]*mres[i][2];
      for(i=0;i<3;i++)S.a[i]=mm[i]*scale/32768;
    }//end cal8G(S)
    ////////////////////
    function readall(W){
    if(W.magAvailable()){
      W.readMag();
      W.readAccel();
      cal8G(W);
     calA2(W);
    console.log(W.a,',',W.m);
    //console.log(W.a);
    }//endif
    }//end readall
    
    

    Data were collected and pasted into the following code that is used to determine the signs of the magnetometer axis that produce the best magnetic dip angle statistics.

    function test(){
     FF=require("Rodrigues").connect();
     var i,j,k,l;
     var d="";
      var t=[0,0,0];
      console.log("mmm,mmp,mpm,mpp,pmm,pmp,ppm,ppp");
     for(i=0;i<Adata.length;i++){
      d=" "+i;
     A=FF.Setup(Adata[i],[0,0,1]);
     Theta=FF.theta;
     Kn=FF.Kn;
     A=FF.An;
    for(j=-1;j<2;j=j+2){
     for(k=-1;k<2;k=k+2){
      for(l=-1;l<2;l=l+2){
       t[0]=Mdata[i][0]*j;
       t[1]=Mdata[i][1]*k;
       t[2]=Mdata[i][2]*l;
       B=FF.RotVector(t);
       An=FF.An;
     dip=pirate*Math.atan(B[2]/Math.sqrt(B[0]*B[0]+B[1]*B[1]));
         d=d+","+dip;
      }//nextl
     }//nextk
    }//nextj
    console.log(d);
    }//next i
    }
    

    This produces output that looks like the following:

    N mmm mmp mpm mpp pmm pmp ppm ppp
    0 66.84 -65.86 63.19 -69.97 69.97 -63.19 65.86 -66.84
    1 65.84 -67.25 63.43 -70.09 70.09 -63.43 67.25 -65.84
    2 66.60 -64.70 61.16 -71.07 71.07 -61.16 64.70 -66.60

    This output is copied into a CSV file and the CSV file is opened using Excel. Descriptive Statistics are then applied to the columns of data

    Statistic mmm mmp mpm mpp pmm pmp ppm ppp
    Mean 36.62 -58.66 22.56 -72.11 72.11 -22.56 58.66 -36.62
    Standard Error 7 4.84 8.39 0.39 0.39 8.39 4.84 7
    Median 65.64 -72.26 65.17 -72.21 72.21 -65.17 72.26 -65.64
    Mode #N/A #N/A #N/A #N/A #N/A #N/A #N/A #N/A
    Standard Deviation 58.16 40.16 69.67 3.27 3.27 69.67 40.16 58.16
    Sample Variance 3382.36 1613.19 4853.89 10.67 10.67 4853.89 1613.19 3382.36
    Kurtosis -0.42 3.95 -1.6 0.78 0.78 -1.6 3.95 -0.42
    Skewness -1.16 2.31 -0.59 0.28 -0.28 0.59 -2.31 1.16
    Range 177.14 150.05 169.77 14.85 14.85 169.77 150.05 177.14
    Minimum -88.87 -87.5 -81.07 -79.4 64.56 -88.7 -62.55 -88.27
    Maximum 88.27 62.55 88.7 -64.56 79.4 81.07 87.5 88.87
    Sum 2526.48 -4047.26 1556.98 -4975.74 4975.74 -1556.98 4047.26 -2526.48
    Count 69 69 69 69 69 69 69 69
    COV 159.00% -68.00% 309.00% -5.00% 5.00% -309.00% 68.00% -159.00%

    The mpp and pmm columns produce the smallest coffoecoent of variation (COV) values. The following code uses the +X, -Y, -Z (pmm) combination.

    function test(){
     FF=require("Rodrigues").connect();
     var i;
     for(i=0;i<Adata.length;i++){
     A=FF.Setup(Adata[i],[0,0,1]);
       Theta=FF.theta;
       Kn=FF.Kn;
     A=FF.An;
       t[0]=Mdata[i][0]*1;
       t[1]=Mdata[i][1]*-1;
       t[2]=Mdata[i][2]*-1;
      B=FF.RotVector(t);
       An=FF.An;
      heading=pirate*Math.atan2(-B[1],B[0]);
     if(heading<0)heading+=360;
     dip=pirate*Math.atan(B[2]/Math.sqrt(B[0]*B[0]+B[1]*B[1]));
    console.log(i,',',A,',',An,',',B,',',
     Theta,',',heading,',',dip);
    }//next i
    }
    

    This produces the following:

    N ax ay az mx my mz m1x m1y m1z Tilt Heading Dip
    0 0.12 0.04 0.99 0.08 0.37 0.92 -0.03 0.34 0.94 7.34 264.53 69.97
    1 0.13 0.02 0.99 0.11 0.36 0.93 -0.02 0.34 0.94 7.66 267.24 70.09
    2 0.13 0.06 0.99 0.11 0.38 0.92 -0.01 0.32 0.95 7.97 268.51 71.07
    3 0.16 0.06 0.99 0.11 0.39 0.92 -0.04 0.33 0.94 9.72 263.55 70.79
    4 0.16 0.08 0.98 -0.09 0.34 0.94 -0.24 0.26 0.94 10.39 227.72 69.28
    5 0.06 0.07 1.00 -0.10 0.32 0.94 -0.16 0.25 0.96 5.34 237.84 72.82
    6 0.08 0.05 1.00 -0.12 0.30 0.95 -0.19 0.25 0.95 5.16 232.69 71.77
    7 0.08 0.06 0.99 -0.12 0.30 0.95 -0.20 0.25 0.95 5.79 231.24 71.55
    8 0.12 -0.01 0.99 -0.17 -0.01 0.99 -0.28 0.01 0.96 6.68 181.35 73.45
    9 0.13 -0.01 0.99 -0.18 0.00 0.98 -0.31 0.01 0.95 7.25 180.95 72.20
    10 0.10 -0.02 0.99 -0.18 -0.01 0.98 -0.28 0.01 0.96 6.00 182.72 73.58
    11 0.12 -0.01 0.99 -0.19 0.00 0.98 -0.30 0.01 0.95 6.82 181.88 72.27
    12 0.09 0.05 0.99 -0.04 -0.21 0.98 -0.12 -0.26 0.96 5.94 114.97 73.10
    13 0.07 0.05 1.00 -0.04 -0.23 0.97 -0.11 -0.28 0.95 4.89 110.49 72.52
    14 0.08 0.05 1.00 -0.03 -0.23 0.97 -0.10 -0.28 0.95 5.31 110.53 72.62
    15 0.09 0.05 1.00 -0.02 -0.23 0.97 -0.11 -0.28 0.95 5.68 111.32 72.63
    16 0.08 0.09 0.99 0.08 -0.19 0.98 0.01 -0.28 0.96 7.09 88.93 73.76
    17 0.11 0.09 0.99 0.10 -0.19 0.98 -0.01 -0.27 0.96 8.00 91.34 74.09
    18 0.10 0.08 0.99 0.11 -0.20 0.97 0.01 -0.28 0.96 7.25 87.14 73.69
    19 0.13 0.08 0.99 0.10 -0.20 0.97 -0.02 -0.28 0.96 8.80 94.39 73.48
    20 0.12 0.14 0.98 0.31 -0.08 0.95 0.20 -0.21 0.96 10.39 46.51 73.30
    21 0.09 0.12 0.99 0.30 -0.09 0.95 0.21 -0.20 0.96 8.76 44.28 73.03
    22 0.09 0.12 0.99 0.30 -0.09 0.95 0.21 -0.21 0.95 8.76 45.22 72.50
    23 0.08 0.11 0.99 0.30 -0.08 0.95 0.22 -0.19 0.96 7.84 40.87 73.14
    24 -0.11 0.02 0.99 0.19 0.08 0.98 0.30 0.06 0.95 6.49 349.05 72.11
    25 -0.15 0.00 0.99 0.17 0.05 0.98 0.32 0.05 0.95 8.75 350.49 71.26
    26 -0.16 0.02 0.99 0.16 0.05 0.99 0.32 0.03 0.95 9.48 354.59 71.02
    27 -0.17 -0.03 0.99 0.15 0.03 0.99 0.31 0.06 0.95 9.79 349.45 71.54
    28 -0.03 -0.05 1.00 0.13 0.23 0.97 0.15 0.27 0.95 3.14 299.10 71.81
    29 -0.04 -0.03 1.00 0.11 0.23 0.97 0.15 0.26 0.95 2.85 299.20 72.50
    30 -0.03 -0.04 1.00 0.12 0.23 0.97 0.15 0.26 0.95 2.87 300.37 72.21
    31 -0.01 -0.05 1.00 0.12 0.22 0.97 0.13 0.27 0.96 2.70 295.80 72.84
    32 -0.15 -0.12 0.98 -0.15 0.17 0.97 -0.01 0.28 0.96 10.81 268.65 73.89
    33 -0.14 -0.13 0.98 -0.16 0.17 0.97 -0.03 0.29 0.96 10.96 264.77 72.81
    34 -0.14 -0.11 0.98 -0.17 0.16 0.97 -0.03 0.27 0.96 10.31 263.52 74.28
    35 -0.09 -0.13 0.99 -0.14 0.15 0.98 -0.05 0.27 0.96 9.17 259.69 73.83
    36 0.95 -0.10 0.31 0.90 0.32 0.28 0.04 0.41 0.91 72.21 275.70 65.49
    37 0.94 -0.10 0.34 0.89 0.33 0.31 0.04 0.42 0.91 70.14 274.89 65.04
    38 0.94 -0.10 0.32 0.88 0.33 0.33 0.01 0.43 0.90 71.15 270.85 64.56
    39 0.94 -0.11 0.33 0.88 0.32 0.34 0.00 0.43 0.90 70.81 270.42 64.75
    40 0.08 -0.04 -1.00 -0.02 0.26 -0.97 0.31 0.08 0.95 -5.33 345.27 71.59
    41 0.09 -0.06 -0.99 0.01 0.25 -0.97 0.30 0.07 0.95 -6.19 347.94 71.84
    42 0.06 -0.08 -1.00 0.02 0.26 -0.97 0.31 -0.12 0.94 -5.42 21.98 70.65
    43 0.12 -0.07 -0.99 0.04 0.24 -0.97 0.31 0.08 0.95 -8.02 345.75 71.41
    44 -0.92 -0.36 -0.18 -0.97 -0.23 -0.02 0.10 0.18 0.98 -79.40 298.09 77.90
    45 -0.92 -0.37 -0.16 -0.97 -0.23 -0.05 0.05 0.18 0.98 -80.68 286.11 79.40
    46 -0.90 -0.40 -0.18 -0.96 -0.26 -0.03 0.07 0.20 0.98 -79.86 289.55 77.59
    47 -0.90 -0.40 -0.17 -0.96 -0.28 -0.03 0.07 0.18 0.98 -80.38 291.45 78.69
    48 -0.90 -0.42 -0.15 -0.95 -0.30 0.01 0.08 0.18 0.98 -81.59 294.28 78.29
    49 -0.97 -0.07 0.21 -0.98 -0.20 -0.04 -0.24 -0.15 0.96 77.69 147.66 73.67
    50 -0.95 -0.08 0.31 -0.98 -0.21 0.00 -0.29 -0.15 0.94 71.91 152.86 70.74
    51 -0.95 -0.09 0.31 -0.98 -0.21 0.05 -0.25 -0.15 0.96 72.06 149.36 73.18
    52 -0.94 -0.08 0.33 -0.98 -0.20 0.05 -0.27 -0.15 0.95 70.50 151.66 72.02
    53 0.07 -0.06 -1.00 0.39 0.00 -0.92 0.04 0.33 0.94 -5.19 276.97 70.45
    54 0.09 -0.08 -0.99 0.39 0.00 -0.92 0.02 0.31 0.95 -6.85 274.35 71.97
    55 0.06 -0.10 -0.99 0.38 -0.01 -0.92 0.21 0.26 0.94 -6.54 309.08 70.25
    56 0.14 -0.05 -0.99 0.43 -0.01 -0.90 -0.20 0.22 0.96 -8.75 227.03 72.81
    57 0.99 -0.09 -0.15 0.98 0.09 0.17 -0.29 0.20 0.94 -81.59 215.17 69.31
    58 0.99 -0.08 -0.09 0.98 0.09 0.19 -0.26 0.19 0.95 -84.78 215.22 71.22
    59 0.99 -0.08 -0.08 0.98 0.10 0.18 -0.24 0.20 0.95 -85.65 220.13 71.89
    60 0.99 -0.10 -0.08 0.98 0.08 0.17 -0.23 0.20 0.95 -85.15 220.17 72.19
    61 -0.16 -0.98 -0.13 -0.31 -0.95 0.06 -0.13 0.21 0.97 -82.70 238.86 75.94
    62 -0.15 -0.98 -0.10 -0.32 -0.95 0.03 -0.15 0.15 0.98 -84.48 224.53 77.45
    63 -0.17 -0.98 -0.13 -0.33 -0.94 0.06 -0.13 0.21 0.97 -82.56 239.09 75.75
    64 -0.18 -0.98 -0.08 -0.33 -0.94 0.05 -0.12 0.16 0.98 -85.15 231.68 78.45
    65 -0.17 0.97 0.18 -0.57 0.81 0.17 -0.41 -0.09 0.91 79.85 167.84 65.39
    66 -0.23 0.95 0.21 -0.59 0.79 0.17 -0.38 -0.06 0.92 77.75 170.57 67.09
    67 -0.24 0.94 0.23 -0.60 0.78 0.19 -0.39 -0.08 0.92 76.95 168.65 66.85
    68 -0.22 0.94 0.27 -0.61 0.77 0.20 -0.42 -0.04 0.91 74.08 174.05 65.15
About