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

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

752 Views
woutervos
Contributor I

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

Labels (1)
0 Kudos
Reply
1 Reply

450 Views
michaelestanley
NXP Employee
NXP Employee

Wouter,

I'm always pleased to see people digging into the code.  I'll add this to my list of things to review for future releases.

Best regards,

Mike

0 Kudos
Reply