ST X-CUBE-MEMS1 User Manual Download Page 6

heading_6/9X

 represents the heading of the device in degrees. Heading 0 degree represents the

magnetic North direction for 9-axis sensor fusion, while, for 6-axis sensor fusion, it represents heading of
device at the algorithm start.

headingErr_6/9X

 represents the heading error of the device in degrees.

2.2.5

MotionFX library output data rate

It is important to set up the sensor fusion library output data rate properly; 100 Hz is recommended.
The output data rate for:

the gyroscope and the accelerometer should be equal to or greater than 100 Hz;

the magnetometer can be lower - 20/40 Hz is typically good for a magnetic field sensor.

Cortex-M3, Cortex-M4 and Cortex-M7

It is possible to scale the library system requirements in terms of MCU/MPU load. As the 

MotionFX_update

function requires approximately three times more computation power than the 

MotionFX_propagate

 function, it

can be called at a lower frequency than the library output data rate if the system resources are limited (e.g., in
embedded systems).
Use the 

modx

 parameter in 

MFX_knobs_t

 structure to decrease the frequency of 

MotionFX_update

 function

calls. For example, setting 

modx

 to 2 calls the 

MotionFX_update

 function once every two

MotionFX_propagate

 function calls.

The recommended settings are:

modx

 = 1, for tablets or other systems with MCU/MPU and for STM32F4;

modx

 = 2, for STM32F1.

2.2.6

Sensor calibration in the MotionFX library

Gyroscope and accelerometer calibration

Accelerometer calibration is not necessary for sensor fusion except for applications demanding very high
orientation precision; it involves aligning the system in several positions according to the gravity direction.
Gyroscope calibration is handled automatically by the MotionFX library by continuously compensating the zero-
rate offset effect.

Magnetometer calibration

The MotionFX library contains routines for magnetometer hard iron calibration.
The magnetometer is affected by the hard-iron and soft-iron phenomena described below.

Hard-iron distortion

Hard-iron distortion is normally generated by ferromagnetic material with permanent magnetic fields that are part
of the object (e.g., a tablet) in use. These materials can be permanent magnets or magnetized iron or steel. They
are time invariant and deform the local geomagnetic field with different offsets in different directions.
As each board can be magnetized differently, the hard iron effect is specific to the individual board.
If you move the board around a space approximating (as much as possible) a 3D sphere in an ideal environment
(no hard-iron/soft-iron distortion) and plot the collected magnetic sensor raw data, the result is a perfect sphere
with no offset.
The hard-iron distortion effect offsets the sphere along the x, y and z axes; in the x-y plane, the hard-iron
distortion is identified by an offset of the origin of the ideal circle from (0, 0), scatter plots for XY and XZ axes are
sufficient to determine if there is an offset.

Soft-iron distortion

Soft-iron distortion is generated by magnetically soft materials or current carrying PCB traces. While hard-iron
distortion is constant regardless of the orientation, the soft-iron distortion changes with the orientation of the
object in the Earth’s field (soft magnetic materials change their magnetization direction).
The local geomagnetic field is deformed with different gain on different directions. The effect of the soft-iron to
distort the ideal full round sphere into a tilted ellipsoid; in the x-y plane, the soft-iron distortion is identified by a
tilted ellipse with the origin at (0,0) for the XY axis (XZ).
The soft iron effect is the same across all boards of the same design, which is why a good PCB design which
takes magnetometer placement (high current traces/other component clearance) into account can generally avoid
any soft iron effects (valid for X-NUCLEO-IKS01A2 expansion board).

Calibration procedure

UM2220

MotionFX library

UM2220

 - 

Rev 7

page 6/24

Summary of Contents for X-CUBE-MEMS1

Page 1: ...M Cortex M0 ARM Cortex M3 ARM Cortex M4 or ARM Cortex M7 architectures It is built on top of STM32Cube software technology to ease portability across different STM32 microcontrollers The software come...

Page 2: ...ronyms Acronym Description API Application programming interface BSP Board support package GUI Graphical user interface HAL Hardware abstraction layer IDE Integrated development environment UM2220 Acr...

Page 3: ...fusion accelerometer gyroscope magnetometer real time 6 axis motion sensor data fusion accelerometer gyroscope computation of rotation quaternions gravity and linear acceleration data gyroscope bias...

Page 4: ...ation experiences low magnetic interference 50 T most of time it is recommended to increase the value LMode represents the gyroscope bias learning mode the library automatically tracks and calibrates...

Page 5: ...The MotionFX_propagate and the MotionFX_update MotionFX_CM0P_update functions provide the sensor fusion output in the MFX_output_t MFX_CM0P_output_t structure rotation_6 9X represents the system orie...

Page 6: ...eter hard iron calibration The magnetometer is affected by the hard iron and soft iron phenomena described below Hard iron distortion Hard iron distortion is normally generated by ferromagnetic materi...

Page 7: ...eturns mag_data_out cal_quality MFX_MAGCALGOOD or MFX_CM0P_MAGCALGOOD the calibration was successfully performed 4 apply calibration results MAG_Calibrated AXIS_X MAG_Value AXIS_X MAG_Offset AXIS_X MA...

Page 8: ...MFX_engine_state_t MotionFX_getStatus_9X void gets the 9 axes library status returns 1 if enabled 0 if disabled void MotionFX_enable_6X MFX_engine_state_t enable enables or disables the 6 axes functio...

Page 9: ...re type MFX_MagCal_output_t are hi_bias is the hard iron offset array T 50 cal_quality is the calibration quality factor MFX_MAGCALUNKNOWN 0 accuracy of the calibration parameters is unknown MFX_MAGCA...

Page 10: ...Status_euler void gets the status of euler angles calculation returns 1 if enabled 0 if disabled MFX_CM0P_engine_state_t MotionFX_CM0P__getStatus_gbias void gets the status of gyroscope calibration re...

Page 11: ...alibration algorithm data_in parameter is a pointer to input data structure the parameters for the structure type MFX_MagCal_CM0P_input_t are mag is uncalibrated magnetometer data T 50 void MotionFX_C...

Page 12: ...Outputs Data Read Interrupt Initialize MagCal_Init getKnobs setKnobs Propagate MagCal_run MagCal_getParams 2 2 9 Demo code The following demonstration code reads data from the accelerometer gyroscope...

Page 13: ...onFX_enable_9X MFX_ENGINE_ENABLE Using Sensor Fusion algorithm Timer_OR_DataRate_Interrupt_Handler MFX_input_t data_in MFX_output_t data_out float dT float q Quaternion pointer to either to Game Rotat...

Page 14: ...ed time s algorithm Cortex M0 STM32L073RZ at 32 MHz Cortex M7 STM32F767ZI at 96 MHz STM32CubeIDE 1 2 0 IAR EWARM 8 32 3 Keil Vision 5 27 STM32CubeIDE 1 2 0 IAR EWARM 8 32 3 Keil Vision 5 27 Min Avg Ma...

Page 15: ...LEO L476RG NUCLEO L152RE To calibrate the magnetometer perform the figure 8 calibration movement Note You can calibrate the magnetometer only when the sensor fusion is activated When user button B1 is...

Page 16: ...it is automatically detected and the appropriate COM port is opened Figure 5 Unicleo main window Step 3 Start and stop data streaming by using the appropriate buttons on the vertical tool bar The data...

Page 17: ...d application window To switch between 9 axes and 6 axes sensor fusion click on the appropriate button To align the tea pot position point the Nucleo board towards the screen and press Reset model but...

Page 18: ...tep 5 Click on the Scatter Plot icon to check the magnetometer calibration quality Figure 8 Magnetometer scatter plot properly calibrated magnetometer UM2220 Sample application UM2220 Rev 7 page 18 24...

Page 19: ...ding button Figure 9 Datalog window 2 4 References All of the following resources are freely available on www st com 1 UM1859 Getting started with the X CUBE MEMS1 motion MEMS and environmental sensor...

Page 20: ...and ARM Cortex M0 01 Oct 2018 5 Removed references to X NUCLEO IKS01A1 throughout document Updated Section 2 2 4 MotionFX library parameters Table 2 Cortex M4 and Cortex M3 elapsed time s algorithm Fi...

Page 21: ...d 9 axis sensor fusion modes 3 2 2 3 MotionFX library operation 4 2 2 4 MotionFX library parameters 4 2 2 5 MotionFX library output data rate 6 2 2 6 Sensor calibration in the MotionFX library 6 2 2 7...

Page 22: ...List of acronyms 2 Table 2 Cortex M4 and Cortex M3 elapsed time s algorithm 14 Table 3 Cortex M0 and Cortex M7 elapsed time s algorithm 14 Table 4 Document revision history 20 UM2220 List of tables U...

Page 23: ...Figure 3 MotionFX API logic sequence 12 Figure 4 STM32 Nucleo LEDs button jumper 15 Figure 5 Unicleo main window 16 Figure 6 User Messages tab 16 Figure 7 Fusion window 17 Figure 8 Magnetometer scatte...

Page 24: ...ts and ST assumes no liability for application assistance or the design of Purchasers products No license express or implied to any intellectual property right is granted by ST herein Resale of ST pro...

Reviews: