cancel
Showing results for 
Search instead for 
Did you mean: 

MotionFX correct sequence

peppea82
Associate II

Hi everybody and thanks in advance for the support.

I have a ST SensorTile and I'm starting with the DataLog project to output data through USB port. I have correctly integrated MotionFX libraries and they seem to run, except there are just a bit of problems.

  • What are the right units for time in MotionFX_propagate and MotionFX_update (param eml_deltatime). It seems it has to be expressed in seconds but in some samples you use a 20 constant defined. For instance: 20ms are 0.02f?
  • What is the param eml_q_update in MotionFX_update? Should I put a float of something or it should remain NULL as stated in example/doc?
  • What is the correct sequence for magnetometer calibration?
    • MotionFX_MagCal_init at start (using sampleTime expressed in milliseconds?)
    • MotionFX_MagCal_run in the loop, before the MotionFX_propagate/_update and until the MFX_MAGCALGOOD is reached?
    • Can the MotionFX_MagCal_run be called every loop independently of the quality reached? What is the drawback?
    • Is possible to know when to call again MagCal run, for possibly changed Mag biases?
    • When is the right time to call MotionFX_MagCal_init to stop calibration? Is there a "right" spot to start again Mag Calibration?
  • How the biases obtained from MotionFX_MagCal_getParams should be used? In what units are they? Should they be added or subtracted from current magnetometer output? Some examples show an additive bias, some other a subtractive bias.
  • Why the MagCal needs a timestamp? Is good to give the HAL_GetTick in every loop it has to be called? (I'm using FreeRTOS in a 20ms timer triggered task).
  • MotionFX_LoadMagCalFromNVM and MotionFX_SaveMagCalInNVM seems to be never called. They are needed at linking time but they seems to be ignored. I've put a simple "save to flash" function (that works correctly outside) but no data is stored in the flash memory. How should I trigger the load/save? If I save parameters, how should I behave using the MagCal routines? What is the advantage?
  • What parameters should/could be manually saved in addition to improve startup time and avoid figure eight recalibration in a fixed setup? Moreover, how can I periodically refresh data? What is the right spot to trigger MagCal/GyroCal? How can the gyro bias calibration be retriggered?
  • How do I know when the right gyro bias is reached? Is useful to start in LMode = 1 (static learning) and then switch to dynamic?
  • Are there any "good to start" ATime, MTime, FRTime for the Sensortile?

Thanks in advance for having the time to read and willing to support me. I hope this answers could be included in the UM2220 User Manual as it seems an imprecise draft.

1 ACCEPTED SOLUTION

Accepted Solutions
Miroslav BATEK
ST Employee

 What are the right units for time in MotionFX_propagate and MotionFX_update (param eml_deltatime). It seems it has to be expressed in seconds but in some samples you use a 20 constant defined. For instance: 20ms are 0.02f?

The eml_deltatime is expressed in seconds, it is float variable, so 20ms is 0.02f.

What is the param eml_q_update in MotionFX_update? Should I put a float of something or it should remain NULL as stated in example/doc?

The emp_q_update parameter (pointer) should remain NULL.

What is the correct sequence for magnetometer calibration?

The sensor fusion algorithm needs calibrated data from magnetometer, you should first perform the magnetometer calibration and then start the sensor fusion. If pass uncalibrated data to sensor fusion algorithm the outputs will have significant error.

MotionFX_MagCal_init at start (using sampleTime expressed in milliseconds?)

Yes, sample time is expressed in milliseconds, you need to tell to the algorithm what is your sample rate for magnetometer data.

MotionFX_MagCal_run in the loop, before the MotionFX_propagate/_update and until the MFX_MAGCALGOOD is reached?

Yes

Can the MotionFX_MagCal_run be called every loop independently of the quality reached? What is the drawback

Yes, you can call the MagCall every loop, but it is not necessary.  Hard iron distortion arises from permanent magnets, magnetized iron or steel located nearby the magnetometer. This distortion remains constant and in fixed location related to the magnetometer for all heading orientations. Hard iron effect adds a constant magnitude field component along each magnetometer axis.

Is possible to know when to call again MagCal run, for possibly changed Mag biases?

No, there is such a logic implemented.

When is the right time to call MotionFX_MagCal_init to stop calibration? Is there a "right" spot to start again Mag Calibration?

When the MagCal return the quality factor MFX_MAGCALGOOD you can stop the calibration.

How the biases obtained from MotionFX_MagCal_getParams should be used? In what units are they? Should they be added or subtracted from current magnetometer output? Some examples show an additive bias, some other a subtractive bias.

The biases are in uT/50 and they should be subtracted from the magnetometer output. Please check application in X-CUBE-MEMS1 package.

Why the MagCal needs a timestamp? Is good to give the HAL_GetTick in every loop it has to be called? (I'm using FreeRTOS in a 20ms timer triggered task).

The MagCal uses internally some filters and it needs to know what is the sample rate of the magnetometer data. You can use the HAL_GetTick, but if the procedure is triggered by timer you can increase simply the timestamp every call by 20ms.

MotionFX_LoadMagCalFromNVM and MotionFX_SaveMagCalInNVM seems to be never called. They are needed at linking time but they seems to be ignored. I've put a simple "save to flash" function (that works correctly outside) but no data is stored in the flash memory. How should I trigger the load/save? If I save parameters, how should I behave using the MagCal routines? What is the advantage?

These functions are callbacks, Load is called when you enable MagCal and Save is called when you disable MagCal.

 What parameters should/could be manually saved in addition to improve startup time and avoid figure eight recalibration in a fixed setup? Moreover, how can I periodically refresh data? What is the right spot to trigger MagCal/GyroCal? How can the gyro bias calibration be retriggered?

There is no possibility to save/restore any other parameters except the magnetometer bias.

How do I know when the right gyro bias is reached? Is useful to start in LMode = 1 (static learning) and then switch to dynamic?

The gyroscope calibration is managed inside the sensor fusion algorithm. If you device is sometimes still I would use the LMode = 1, if it is in continuous movement I would use LMode = 2.

Are there any "good to start" ATime, MTime, FRTime for the Sensortile?

The default values will be OK for SensorTile.

View solution in original post

2 REPLIES 2
Miroslav BATEK
ST Employee

 What are the right units for time in MotionFX_propagate and MotionFX_update (param eml_deltatime). It seems it has to be expressed in seconds but in some samples you use a 20 constant defined. For instance: 20ms are 0.02f?

The eml_deltatime is expressed in seconds, it is float variable, so 20ms is 0.02f.

What is the param eml_q_update in MotionFX_update? Should I put a float of something or it should remain NULL as stated in example/doc?

The emp_q_update parameter (pointer) should remain NULL.

What is the correct sequence for magnetometer calibration?

The sensor fusion algorithm needs calibrated data from magnetometer, you should first perform the magnetometer calibration and then start the sensor fusion. If pass uncalibrated data to sensor fusion algorithm the outputs will have significant error.

MotionFX_MagCal_init at start (using sampleTime expressed in milliseconds?)

Yes, sample time is expressed in milliseconds, you need to tell to the algorithm what is your sample rate for magnetometer data.

MotionFX_MagCal_run in the loop, before the MotionFX_propagate/_update and until the MFX_MAGCALGOOD is reached?

Yes

Can the MotionFX_MagCal_run be called every loop independently of the quality reached? What is the drawback

Yes, you can call the MagCall every loop, but it is not necessary.  Hard iron distortion arises from permanent magnets, magnetized iron or steel located nearby the magnetometer. This distortion remains constant and in fixed location related to the magnetometer for all heading orientations. Hard iron effect adds a constant magnitude field component along each magnetometer axis.

Is possible to know when to call again MagCal run, for possibly changed Mag biases?

No, there is such a logic implemented.

When is the right time to call MotionFX_MagCal_init to stop calibration? Is there a "right" spot to start again Mag Calibration?

When the MagCal return the quality factor MFX_MAGCALGOOD you can stop the calibration.

How the biases obtained from MotionFX_MagCal_getParams should be used? In what units are they? Should they be added or subtracted from current magnetometer output? Some examples show an additive bias, some other a subtractive bias.

The biases are in uT/50 and they should be subtracted from the magnetometer output. Please check application in X-CUBE-MEMS1 package.

Why the MagCal needs a timestamp? Is good to give the HAL_GetTick in every loop it has to be called? (I'm using FreeRTOS in a 20ms timer triggered task).

The MagCal uses internally some filters and it needs to know what is the sample rate of the magnetometer data. You can use the HAL_GetTick, but if the procedure is triggered by timer you can increase simply the timestamp every call by 20ms.

MotionFX_LoadMagCalFromNVM and MotionFX_SaveMagCalInNVM seems to be never called. They are needed at linking time but they seems to be ignored. I've put a simple "save to flash" function (that works correctly outside) but no data is stored in the flash memory. How should I trigger the load/save? If I save parameters, how should I behave using the MagCal routines? What is the advantage?

These functions are callbacks, Load is called when you enable MagCal and Save is called when you disable MagCal.

 What parameters should/could be manually saved in addition to improve startup time and avoid figure eight recalibration in a fixed setup? Moreover, how can I periodically refresh data? What is the right spot to trigger MagCal/GyroCal? How can the gyro bias calibration be retriggered?

There is no possibility to save/restore any other parameters except the magnetometer bias.

How do I know when the right gyro bias is reached? Is useful to start in LMode = 1 (static learning) and then switch to dynamic?

The gyroscope calibration is managed inside the sensor fusion algorithm. If you device is sometimes still I would use the LMode = 1, if it is in continuous movement I would use LMode = 2.

Are there any "good to start" ATime, MTime, FRTime for the Sensortile?

The default values will be OK for SensorTile.

DAlta.1
Associate II

Hi peppea82,

Could you please share the code on how you have integrated that library? I am struggling to do it and I'd appreciate reading you code to better understand@peppea82​ ​