cancel
Showing results for 
Search instead for 
Did you mean: 

The X-CUBE-MEMS1 libraries in detail - MotionMC application

LauraCx
ST Employee

Motion Magnetic Sensor library application and functions in X-CUBE-MEMS1 

1. Motion Magnetic Sensor library

The description of MotionMC library for the magnetic sensor calibration gives the opportunity to get a more detailed overview on the magnetic sensor.

A magnetic sensor is usually intended to measure Earth magnetic field to get the absolute position/direction of the sensor in space. However, near the surroundings of a magnetometer, it can cause distortion of Earth magnetic field. Based on the distortion character, we can categorize it as two types: hard iron and soft iron effect. 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. Soft iron distortion arises from the interaction of the Earth magnetic field and the material which surrounds the magnetometer sensor distorting the Earth magnetic field. The distortion magnitude and direction depend on the incident angle of the Earth magnetic field on the material. Hence, it varies with the magnetometer orientation.

As we will see in more detail in the next post, the library acquires data from the magnetometer and calculates the hard iron (HI) and soft iron (SI) coefficients. The calibration coefficients are then used to compensate raw data from the magnetometer and reduce hard iron and soft iron effects.
1614.png
 

2. Calibration Algorithm

The MotionMC library acquires data from the magnetometer and features the hard iron compensation, theoretically unlimited (within sensor range) and a wide scale factor compensation range from 0.65 to 1.35 in every direction.

The two central functions for the MotionMC manage the magnetometer parameters calibration and are the following ones:

>> void MotionMC_Update (MMC_Input_t *data_in)

>> void MotionMC_GetCalParams (MMC_Output_t *data_out)

where the input data *data_in is a structure composed from:

  • Mag[3] is an array of magnetometer sensor value in µT
  • TimeStamp parameter is the timestamp value in ms for current magnetometer sensor data 

and the output data *data_out is also a structured of:

  • HI_Bias[3] is an array of magnetometer hard iron (HI) coefficients in µT
  • SF_Matrix[3][3] is a 3x3 matrix of magnetometer scale factor (SF) coefficients
  • CalQuality is the calibration quality factor

See below the typical flowchart of the MotionMC calibration procedure :fast_down_button:
 

1615.png
 

3. Resources

User Manual 2192  Getting started with MotionMC magnetometer calibration library in X-CUBEMEMS1 expansion for STM32Cube
 
Version history
Last update:
‎2021-10-22 02:45 AM
Updated by: