ICM20948 Calibration, Yaw stability and tilt compensation

Hi all,

I am working with ICM20948 IMU,

So I started to learn all the basic knowledge of IMU,

using this repo for fusion
jremington/ICM_20948-AHRS

I studied this for calibration

Done all steps as far as I understood,
As I am new to IMU I tried my best to understand and implement everything.

I am attaching my calib data
acc_cal.txt - Accelerometer calib data
acc_out.txt - Accelerometer corrected data
mag_cal.txt - Magnitometer calib data
mag_out.txt - Magnitometer corrected data
dataOut.txt - Dataut from Arduino
magneto1_4.c - Used magneto for this calibration by @jremington

I cannot upload files @jremington as I am new here.
I can send it personally.

Now with this calib data
Accelerometer

PS C:\Users\Lenovo\Documents\Arduino\libraries\ICM_20948-AHRS\New_Calib> .\magneto.exe

Magneto 1.4 2/10/2021
Input .csv file? acc.csv
  0  -1432    856  17536
  1  -1296    952  17328
  2  -1400    824  17408
  3  -1424    792  17272
  4  -1336    672  17272
  5  -1488    720  17448
  6  -1280    512  17360
  7  -1400    664  17288
  8  -1248    784  17224
  9   2560   -976  20056
 10  -1520    880  17344
 11  -1072     88  18216
 12   4544   3736  15368
 13  -3640   3920  16744
 14    216   4240  15152
 15  -1552   2976  16760
 16  -1128   2760  14312
 17   -680   4488  20160
 18  11440   4176   8224
 19    112   2584  17112
 20  -1680   5392  17848
 21  -4408   7640  12672
 22   3016    280  17352
 23   1216  -1800  21088
 24    -48   4824  14976
 25  -2840   4104  15464
 26  -1432   5136  18600
 27  -2144    360  15744
 28  -2168  -3736  23656
 29   1392  -9056  14856
 30   5184  -6440  -6512
 31  -1096  -4968 -14272
 32  -7888  -1480 -14984
 33  -9512   -864 -14568
 34  -6000   -520 -17776
 35  -3352  -5776 -17992
 36   5736  -6600 -19904
 37  -4008   2056  31216
 38  -6104  18960  10952
 39   1440  17360 -12648
 40  -3336   8840  -9760
 41   3520   6360 -11432
 42    816  13744 -11496
 43   1088  25992   2240
 44   1808   5880  10992
 45   1752  -1720  19320
 46   1472   2360  14872
 47   1736    864  19744
 48    128  -1024  25600
 49    592  -3800  12384
 50  -1312  -1536 -10296
 51   2344  -4504 -13600
 52   1104  -3192 -19480
 53   2968  -3040 -23288
 54     72   -864  14192
 55  -8512   7672  19048
 56   4488   6592  15512
 57  -1152   7736  15376
 58  -7848   2240  24136
 59 -13368  -3464  17264
 60 -14968  -5656 -29728
 61  -8480  -6976 -21584
 62  -9824  -4488 -18208
 63   5752  -2712   9376
 64  22344  10112  31784
 65  -1608  -1376  10720
 66    944  -5784  20648
 67  -1368  -5456  17328
 68  -1080  -6520  15640
 69   8984  -8944    200
 70   3832  -1520 -13416
 71  20288   9792 -19400
 72  13392  15208 -16656
 73    800    424   -776
 74 -10592   4840  21112
 75  -8712  12976  30360
 76  -1288  11480  17424
 77   2568  12504 -17160
 78   8944  25248 -27320
 79   6712  21344 -14896
 80  -9400   9680  18464
 81  -2984   9920  19504
 82 -11568  15896  25448
 83  -3968  12280  10480
 84    240  15504 -27232
 85   5144  22448 -18176
 86  -7904  19040 -24384
 87   -664   7808  -7152
 88   9800   8120  20312
 89   8672  12592  31920
 90 -17272   9616  24416
 91   -552   4112  -9816
 92   -336   9416  -5376
 93  -5752  20896 -28544
 94 -17688  10480  -9832
 95 -12984   8712  17256
 96  -4600   9192  24024
 97 -11984  18744  26640
 98   9016   3704 -23064
 99   9728  11960 -25416
100  -6416  29128 -26064
101  -9296    440    232
102   2360   9768  14136
103 -11312  11288  19264
104 -17136   7224  14728
105  10824  12144  -4216
106   6960  21008 -23496
107 -12384  29040 -15848
108 -22368   3000 -11904
109   4232  13472  15752
110 -15256  10320  23200
111  -4376   5192  18800
112  11816  22960 -19176
113 -20848  25760 -10792
114  -2984   6712 -16280
115  -4104  10000   1648
116 -32768   3992   1840
117 -21808   9800   1056
118   5896  30544 -13840
119  -6512  15888 -32768
120  -3648  14728  -6480
121  -5760   9256  18176
122 -24480   2600  23488
123  -2584   1344  17320
124  19776    896  14224
125  12328  15384  32767
126  18472  13448  16504
127  16688   2560  24968
128 -14824  -4072  11616
129 -11976    -24  -3152
130   3592  25120   5040
131  16584  24576  -5408
132   2952   8432  11720
133  -3368  19336  19280
134   6176   6512  32608
135   6000   3432  13280
136  13728  21464 -15336
137  12560  14536 -29016
138   1848  32767  -7776
139 -11984  13848  -4712
140 -17712  11992  26856
141 -15592  16912  29856
142   7712  12152  -6544
143   7696  18800 -19912
144  -1632  23544 -29968
145   -256  15928  -7008
146 -23520  15784  32560
147 -25720  19144  23136
148      8   6608   -368
149   6848   6744    456
150  18136  22224   3032
151  13424  17232   2088
152   2168  20728  11176
153  -1424   1720   1456
154   1896   5512  17928
155  -3960   3112  12104
156    -40   1208   -320
157  -3072   7904  21128
158  17656  10048  29288
159    344   9240  -2200
160  11408   4496 -29272
161  11072   5048 -22392
162  15208   9176 -10168
163   1480   9992  -7776
164  -6592  27704  26000
165   8400  31256  10064
166  16072  15832  16128
167  -2232  27408 -23592
168  18088  14336 -23920
169   9608   9360 -30776
170   8352  19184  20200
171  24928  24880   9968
172  18640  22208  10536
173   7320  10920 -32768
174  10528  -2288 -15648
175   4448 -13944    520
176  18504 -10680  -7112
177  13968  -6248 -10592
178  21344  -2640 -12512
179    800  -2080 -12416
180  -4160  -7216  -9784
181  -5392  -5608 -14912
182    552  -7320 -18184
183   1272  -1888 -17032
184  -1616  -2512 -14856
185  -7040  -2248 -12800
186 -13352  -2432  -8752
187 -18696   -752  -4232
188 -12856  -3288   5608
189 -11872  -2696   3624
190  -1768     72  18528
191   5336   2296  19576
192   3344   2416  13184
193  -5096   4144  16744
194 -10784   5592  16280
195 -15744   7168   7096
196 -13960   5304 -18496
197  -4456   2296 -11296
198   8504    496 -11696
199   9352   4152 -13152
200  11000   3776 -14120
201   5808   4192  -8824
202  10552   2824  -5648
203  14408  11640   7488
204   9000   9440   8528
205   6536   7800  12952
206   9760   8112   7936
207   8880   3048 -12080
208   4368   2856  -6936
209   3672  -1896 -11184
210  -5888  -2248 -20008
211 -14464  -4944 -10928
212  -4792  -5136  -1216
213   4360  -7424   7192
214   7488  10056  15144
215   5376  15744  12680
216   6120  16976    968
217   7136  14432  -8096
218   6888   6560 -10440
219   3920  10808 -12512
220  10848  16088   1336
221   6512  15440  31328
222   7168   2736  15512
223  -9232 -10504  -1344
224  -5328  -5576 -13472
225   -728   2472 -17312
226  -2888    952 -15040
227  -1160   -968 -13184
228  -1592   -544 -12528
229  -8832  -1328 -14184
230  -7672  -5920   1560
231  -1096  -2920  18848
232  -2560   2792  13944
233  -1760   8416  20512
234   3808   5640  13832
235   4368   6768  13336
236  -1800   -720  13600
237   4168  11728  16376
238    968  -1744  26672
239 -10264  -1520  13696
240  -1120   3808  16832
241  18464   6040  10264
242   5104   3888  22144
243  16512    400   1768
244  16200   -112   2072
245  17384   -744   2968
246  17040    768  -3496
247  23360  -2552    -96
248  32767  23904  -1544
249   5840   7120  19072
250  -1192   7880  28744
251    632   1528  17432
252  -2608   5184  19136
253   -312   1928  17376
254  -1848   1864  19144
255  -2848   -928  19144
256   2080  -4080  18096
257  -1912   -696  19536
258  -9432  -2264  25904
259  -8680  10632  26128
260   8112   2968  12648
261  15536  -2264   5976
262  15832     64   5304
263  15952   -904    768
264  16400   -144    944
265  16336   -200   2832
266  16584   -256    552
267  16552   -168    984
268  16240   -752   1680
269  16792   -320   1656
270  16640   -432   1264
271  16408   -208   2464
272  16992    328    744
273  16120   -992   1328
274  15696   -968   1344
275  10672   2216  13096
276   1920    728  19688
277  -1680    720  19584
278   -216   1064  17472
279  -9104   4176  16528
280  15880  32767    816
281 -14848  -1024  -1112
282 -15328    624  -3080
283 -16128    784  -1160
284 -15672   1080  -3560
285 -15840    872  -2480
286 -16096    616  -2344
287 -15696    560  -3160
288 -15752   1000  -2680
289 -15680    840  -2400
290 -16032    736  -2304
291 -15880    648  -2792
292 -15832    832  -2824
293 -22040  10800   7472
294 -32768  15712    288
295    536 -11728   8640
296  -7152 -10696  17480
297   -904  14080  13552
298   6960  20952  32767
299   1576  13112   5736

Average magnitude (default Hm) and sigma of 300 vectors = 20760.5, 7778.8

Reject outliers? (0 or d, reject if > d*sigma from mean) 2
Rejection level selected:  2.0

Rejecting measurements if abs(vector_length-average)/(std. dev.) >   2.0
reject #64,  22344.0  10112.0  31784.0
reject #73,    800.0    424.0   -776.0
reject #78,   8944.0  25248.0 -27320.0
reject #100,  -6416.0  29128.0 -26064.0
reject #119,  -6512.0  15888.0 -32768.0
reject #125,  12328.0  15384.0  32767.0
reject #141, -15592.0  16912.0  29856.0
reject #144,  -1632.0  23544.0 -29968.0
reject #146, -23520.0  15784.0  32560.0
reject #147, -25720.0  19144.0  23136.0
reject #153,  -1424.0   1720.0   1456.0
reject #156,    -40.0   1208.0   -320.0
reject #164,  -6592.0  27704.0  26000.0
reject #171,  24928.0  24880.0   9968.0
reject #248,  32767.0  23904.0  -1544.0
reject #280,  15880.0  32767.0    816.0
reject #294, -32768.0  15712.0    288.0
reject #298,   6960.0  20952.0  32767.0

Number of measurements to be rejected: 18, accepted: 282

282 measurements processed, expected 282

Expected norm of local field vector Hm? (Enter 0 for default  20760.5) 0

Set Hm =  20760.5

Combined bias vector B:
 -614.88  9543.73  -810.14

Correction matrix Ainv, using Hm= 20760.5:
  1.07207   0.00232   0.02329
  0.00232   1.15398   0.01192
  0.02329   0.01192   0.87100

Where Hcalc = Ainv*(H-B)

Code initialization statements...

 float B[3]
 { -614.88, 9543.73, -810.14};

 float Ainv[3][3]
  {{  1.07207,  0.00232,  0.02329},
  {  0.00232,  1.15398,  0.01192},
  {  0.02329,  0.01192,  0.87100}};
 output filename for corrected values (csv) acc_out.txt

RMS corrected vector length 20760.505048

RMS residual -0.000000
PS C:\Users\Lenovo\Documents\Arduino\libraries\ICM_20948-AHRS\New_Calib>

Magnetic calib data

PS C:\Users\Lenovo\Documents\Arduino\libraries\ICM_20948-AHRS\New_Calib> .\magneto.exe

Magneto 1.4 2/10/2021
Input .csv file? mag.csv
  0    220     72    147
  1    231     74    131
  2    226     81    141
  3    217     77    140
  4    219     74    138
  5    224     74    134
  6    221     74    131
  7    221     76    143
  8    238     66    143
  9    225     67    135
 10    214     99    150
 11    178    169    186
 12    105    252    184
 13     -9    319    147
 14    -98    335    150
 15   -104    324    163
 16     -2    319    171
 17    107    257    153
 18    161    106    257
 19    133    -27    275
 20     82   -113    311
 21     12   -173    313
 22     46   -158    299
 23    142    -47    287
 24    163    174    238
 25     59    298    184
 26    -30    338    165
 27    -33    327    190
 28     -4    314    237
 29      7    135    399
 30    -72   -183    313
 31    -33   -261    118
 32     41   -226      0
 33     31   -211    -26
 34      0   -226    -26
 35    -23   -265    108
 36     29   -148    339
 37    117    260    252
 38      8    308    -34
 39    -36     93   -159
 40    -25    -71   -146
 41    -18   -127    -93
 42    -16    -35   -154
 43     33    216   -102
 44     18    335    191
 45      9    294    289
 46     18    308    252
 47     36    306    251
 48    117    250    226
 49    202     66    219
 50    256    -60    104
 51    192    -61    -58
 52    182   -109    -29
 53    192   -152     67
 54    198    -12    223
 55    165    187    184
 56    182    179     74
 57    175    205    122
 58    194    164    138
 59    208     98    125
 60    262     13    127
 61     69   -217    205
 62    -89   -241    213
 63   -173     89    385
 64     90    199    305
 65    163    114    257
 66    173     69    257
 67    164     55    263
 68    142      7    287
 69    104   -155    249
 70     -7   -238      9
 71   -128   -130    -99
 72   -129   -230     41
 73    118   -148    275
 74    124    215    238
 75     77    276    213
 76    170     74    264
 77    110   -202      8
 78    -14    -10   -166
 79   -119   -250    134
 80     75    153    377
 81     31    301    197
 82    153    202    141
 83    165    -96    207
 84     99   -123    -97
 85     39      1   -157
 86    -25   -162    -79
 87   -150   -171    287
 88    -62    221    363
 89    139    257    184
 90    202     66    150
 91    115   -192    -15
 92     55    -65   -175
 93     88    -76   -117
 94   -111   -246    133
 95    -70    161    410
 96    159    244    133
 97    210     -7     80
 98     43   -183    -83
 99     38    -50   -178
100     78   -111    -98
101   -128   -231    194
102    -83    157    395
103    161    222    119
104    169    -37      4
105    -83   -215    -51
106    -23    -44   -176
107     64    -79   -127
108    -21   -264    166
109    -37    142    409
110    139    215    198
111    185    -89     65
112   -129   -111   -167
113     31    -35   -159
114   -217   -171     30
115    -78    -41    388
116    122    257    143
117    173    -23    -20
118   -174   -223     76
119   -110    -38   -155
120   -199   -222    131
121    -83     91    419
122    140    201    159
123    107   -169     10
124   -185   -232    131
125   -129   -104    347
126     24   -171    270
127    -21      2    399
128   -171    -55    413
129     82   -236    123
130   -316    -31     53
131   -336     88     33
132    -61   -272    115
133     96     42    323
134    -78    270    264
135    -18     44    421
136    -53   -211    -52
137    -42    106   -181
138    -78   -192    -55
139    -13    -86    376
140     59    295    181
141    187    139    146
142     69   -205    -10
143     52     21   -193
144     -9   -110   -125
145    -60   -183    301
146     69    275    214
147    199    122    105
148     70   -228    104
149   -268   -145    163
150   -325     -6     65
151   -334     83    192
152   -286      8    290
153   -194    -61    366
154   -279     18    336
155   -231     31    376
156   -175    -59    388
157   -201      0    377
158   -171   -221    175
159    -31    -35   -171
160   -210    216    -26
161   -296    192    131
162   -296    109     62
163   -129   -235    174
164    -83     36    431
165   -185     -3    366
166     41   -238    178
167    -13    217   -148
168   -276    226    130
169   -237   -155    118
170   -134    -71    414
171   -257     51    328
172      6   -247    165
173   -112    172   -160
174   -216    189    -41
175   -271     -2    -47
176   -331    100      4
177   -278    238     66
178   -227    281    121
179   -225    223    -40
180   -111    186   -140
181   -167    193   -106
182   -226    227    -32
183   -230    259      4
184   -156    267    -34
185    -88    270    -81
186     -1    272    -84
187     71    275    -39
188    153    237     22
189    179    221     92
190    131    232    233
191     65    254    280
192     79    254    261
193    147    251    173
194    146    247     93
195    129    242     -5
196    -64    240   -105
197   -176    233    -59
198   -272    247    110
199   -261    269    185
200   -251    249    178
201   -251    269    171
202   -184    264    258
203     12    246    313
204    129    240    233
205    102    252    248
206    -66    315    255
207   -111    357    187
208   -162    357     85
209   -131    328    -41
210     -6    340    -27
211    100    255    -74
212    187    -56    -29
213     83   -207    214
214      2    -95    358
215    -42     33    419
216    -98    187    371
217   -131    280    271
218   -148    320    174
219   -157    319    156
220   -139    295    267
221    -70     -7    403
222     26   -213    237
223     77   -128    -95
224    -15    182   -141
225   -117    300      5
226   -108    296     19
227   -113    286      9
228   -116    294      9
229    -36    261    -68
230    219     61    -10
231    213    -40    121
232    214     64    165
233    152    178    201
234    153    144    195
235    170    129    217
236    175    142    176
237    201    108    156
238    196    103    154
239    217     90    125
240    211    101    119
241    115     86    293
242     23     71    369
243    -94     52    372
244   -101     37    368
245   -131     46    357
246   -134     44    352
247   -110     51    369
248     -7     70    368
249    124     89    286
250    217     95    159
251    215     72    154
252    222     80    147
253    211     91    136
254    213     83    159
255    215     90    144
256    219     96    141
257    211     79    141
258    225     80    149
259    148     94    257
260     79     88    334
261     -2     77    361
262    -81     49    366
263   -117     44    352
264   -117     41    345
265   -125     37    356
266   -129     49    350
267   -122     41    350
268   -130     30    339
269   -129     44    357
270   -134     36    350
271   -127     41    347
272   -130     42    356
273   -136     33    340
274   -113     42    363
275     81     51    331
276    191     57    201
277    214     64    174
278    211     69    162
279    215    100    128
280    186    100     30
281     37     91   -129
282    -10     99   -143
283    -12     88   -144
284    -14     77   -147
285     -8     81   -143
286     -9     80   -149
287     -8     74   -148
288     -3     74   -141
289    -19     88   -154
290     -8     79   -141
291    -20     79   -153
292    -20     79   -153
293     20     76   -143
294     83     51   -122
295    211     64    160
296    207     74    136
297    192    101    146
298    188    143    137
299    180    154    124

Average magnitude (default Hm) and sigma of 300 vectors =  307.2,   75.7

Reject outliers? (0 or d, reject if > d*sigma from mean) 2
Rejection level selected:  2.0

Rejecting measurements if abs(vector_length-average)/(std. dev.) >   2.0

Number of measurements to be rejected: 0, accepted: 300

300 measurements processed, expected 300

Expected norm of local field vector Hm? (Enter 0 for default    307.2) 0

Set Hm =    307.2

Combined bias vector B:
  -54.22    41.79   112.05

Correction matrix Ainv, using Hm=   307.2:
  1.10759   0.02096   0.03081
  0.02096   1.00811  -0.00509
  0.03081  -0.00509   1.08489

Where Hcalc = Ainv*(H-B)

Code initialization statements...

 float B[3]
 {  -54.22,   41.79,  112.05};

 float Ainv[3][3]
  {{  1.10759,  0.02096,  0.03081},
  {  0.02096,  1.00811, -0.00509},
  {  0.03081, -0.00509,  1.08489}};
 output filename for corrected values (csv) mag_out.txt

RMS corrected vector length 307.164411

RMS residual -0.000000

With this data implemented in code from
jremington/ICM_20948-AHRS

data from Arduino

343, 3, -33
343, 2, -32
343, 3, -33
343, 2, -33
342, 3, -33
342, 2, -33
345, 2, -32
338, -4, -32
335, -13, -33
331, -21, -33
327, -26, -35
322, -31, -37
313, -37, -41
307, -42, -43
297, -49, -49
287, -53, -56
275, -57, -64
263, -59, -74
260, -58, -74
257, -58, -76
261, -58, -74
260, -58, -73
261, -58, -74
283, -53, -56
296, -49, -49
307, -38, -44
322, -29, -35
331, -16, -32
336, -4, -32
340, 2, -33
342, 9, -35
348, 19, -36
1, 32, -40
17, 45, -51
33, 52, -59
46, 55, -9
65, 57, -83
70, 58, -87
78, 59, -92
82, 58, -96
86, 57, -98
89, 57, -101
88, 57, -101
89, 57, -101
83, 57, -97
59, 57, -78
25, 48, -56
35, 30, -42
335, 4, -28
339, 7, -36
349, 2, -31
350, 2, -33
350, 2, -32
348, 2, -32
349, 3, -33
349, 3, -32
350, 3, -32
349, 3, -33
350, 9, -34

Why pitch is effecting yaw is my primary concern..
is tilt compensation not done here?

1 Like

I tried to use Scilab for plotting corrected values.
But I am completely new, I cannot achieve to do it,
can someone help me with code or point me some tutorial for that?

1 Like

You can also try giving something like the adafruit ahrs libs your sensor data for fusion.

Probably because you did not apply the calibration corrections properly.

Post the results of the magneto calibration steps, and post the code showing how you applied the calibration to the raw data.

I cannot upload files

You uploaded plenty of files, just not the useful ones.

1 Like

Thank you for your response, But I have only Arduino UNO, So I cant use DMP, So I am trying to be with basics.
Is there something small fusion which can help me other than what @jremington mentioned?

Hi @jremington
I read your posts a lot on calibration and IMU behavior they are very informative. Thank you for your response.

Probably because you did not apply the calibration corrections properly.

  • You may be true as I am just getting started on calibration

Post the results of the magneto calibration steps

PS C:\Users\Lenovo\Documents\Arduino\libraries\ICM_20948-AHRS\New_Calib> .\magneto.exe

Magneto 1.4 2/10/2021
Input .csv file? mag.csv
  0    220     72    147
  1    231     74    131
  2    226     81    141
  3    217     77    140
  4    219     74    138
  5    224     74    134
  6    221     74    131
  7    221     76    143
  8    238     66    143
  9    225     67    135
 10    214     99    150
 11    178    169    186
 12    105    252    184
 13     -9    319    147
 14    -98    335    150
 15   -104    324    163
 16     -2    319    171
 17    107    257    153
 18    161    106    257
 19    133    -27    275
 20     82   -113    311
 21     12   -173    313
 22     46   -158    299
 23    142    -47    287
 24    163    174    238
 25     59    298    184
 26    -30    338    165
 27    -33    327    190
 28     -4    314    237
 29      7    135    399
 30    -72   -183    313
 31    -33   -261    118
 32     41   -226      0
 33     31   -211    -26
 34      0   -226    -26
 35    -23   -265    108
 36     29   -148    339
 37    117    260    252
 38      8    308    -34
 39    -36     93   -159
 40    -25    -71   -146
 41    -18   -127    -93
 42    -16    -35   -154
 43     33    216   -102
 44     18    335    191
 45      9    294    289
 46     18    308    252
 47     36    306    251
 48    117    250    226
 49    202     66    219
 50    256    -60    104
 51    192    -61    -58
 52    182   -109    -29
 53    192   -152     67
 54    198    -12    223
 55    165    187    184
 56    182    179     74
 57    175    205    122
 58    194    164    138
 59    208     98    125
 60    262     13    127
 61     69   -217    205
 62    -89   -241    213
 63   -173     89    385
 64     90    199    305
 65    163    114    257
 66    173     69    257
 67    164     55    263
 68    142      7    287
 69    104   -155    249
 70     -7   -238      9
 71   -128   -130    -99
 72   -129   -230     41
 73    118   -148    275
 74    124    215    238
 75     77    276    213
 76    170     74    264
 77    110   -202      8
 78    -14    -10   -166
 79   -119   -250    134
 80     75    153    377
 81     31    301    197
 82    153    202    141
 83    165    -96    207
 84     99   -123    -97
 85     39      1   -157
 86    -25   -162    -79
 87   -150   -171    287
 88    -62    221    363
 89    139    257    184
 90    202     66    150
 91    115   -192    -15
 92     55    -65   -175
 93     88    -76   -117
 94   -111   -246    133
 95    -70    161    410
 96    159    244    133
 97    210     -7     80
 98     43   -183    -83
 99     38    -50   -178
100     78   -111    -98
101   -128   -231    194
102    -83    157    395
103    161    222    119
104    169    -37      4
105    -83   -215    -51
106    -23    -44   -176
107     64    -79   -127
108    -21   -264    166
109    -37    142    409
110    139    215    198
111    185    -89     65
112   -129   -111   -167
113     31    -35   -159
114   -217   -171     30
115    -78    -41    388
116    122    257    143
117    173    -23    -20
118   -174   -223     76
119   -110    -38   -155
120   -199   -222    131
121    -83     91    419
122    140    201    159
123    107   -169     10
124   -185   -232    131
125   -129   -104    347
126     24   -171    270
127    -21      2    399
128   -171    -55    413
129     82   -236    123
130   -316    -31     53
131   -336     88     33
132    -61   -272    115
133     96     42    323
134    -78    270    264
135    -18     44    421
136    -53   -211    -52
137    -42    106   -181
138    -78   -192    -55
139    -13    -86    376
140     59    295    181
141    187    139    146
142     69   -205    -10
143     52     21   -193
144     -9   -110   -125
145    -60   -183    301
146     69    275    214
147    199    122    105
148     70   -228    104
149   -268   -145    163
150   -325     -6     65
151   -334     83    192
152   -286      8    290
153   -194    -61    366
154   -279     18    336
155   -231     31    376
156   -175    -59    388
157   -201      0    377
158   -171   -221    175
159    -31    -35   -171
160   -210    216    -26
161   -296    192    131
162   -296    109     62
163   -129   -235    174
164    -83     36    431
165   -185     -3    366
166     41   -238    178
167    -13    217   -148
168   -276    226    130
169   -237   -155    118
170   -134    -71    414
171   -257     51    328
172      6   -247    165
173   -112    172   -160
174   -216    189    -41
175   -271     -2    -47
176   -331    100      4
177   -278    238     66
178   -227    281    121
179   -225    223    -40
180   -111    186   -140
181   -167    193   -106
182   -226    227    -32
183   -230    259      4
184   -156    267    -34
185    -88    270    -81
186     -1    272    -84
187     71    275    -39
188    153    237     22
189    179    221     92
190    131    232    233
191     65    254    280
192     79    254    261
193    147    251    173
194    146    247     93
195    129    242     -5
196    -64    240   -105
197   -176    233    -59
198   -272    247    110
199   -261    269    185
200   -251    249    178
201   -251    269    171
202   -184    264    258
203     12    246    313
204    129    240    233
205    102    252    248
206    -66    315    255
207   -111    357    187
208   -162    357     85
209   -131    328    -41
210     -6    340    -27
211    100    255    -74
212    187    -56    -29
213     83   -207    214
214      2    -95    358
215    -42     33    419
216    -98    187    371
217   -131    280    271
218   -148    320    174
219   -157    319    156
220   -139    295    267
221    -70     -7    403
222     26   -213    237
223     77   -128    -95
224    -15    182   -141
225   -117    300      5
226   -108    296     19
227   -113    286      9
228   -116    294      9
229    -36    261    -68
230    219     61    -10
231    213    -40    121
232    214     64    165
233    152    178    201
234    153    144    195
235    170    129    217
236    175    142    176
237    201    108    156
238    196    103    154
239    217     90    125
240    211    101    119
241    115     86    293
242     23     71    369
243    -94     52    372
244   -101     37    368
245   -131     46    357
246   -134     44    352
247   -110     51    369
248     -7     70    368
249    124     89    286
250    217     95    159
251    215     72    154
252    222     80    147
253    211     91    136
254    213     83    159
255    215     90    144
256    219     96    141
257    211     79    141
258    225     80    149
259    148     94    257
260     79     88    334
261     -2     77    361
262    -81     49    366
263   -117     44    352
264   -117     41    345
265   -125     37    356
266   -129     49    350
267   -122     41    350
268   -130     30    339
269   -129     44    357
270   -134     36    350
271   -127     41    347
272   -130     42    356
273   -136     33    340
274   -113     42    363
275     81     51    331
276    191     57    201
277    214     64    174
278    211     69    162
279    215    100    128
280    186    100     30
281     37     91   -129
282    -10     99   -143
283    -12     88   -144
284    -14     77   -147
285     -8     81   -143
286     -9     80   -149
287     -8     74   -148
288     -3     74   -141
289    -19     88   -154
290     -8     79   -141
291    -20     79   -153
292    -20     79   -153
293     20     76   -143
294     83     51   -122
295    211     64    160
296    207     74    136
297    192    101    146
298    188    143    137
299    180    154    124

Average magnitude (default Hm) and sigma of 300 vectors =  307.2,   75.7

Reject outliers? (0 or d, reject if > d*sigma from mean) 2
Rejection level selected:  2.0

Rejecting measurements if abs(vector_length-average)/(std. dev.) >   2.0

Number of measurements to be rejected: 0, accepted: 300

300 measurements processed, expected 300

Expected norm of local field vector Hm? (Enter 0 for default    307.2) 0

Set Hm =    307.2

Combined bias vector B:
  -54.22    41.79   112.05

Correction matrix Ainv, using Hm=   307.2:
  1.10759   0.02096   0.03081
  0.02096   1.00811  -0.00509
  0.03081  -0.00509   1.08489

Where Hcalc = Ainv*(H-B)

Code initialization statements...

 float B[3]
 {  -54.22,   41.79,  112.05};

 float Ainv[3][3]
  {{  1.10759,  0.02096,  0.03081},
  {  0.02096,  1.00811, -0.00509},
  {  0.03081, -0.00509,  1.08489}};
 output filename for corrected values (csv) mag_out.txt

RMS corrected vector length 307.164411

RMS residual -0.000000

Is there something for calibration of magnetometer?

ICM_20948_I2C imu; // create an ICM_20948_I2C object imu;

// VERY IMPORTANT!
//These are the previously determined offsets and scale factors for accelerometer and magnetometer, using MPU9250_cal and Magneto
//The compass will NOT work well or at all if these are not correct

//Gyro default scale 250 dps. Convert to radians/sec subtract offsets
float Gscale = (M_PI / 180.0) * 0.00763; //250 dps scale sensitivity = 131 dps/LSB
float G_offset[3] = {-51.3, 93.8, -47.0};

//Accel scale: divide by 16604.0 to normalize
float A_B[3]
 { -614.88, 9543.73, -810.14};

float A_Ainv[3][3]
  {{  1.07207,  0.00232,  0.02329},
  {  0.00232,  1.15398,  0.01192},
  {  0.02329,  0.01192,  0.87100}};

//Mag scale divide by 369.4 to normalize
float M_B[3]
 {  -54.22,   41.79,  112.05};

float M_Ainv[3][3]
  {{  1.10759,  0.02096,  0.03081},
  {  0.02096,  1.00811, -0.00509},
  {  0.03081, -0.00509,  1.08489}};

// local magnetic declination in degrees
float declination = -0;

These are the only lines I modified in the library
jremington/ICM_20948-AHRS

Steps I followed for calibration

  1. Power on UNO and flash ICM_20948_get_cal_data.ino
  2. Captured 300 samples of data.
  3. Extracted only mag x,y,x data from it.
  4. Passed to Magneto1.4 as i showed above
  5. Got offsets and hard iron matrix.
  6. Modified them in the code I showed above.
  7. Captured data using ICM_20948_Mahony.ino
  8. Found that pitch affects yaw.

Note:
"The IMU is flat to the surface"
Why I am saying this is previously I worked on BMX160 which I ran into problems, As I have my IMU vertical in the system. So I Axis remapped and solved it.
Now want to replace it with ICM20948. so I started research on this IMU.

Hi @jremington
Can you spare some time and connect through the meet/skype for an hour.
So that I can explain my system and my challenges.
you can guide me on the right path.

Sorry, this is the only one I'm aware of.

The best test for whether you have properly applied the corrections to the magnetometer and accelerometer is to collect 2-300 (corrected) data points from each, and run the magneto step for each once again.

The offsets should be about zero, and the matrix elements about 1 (diagonal) and zero (off diagonal).

Edit: it looks like you did enter the corrections properly, so I'll recheck the Github repo using my sensor.

1 Like

I downloaded the ICM_20948 Mahony code from my repository, uploaded it to an Arduino Pro Mini using the existing calibration for the one ICM_20948 sensor I have, pointed the sensor X axis roughly toward North, and got the following result.

Since I'm holding the sensor in my hand while applying pitch changes, I expect minor variations but conclude that yaw is not significantly affected by changes in pitch.

What did you do about the gyro offsets?

Angles below are yaw, pitch, roll

354, 3, 4
359, 6, 4
355, 10, 3
356, 16, 3
354, 19, 3
352, 23, 3
354, 28, 3
353, 29, 3
353, 31, 3
353, 29, 3
353, 5, 2
354, -13, 3
357, -26, 5
354, -33, 5
356, -36, 5
355, -38, 5
355, -40, 5
357, -40, 5
356, -41, 7
359, -33, 4
358, -40, 7
358, -41, 7
356, -34, 5
356, -26, 4
355, -18, 3
354, -14, 2
353, -9, 2
353, -2, 1
353, 5, -0
354, 9, -0

Thank you @jremington

Yes , I missed it.
Just now I modified them and tried to test.
for my surprise the magneto values are not coming.

Yesterday I tried to use DMP can that cause this issue?
Library : SparkFun_9DoF_IMU_Breakout_-_ICM_20948

I turned off the sensor and powered on.
still cant see any magnetic data out.

Can someone help me how to disable DMP Or reset the IMU to initial state?

3624, 448, 32767, 0, 0, 0
3672, 524, 32767, 0, 0, 0
3628, 456, 32767, 0, 0, 0
3636, 532, 32767, 0, 0, 0
3620, 528, 32767, 0, 0, 0

If there are no data from the magnetometer, that certainly explains why pitch affects yaw!

I don't think the sensor has any semi-permanent memory, so try the simplest example from the Sparkfun library that collects raw data.

1 Like

No @jremington ,
the issue with "Pitch effects Yaw" May be with the Gyro offsets.
Because without Magnetometer yaw doesn't change.

This may help someone out there struggling similar problem.

myICM.startupMagnetometer();
  if (myICM.status != ICM_20948_Stat_Ok)
  {
    SERIAL_PORT.print(F("startupMagnetometer returned: "));
    SERIAL_PORT.println(myICM.statusString());
  }

Adding this piece of code to the basic example started my magnetometer.

Now I will test gyro offsets and will confirm @jremington .

HI @jremington

Yes with Gyro offset it was working great.

6, -46, 9
5, -45, 9
6, -45, 9
6, -45, 9
6, -45, 9
2, -45, 8
3, -45, 9
4, -40, 3
5, -30, 2
6, -22, 0
9, -15, 3
9, -12, 3
10, -4, 4
10, 4, -1
7, 15, 4
9, 27, 3
18, 40, -8
22, 49, -13
26, 56, -12
44, 61, -36
51, 59, -49
66, 65, -63
58, 63, -54
52, 63, -46
50, 65, -41
57, 65, -51
54, 65, -45
53, 61, -48
43, 58, -35
32, 52, -24
21, 41, -6
9, 16, 11
10, -2, 7
16, -20, 6
16, -39, 5
19, -50, 12
21, -59, 11
17, -65, 6
22, -66, 14
19, -67, 11
25, -65, 15
19, -63, 9
33, -55, 26
18, -42, 6
16, -40, 4
15, -37, 3
20, -35, 11
15, -39, -0
14, -38, -2
14, -38, -3
13, -38, -3
15, -32, -1
14, -33, 4
13, -28, 3
14, -31, 2
11, -34, 2
11, -34, 2
12, -31, 3
10, -25, 3
10, -17, 1
10, -12, 1
10, -4, 1
7, 9, 3
6, 22, 7
7, 35, 2
5, 43, 4
4, 46, 4
5, 42, 4
3, 33, 7
2, 22, 5
2, 9, 6
4, -6, 11
6, -19, 10
6, -26, 12
9, -31, 9
11, -36, 10
12, -35, 13
9, -29, 10
9, -21, 11
7, -10, 10
4, 4, 9
3, 15, 7
3, 26, 7
2, 23, 8
5, 8, 8
8, -14, 10
12, -28, 12
13, -33, 10
12, -34, 10
9, -19, 2
8, -5, 9
7, 6, 6
6, 20, 8
7, 21, 5
5, 12, 11
7, -8, 10
12, -24, 13
13, -32, 10
11, -27, 8
9, -17, 7
9, -0, 3
8, 9, 2
9, 23, -3
11, 33, -5
10, 24, -1
8, 17, 2
8, -9, 10
8, -20, 12
12, -29, 18
13, -31, 18
8, -15, 11
9, 3, -5
11, 24, -11
19, 42, -23
10, 48, -11
8, 22, -5
7, -2, 12
10, -19, 16
16, -29, 20
18, -31, 15
22, -37, 16
19, -27, 18
18, -27, 1
13, -29, -12
11, -31, -3
11, -35, 4
13, -45, 9
15, -45, 9
14, -46, 11

These are my values out.

But I have some observations

  1. If pitch changes between +45 to -45 the yaw seems great. But if it crosses that range it changes the yaw a lot. - In above values it can be observed.
  2. Initial point of pitch and roll should be "0" by default with calibration?
    in my case the pitch is starting at plane surface is -50. Why like that?
    some calibration point I missed?
    3)Is there a way to start sensor at 0 pitch and 0 roll? on power on.
  3. Cant I achieve atleast +90 to -90 in pitch?
  4. Why your pitch just changing only 2-3 degrees and mine changing really 10 degrees. Is that because of way we pitch the IMU or something more I can do to make yaw stable.
  • Pitch and roll are determined by the accelerometer. Both should be zero when the sensor is level, so there is still a problem with your calibration.

  • At 90 or -90 degrees in pitch, gimbal lock becomes the problem and the yaw and roll angles will be wrong. Euler angles are not useful over the full 360 range.

Why your pitch just changing only 2-3 degrees

I am changing the angle slowly, and it is being correctly reported. Your calibration is still wrong, or the gyro sensitivity/scale factor is wrong.

As a test, you can set the gyro readings to be zero, and the sensor should report the correct orientation when held still. However, it will respond slowly to changes in orientation.

Pitch and roll are determined by the accelerometer. Both should be zero when the sensor is level, so there is still a problem with your calibration.

  • True @jremington its the problem with calibration
  • I turned the IMU as infinite for MAG, But the Accelerometer required slow and steady calibration
  • I Turned the IMU in 45degree in all axis.
  • Now pitch and roll are at 4 degrees only.

At 90 or -90 degrees in pitch, gimbal lock becomes the problem and the yaw and roll angles will be wrong. Euler angles are not useful over the full 360 range.

  • Means we cant move object in 360 degree using Euler then.
  • Is reading quaternions and understanding orientation of object in space easy?
    can you/someone point me best tutorial to understand the quaternions and orientation

the gyro sensitivity/scale factor is wrong.

  • I am using the maximum available sensitivity of the sensor is this wrong?
  • what is the best sensitivity/scale for ACC,GYRO & MAG?

There may be a problem with your code and/or calibration.

In my hands, the same code and sensor, when properly calibrated, work exactly as expected and very well. So, start over, download the code again, redo all the calibration steps and check every entry carefully.

Means we cant move object in 360 degree using Euler then

Not without taking some simple corrective actions, described here: Maths - Conversion Quaternion to Euler - Martin Baker

I am using the maximum available sensitivity of the sensor is this wrong?

Whatever scale you use, the output units must be in radians/sec. I used the default 250 degrees/sec and converted them using this scale factor:

//Gyro default scale 250 dps. Subtract offsets, then convert to radians/sec 
float Gscale = (M_PI / 180.0) * 0.00763; //250 dps scale sensitivity = 131 dps/LSB

Thank you @jremington

Not without taking some simple corrective actions, described here: Maths - Conversion Quaternion to Euler - Martin Baker

-- Will implement them

Daily I need calibrate IMU?

  • Today while i am checking i found the calibration is disturbed.
    -- My roll and pitch are not crossing +/-24 degrees
  • why my accelerometer calibration can be disturbed?
  • Is it mandatory to do calibration daily or is there a measure to know that calibration disturbed?
    or when to do it ?
  • Is there a dynamic calibration library which can reduce the efforts of calibration and do it on power on with simple gestures like I do in my mobile 8 motion.
  • Is there a way to reset the pitch and roll values to zero after I set the device to some orientation?

You need to calibrate the IMU in its final place of installation, and any time the physical environment has changed, like the presence of current carrying wires, magnets or magnetizable objects (even steel mounting screws).

-- My roll and pitch are not crossing +/-24 degrees

Something is seriously wrong.

Adafruit has a more automated calibration procedure.

To reset pitch and roll to zero for an arbitrary orientation requires a simple quaternion multiplication.

To reset pitch and roll to zero for an arbitrary orientation requires a simple quaternion multiplication.

  • Can you point me to the tutorial or method how to do it @jremington

is there a measure to know that calibration disturbed?

  • Is there a method to know that it was disturbed?

I tried to use Scilab for plotting corrected values but cant do it.

  • Can you give some small script or tutorial link on how to do it?

Something is seriously wrong.

  • Yes my bad, I done a mistake.
    I tried to add come configuration and this happened.
    I removed it and now it is working.
 void setup()
{
  Serial.begin(115200);
  while (!Serial); //wait for connection
  WIRE_PORT.begin();
  WIRE_PORT.setClock(400000);
  imu.begin(WIRE_PORT, AD0_VAL);
  if (imu.status != ICM_20948_Stat_Ok) {
    Serial.println(F("ICM_90248 not detected"));
    while (1);
  }
    imu.startupMagnetometer();
  if (imu.status != ICM_20948_Stat_Ok)
  {
    Serial.print(F("startupMagnetometer returned: "));
    Serial.println(imu.statusString());
  }
//----------These are the lines created problem-----------------------
  // Set full scale ranges for both acc and gyr
//  ICM_20948_fss_t myFSS; // This uses a "Full Scale Settings" structure that can contain values for all configurable sensors
//
//  myFSS.a = gpm4; // (ICM_20948_ACCEL_CONFIG_FS_SEL_e)
//                  // gpm2
//                  // gpm4
//                  // gpm8
//                  // gpm16
//
//  myFSS.g = dps250; // (ICM_20948_GYRO_CONFIG_1_FS_SEL_e)
//                    // dps250
//                    // dps500
//                    // dps1000
//                    // dps2000
//
//  imu.setFullScale((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), myFSS);
//  if (imu.status != ICM_20948_Stat_Ok)
//  {
//    Serial.print(F("setFullScale returned: "));
//    Serial.println(imu.statusString());
//  }
}

What I want to do is adjust the sensitivity but then this started happening.
Is something wrong with this?

As I understood the basics let me explain my application

I have two IMU one in-ground vehicle and one head-mounted.

I want to control the vehicle using head gestures.

my primary observations

Can we achieve the movement by vehicle with just left and right movement of the head?

Is the yaw difference between the two sensors will be constant always?

If not how to achieve the constant yaw difference between two sensors
--- I already tried to log both values and found the difference between yaw is changing from 0 to 50 degrees in motion and again reaching 0.
---- Is my idea correct? - taking the difference of two Imu yaws., Can I achieve it?

Is there some fusions that can fuse two or three IMUs and give an orientation of object for indoor navigation?

@jremington please help me out.
Or any more info required @jremington?

Anyone, please support me on my issues with the project?
Something I am missing as per knowledge with IMU or basic process?