Dear reader,
I noticed that the magnetometer calibration of the sensor fusion algorithm (version 7.10) gave inconsistent results after startup, when repeated a few times. I dug into the code and found the magnetometer calibration procedure is sensor chip dependent. For my sensor, the magnetometer buffer containing the measurements used for the calibration filled too quickly. This caused the geometry of magnetometer measurements to be constricted, resulting in an incorrect fit, with a good fix measure.
I propose the following patch, that makes the procedure sensor chip independent.
In magnetic.h:
59 - #define MESHDELTACOUNTS 50
59 + #define MESHDELTACOUNTS 5.0F
And in magnetic.c:
230 - if (idelta < MESHDELTACOUNTS)
230 + if (idelta < (int32_t)(MESHDELTACOUNTS*pthisMag->fCountsPeruT))
268 - if (idelta < MESHDELTACOUNTS)
268 + if (idelta < (int32_t)(MESHDELTACOUNTS*pthisMag->fCountsPeruT))
In addition, I noticed that in comments of the algorithm it was noted that the magnetic field strength should be between 22 and 67 uT, however in magnetic.h the minimum and maximum were defined as 10 and 90 uT. I propose to change the following:
56 - #define MINBFITUT 10.0F
57 - #define MAXBFITUT 90.0F
56 + #define MINBFITUT 22.0F
57 + #define MAXBFITUT 67.0F
Hopefully someone from NXP can confirm that these patches are correct.
Regards,
Wouter