cancel
Showing results for 
Search instead for 
Did you mean: 

MEMS ACCELEROMETER LSM6DSV16X Remove Gravity

FilipeLourenço
Associate II

I am using steval mkbox-pro with FP-SNS-DATALOG2 to get acceleration from the subway train.

How can i remove the gravity effect in measurements from the LSM6DSV16X accelerometer?

 

5 REPLIES 5
Andrea VITALI
ST Employee

The simple but inaccurate way is to apply an high-pass filter which removes the DC component (the mean value), usually associated with gravity. This works very well if motion is high frequency. Less well if motion is low frequency and near DC.

High-pass filtering can be achieved by subtracting the output of a low-pass filter, a moving average would work fine. Moving average is the mean of the samples in a sliding window. It can be efficiently implemented with constant complexity independent of the window length - see attached implementation example - a circular buffer is maintained and output is updated by just subtracting the sample going out of the window and adding the new sample entering the window.

The more complex but very accurate way is to use sensor fusion and subtract the estimated gravity vector. Check the MotionFX library in the X-Cube-MEMS software package.

Hello @Andrea VITALI,

Thanks!

Is it possible to have both X-Cube-MEMS software package and en.fp-sns-datalog2 in the same Steval Mkbox pro?

Oher questions:

Is it possible to use the magnetometer to get the orientation of the sensor? (to remove the gravity contribution on the  acelerometer)

I am also doing sound acquisition using the mic MP23DB01HP, but it gives me only waveform... What are the units? Or how can i get it in known sound measurement units?

Thanks!

Modifying a Function Pack such as FP-SNS-DATALOG2 is very complex and would require a significant effort to integrate MotionFX and customize as needed.

An easier and faster way to prototype a system with sensor fusion (MotionFX) and logging capabilities (to SD card and/or BLE transmission) would be to use the AlgoBuilder tool in MEMS Studio: it is a low/no-code GUI to create FW for ST platforms.  Like power-point: drag and drop blocks and connected them as needed. The GUI will generate the code and the project, compile, and flash the device (of course you need the STM32CubeIDE toolchain installed to be able to compile, and STM32CubeProg installed to be able to flash the device). 

In AlgoBuilder create a new design. Select SensorTile.Box PRO as you platform if you plan to use USB connection to display in real-time the data, otherwise select SensorTile.Box PRO BLE if you plan to connect via BLE. In the project you need to drag and drop the "gravity vector" block of MotionFX 6X (acc+gyro fusion) or MotionFX 9X (acc+gyro+mag fusion), the latter is the most accurate for your application. Then you need to drag and drop the SD card block to save the output to the SD card. And you can also add some display/plot block to display in real-time (using MEMS Studio connected over USB or BLE). See attached screenshots. It should take less than one hour to get this up and running.

AlgoBuilder offers the possibility to add "custom blocks" to run custom code. Anyway, the generated code is very well structured and easy to understand: the main.c will run sensor_ab.c which is the actual main loop of the FW, start there if you want to see how it is done.

About your other questions: a small writeup is necessary. Short answer: no the mag is not necessary. The acc is necessary always. The gyro is also necessary if you want to handle high dynamic conditions where accel measure gravity+linear acceleration.

The gravity vector is computed given the orientation of the device. The orientation is represented as quaternion (axis/angle) or as Euler angles (roll, pitch, yaw). Roll and pitch require an accelerometer. Yaw or heading require a magnetometer - see Design tip DT0058 for more details. This is a simple 6X (acc+mag) fusion implemented in MotionEC (e-Compass). Problem with this is that if there high dynamic motion the accelerometer would not measure the gravity but gravity+linear acceleration. For this reason the gyro is utilized to update the estimated orientation when accel or mag cannot be trusted, see DT0060 for details. This is the 9X (acc+gyro+mag) fusion. The other 6X fusion mentioned above (acc+gyro) gives up the mag and will give you accurate relative yaw not absolute yaw, because it has no sensor to measure the magnetic north.

If you want the gravity vector in static conditions MotionEC is sufficient (this case is easy: accel will output the gravity). If you want the gravity vector in high dynamic conditions MotionFX is needed (6X or 9X, both of them will tell you the correct gravity vector, but only 9X will tell you the absolute yaw/heading angle). You may also want to check Design Tip DT0106 about gravity subtraction and dead reckoning.

About your last question on the digital microphone MP23DB01HP: the output is a pulse-density-modulation stream (PDM), a stream of 0s and 1s at 0.5-3MHz depending on the mode, low-power or high-performance. The average over a certain interval (20.8us if you want 48kHz samples) is the sound level, this PDM-to-PCM conversion is done by a dedicated peripheral on the STM32 microcontoller or by FW. The maximum saturation value is reached at 120 or 135dBSPL as specified in the datasheet. The stream of PCM samples represent the audio waveform.

 

 

Thanks @Andrea VITALI !

With this sollution i can still have the FP-SNS-DATALOG2 flashed in the device right?

I am installing STM32CubeIDE and  MEMS Studio. But everytime i try to open the MEMS Studio it stays with a white window and nothing happens(the app does not answer), Am i doing something wrong?

If you want to keep 2 binaries in the same device, you should change both projects so that they map to different memory banks and then write a small bootloader that runs one or the other depending on some condition. There is an example on how to do this in FP-SNS-STBOX1 (BLEDualProgram where one binary is kept and run in one bank, while the new binary is downloaded and stored in the other bank, then at the reboot the new binary is run - hence the name FOTA firmware over-the-air update).

MEMS Studio installation: Windows, Linux, or MacOS version?