ST X-CUBE-MEMS1 User Manual

ST X-CUBE-MEMS1 User Manual

Getting started with motionfx sensor fusion library in expansion for stm32cube
Hide thumbs Also See for X-CUBE-MEMS1:

Advertisement

UM2220
User manual
Getting started with MotionFX sensor fusion library in X-CUBE-MEMS1
expansion for STM32Cube
Introduction
The MotionFX is a middleware library component of the
X-CUBE-MEMS1
software and runs on STM32. It provides real-time
motion-sensor data fusion. It also performs gyroscope bias and magnetometer hard iron calibration.
This library is intended to work with ST MEMS only.
®
The algorithm is provided in static library format and is designed to be used on STM32 microcontrollers based on the ARM
®
®
®
®
®
®
®
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 comes with sample implementation running on
X-NUCLEO-IKS01A2
or
X-NUCLEO-IKS01A3
expansion board on
a NUCLEO-F401RE, NUCLEO-L476RG,
NUCLEO-L152RE
or
NUCLEO-L073RZ
development board.
UM2220 - Rev 7 - March 2020
www.st.com
For further information contact your local STMicroelectronics sales office.

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the X-CUBE-MEMS1 and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

Summary of Contents for ST X-CUBE-MEMS1

  • Page 1 UM2220 User manual Getting started with MotionFX sensor fusion library in X-CUBE-MEMS1 expansion for STM32Cube Introduction The MotionFX is a middleware library component of the X-CUBE-MEMS1 software and runs on STM32. It provides real-time motion-sensor data fusion. It also performs gyroscope bias and magnetometer hard iron calibration.
  • Page 2: Acronyms And Abbreviations

    UM2220 Acronyms and abbreviations Acronyms and abbreviations Table 1. List of acronyms Acronym Description Application programming interface Board support package Graphical user interface Hardware abstraction layer Integrated development environment UM2220 - Rev 7 page 2/24...
  • Page 3: Motionfx Middleware Library In X-Cube-Mems1 Software Expansion For Stm32Cube

    MEMS sensors, regardless of environmental conditions, for an optimum performance. The library is designed for ST MEMS only. Functionality and performance when using other MEMS sensors are not analyzed and can be significantly different from what described in the document.
  • Page 4: Motionfx Library Operation

    UM2220 MotionFX library 2.2.3 MotionFX library operation The MotionFX library integrates 6- and 9-axis sensor fusion algorithms in one library; they can even run simultaneously to provide both rotation vector (9X) and game rotation vector (6X). Cortex-M3, Cortex-M4 and Cortex-M7 The library implements the following critical internal functions associated with sensor fusion computation: the MotionFX_propagate is a prediction function used to estimate the orientation in 3D space;...
  • Page 5: Figure 1. Example Of Sensor Orientations

    UM2220 MotionFX library Figure 1. Example of sensor orientations Cortex-M0+ Only the sensor orientation must be set using MotionFX_CM0P_setOrientation function. The parameters of this function are orientation strings which are composed in the same manner as for Cortex-M3, Cortex-M4 and Cortex-M7 (see above).
  • Page 6: Motionfx Library Output Data Rate

    UM2220 MotionFX library • 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.
  • Page 7: Figure 2. Stm32 Nucleo Board Rotation During Calibration

    UM2220 MotionFX library The MotionFX library magnetometer calibration library compensates for hard-iron distortions. The magnetometer calibration can be performed at a slower frequency than the sensor fusion output data rate (e.g., 25 Hz). To run the calibration: initialize magnetometer calibration library (MotionFX_MagCal_init or MotionFX_CM0P_MagCal_init) call periodically calibration function (MotionFX_MagCal_run or MotionFX_CM0P_MagCal_run) until the calibration is successfully performed check if calibration was successful (MotionFX_MagCal_getParams or...
  • Page 8: Motionfx Apis

    UM2220 MotionFX library 2.2.7 MotionFX APIs The MotionFX APIs are: • Cortex-M3, Cortex-M4 and Cortex-M7 – uint8_t MotionFX_GetLibVersion(char *version) ◦ retrieves the version of the library ◦ *version is a pointer to an array of 35 characters ◦ returns the number of characters in the version string –...
  • Page 9 UM2220 MotionFX library – void MotionFX_propagate(MFX_output_t *data_out, MFX_input_t *data_in, float *eml_deltatime) ◦ runs the Kalman filter propagate ◦ *data_out parameter is a pointer to output data structure ◦ *data_in parameter is a pointer to input data structure ◦ *eml_deltatime parameter is a pointer to delta time between two propagate calls [sec] –...
  • Page 10 UM2220 MotionFX library • Cortex-M0+ – uint8_t MotionFX_CM0P_GetLibVersion(char *version) ◦ retrieves the version of the library ◦ *version is a pointer to an array of 35 characters ◦ returns the number of characters in the version string – void MotionFX_CM0P_Initialize(void) ◦...
  • Page 11 UM2220 MotionFX library – void MotionFX_CM0P_update(MFX_CM0P_output_t *data_out, MFX_CM0P_input_t *data_in, float deltatime) ◦ runs the sensor fusion algorithm ◦ *data_out parameter is a pointer to output data structure ◦ *data_in parameter is a pointer to input data structure ◦ deltatime parameter is a delta time between two propagate calls [sec] –...
  • Page 12: Api Flow Chart

    UM2220 MotionFX library 2.2.8 API flow chart Figure 3. MotionFX API logic sequence Start Initialize GetLibVersion getKnobs/setKnobs MagCal_Init Wait Expiring Timer Data Read Interrupt Read Acc+Gyr+Mag Data MagCal_run / MagCal_getParams Propagate Update Get MotionFX Outputs 2.2.9 Demo code The following demonstration code reads data from the accelerometer, gyroscope and magnetometer sensors and gets the rotation, quaternions, gravity and linear acceleration.
  • Page 13 UM2220 MotionFX library #define MFX_STR_LENG 35 #define ENABLE_6X 1 float LastTime; […] /*** Initialization ***/ char lib_version[MFX_STR_LENG]; MFX_knobs_t iKnobs; /* Sensor Fusion API initialization function */ MotionFX_initialize(); /* Optional: Get version */ MotionFX_GetLibVersion(lib_version); MotionFX_getKnobs(&iKnobs); /* Modify knobs settings & set the knobs */ MotionFX_setKnobs(&iKnobs);...
  • Page 14: Algorithm Performance

    UM2220 Sample application /* Run Sensor Fusion algorithm */ MotionFX_propagate(&data_out, &data_in, &dT); MotionFX_update(&data_out, &data_in, &dT, NULL) if (ENABLE_6X) q = &data_out.quaternion_6X[0]; /* Game rotation Vector */ else q = &data_out.quaternion_9X[0]; /* Rotation Vector in 9X */ 2.2.10 Algorithm performance Table 2. Cortex-M4 and Cortex-M3: elapsed time (µs) algorithm Cortex-M4 STM32F401RE at 84 MHz Cortex-M3 STM32L152RE at 32 MHz...
  • Page 15: Unicleo-Gui Application

    2.3.1 Unicleo-GUI application The sample application uses the Windows Unicleo-GUI utility, which can be downloaded from www.st.com. Step 1. Ensure that the necessary drivers are installed and the STM32 Nucleo board with appropriate expansion board is connected to the PC.
  • Page 16: Figure 5. Unicleo Main Window

    UM2220 Sample application Step 2. Launch the Unicleo-GUI application to open the main application window. If an STM32 Nucleo board with supported firmware is connected to the PC, it is automatically detected and the appropriate COM port is opened. Figure 5. Unicleo main window Step 3.
  • Page 17: Figure 7. Fusion Window

    UM2220 Sample application Step 4. Click on the Fusion icon in the vertical toolbar to open the dedicated 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 button. Figure 7.
  • Page 18: Figure 8. Magnetometer Scatter Plot (Properly Calibrated Magnetometer)

    UM2220 Sample application Step 5. Click on the Scatter Plot icon to check the magnetometer calibration quality. Figure 8. Magnetometer scatter plot (properly calibrated magnetometer) UM2220 - Rev 7 page 18/24...
  • Page 19: References

    Datalog window References All of the following resources are freely available on www.st.com. UM1859: Getting started with the X-CUBE-MEMS1 motion MEMS and environmental sensor software expansion for STM32Cube UM1724: STM32 Nucleo-64 board UM2128: Getting started with Unicleo-GUI for motion MEMS and environmental sensor software expansion...
  • Page 20: Revision History

    UM2220 Revision history Table 4. Document revision history Date Version Changes 12-May-2017 Initial release. Added references to NUCLEO-L152RE development board and Section 2.2.10 Algorithm 26-Jan-2018 performance. 20-Mar-2018 Updated Introduction, Section 2.1: "MotionFX overview" and Section 2.2.9: "Demo code". Updated Section 2.2.7 MotionFX APIs and Figure 3. MotionFX API logic sequence. Added Table 3.
  • Page 21: Table Of Contents

    Acronyms and abbreviations ............2 MotionFX middleware library in X-CUBE-MEMS1 software expansion for STM32Cube .
  • Page 22 UM2220 List of tables List of tables Table 1. List of acronyms ..............2 Table 2.
  • Page 23 UM2220 List of figures List of figures Figure 1. Example of sensor orientations ............5 Figure 2.
  • Page 24 ST’s terms and conditions of sale in place at the time of order acknowledgement. Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or the design of Purchasers’...

Table of Contents

Save PDF