Wouter Vos

Patch for magnetometer chip dependent calibration problem caused by geometry of magnetometer measurements

Discussion created by Wouter Vos on Oct 28, 2017
Latest reply on Oct 30, 2017 by Mike Stanley

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 ///< magnetic buffer mesh spacing in counts (here 5uT)
59 + #define MESHDELTACOUNTS 5.0F//50 ///< magnetic buffer mesh spacing in uT

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 ///< minimum acceptable geomagnetic field B (uT) for valid calibration
57 - #define MAXBFITUT 90.0F ///< maximum acceptable geomagnetic field B (uT) for valid calibration
56 + #define MINBFITUT 22.0F ///< minimum acceptable geomagnetic field B (uT) for valid calibration
57 + #define MAXBFITUT 67.0F ///< maximum acceptable geomagnetic field B (uT) for valid calibration

Hopefully someone from NXP can confirm that these patches are correct.

Regards,

Wouter

Outcomes