cancel
Showing results for 
Search instead for 
Did you mean: 

MotionFX magnetometer calibration not always working

BFlor.1
Associate II

Hi everybody,

I use the motionFX with accelerometer, gyroscope and magnetometer (9X sensor fusion) but I have a problem using the magnetometer calibration.

I proceed as mentioned in the documentation of motionFX library:

  • Call MotionFX_MagCal_init
  • Call MotionFX_MagCal_run and MotionFX_MagCal_getParams in a loop until I get MFX_MAGCALGOOD quality

Some remarks:

  • the magnetometer is very closed of dc motors, so there is very important hard iron bias.
  • during the calibration, I do a 360 turn back and forth, on each axis. But most of the time, the calibration status doesn't change.

Sometimes, it is impossible to get a MFX_MAGCALGOOD quality, I only get MFX_MAGCALUNKNOWN.

I have a few questions:

  • how MotionFX_MagCal_init and MotionFX_MagCal_run work? After how much time and after how many samples can we expect to have good calibration results?
  • is there any restriction on the calibration algorithm about the hard iron bias range? (I mean, does calibration work with very high hard iron bias?)
  • is the move I do during the calibration correct ? What move am I supposed to do during the calibration to be sure to get good calibration on any product? 
  • I noticed that on some products, the calibration is easily successful, but on others, it is impossible to achieve. Do you have any ideas on what could explain such difference?

Thanks for your time and your help

1 ACCEPTED SOLUTION

Accepted Solutions
BFlor.1
Associate II

Hello,

Thanks a lot for the update.

I figured out what was my problem, and it was actually.... me.

I passed a delta time to the function MotionFX_MagCal_run (like the propagate and update functions) whereas a timestamp is expected... Now I don't have random results depending on the product I am working with.

But now, I face another problem concerning the parameter "sampletime" of the MotionFX_MagCal_init function.

In my case, the magnetometer is not on the same board than accelerometer and gyroscope, and I have a quite slow sampling rate on the magnetometer data : 200ms period between two consecutive data. However I can succesfully use the sensor fusion library (even if the result may not be as good as it could be with a higher mag sampling rate).

Concerning the mag calibration, if I pass a 200ms samplingtime to the MotionFX_MagCal_init function, I never succedeed to achieve a calibration. But if I pass a fake lower sampletime (let's say 10ms), I get calibration results (even with strong hi bias around).

Do you have any idea why a high samplingrate may not work or if I do something wrong?

Thanks again for your time

View solution in original post

4 REPLIES 4
Miroslav BATEK
ST Employee

Hello,

  • how MotionFX_MagCal_init and MotionFX_MagCal_run work? After how much time and after how many samples can we expect to have good calibration results?

Usually it takes a few seconds, but it really depends on the data. If there is a lot of disturbances the algorithm won't be able calculate the calibration coefficients and won't achieved the GOOD calibration quality.

  • is there any restriction on the calibration algorithm about the hard iron bias range? (I mean, does calibration work with very high hard iron bias?)

Theoretically there is not limit for hard iron bias, but your sensor might be saturated and it will impact the calibration.

  • is the move I do during the calibration correct ? What move am I supposed to do during the calibration to be sure to get good calibration on any product? 

Yes, rotation along all tree axis is good, you can do also do "8 shape" movement.

  • I noticed that on some products, the calibration is easily successful, but on others, it is impossible to achieve. Do you have any ideas on what could explain such difference?

The best way to find the root cause is plot the magnetometer data in scatter plot 2D chart, X-Y, X-Z, Y-Z. It should give you more information what's going on.

BFlor.1
Associate II

Hello,

Thanks a lot for the update.

I figured out what was my problem, and it was actually.... me.

I passed a delta time to the function MotionFX_MagCal_run (like the propagate and update functions) whereas a timestamp is expected... Now I don't have random results depending on the product I am working with.

But now, I face another problem concerning the parameter "sampletime" of the MotionFX_MagCal_init function.

In my case, the magnetometer is not on the same board than accelerometer and gyroscope, and I have a quite slow sampling rate on the magnetometer data : 200ms period between two consecutive data. However I can succesfully use the sensor fusion library (even if the result may not be as good as it could be with a higher mag sampling rate).

Concerning the mag calibration, if I pass a 200ms samplingtime to the MotionFX_MagCal_init function, I never succedeed to achieve a calibration. But if I pass a fake lower sampletime (let's say 10ms), I get calibration results (even with strong hi bias around).

Do you have any idea why a high samplingrate may not work or if I do something wrong?

Thanks again for your time

BFlor.1
Associate II

Also, I have another question (no link with the calibration): before integrated the 9X library, my project was compiled using the "-mfloat-abi=hard" option to use hardware floating point unit of the MCU. But in order to use the library (which is precompiled with no hardware floating point unit set), I have to compile the whole project with the option "-mfloat-abi=softfp".

Are there any way to get the 9X library already compiled with the "-mfloat-abi=hard" option ? I would prefer to use this option, as my MCU supports the hardware floating point.

Thanks

I know this post is old,but I thought that I would answer your question as it may help someone else. I am using a STM32L471 that also has a hardware FPU. I use STM32CubeIDE and in my project I have included the X-CUBE-MEMS1.8.2.0 Software Pack and from that the MotionFX library. In my Project Explorer view if I expand: Middlewares> ST> STM32_MotionFX_Library> Lib> it shows:

MotionFX_CM4F_wc32_ot_hard.a

This leads me to believe that the hardware FPU object code is included since if I browse...

en.x-cube-mems1\STM32CubeExpansion_MEMS1_V8.2.0\Middlewares\ST\STM32_MotionFX_Library\Lib\

I find that there are 10 different object files for different processor series and there are 2 that have 'hard' as part of their names namely:

MotionFX_CM4F_wc32_ot_hard.a

MotionFX_CM7F_wc32_ot_hard.a

So it does seem that depending on your processor it includes the hard or soft FP object code for the MotionFX library.

Edit:

NB:

I was also struggling with to get the cal_quality = MFX_MAGCALGOOD. Using the X-NUCLEO-IKS01A3 sensor expansion board together with a NUCLEO-F446RE board. I used the Unicleo-GUI interface together with the DataLogFusion example:

en.x-cube-mems1\STM32CubeExpansion_MEMS1_V8.3.0\Projects\STM32F401RE-Nucleo\Applications\IKS01A3\DataLogFusion

In debug mode I was able to watch the cal_quality variable. I moved the board around slowly in figures of 8 for 10 min and then finally I saw the MFX_MAGCALGOOD appear. Then I tried again, thinking that the instruction manual says 'slowly' so I forced myself to slow down the motion, it took 21 min and still no calibration. Then I got fed up and moved it vigorously in a small figure of 8. It took 13 sec and calibration was done! I tried again and got calibration done in 6 sec. I tried again and I got it done in 4 sec! The bottom line is the more vigorously you move the board, the quicker it calibrates. If you move it slowly like I did, you better prepare for no calibration or a very long calibration time .

I really hope this helps someone. It took me days to figure this out since the documentation says to move it slowly.