cancel
Showing results for 
Search instead for 
Did you mean: 

How does the X-CUBE-MEMS1 Motion MC library know the difference between an LSM9DS1 and an LSM6DSO?

Rstua.1
Senior

Deep in the STMicro Compass example in the STMicro's X-CUBE-MEMS1 code-package there is a call made to the STMicro Motion MC library to calibrate the LSM6DSO magnetometer. The STMicro compass code passes both the magnetometer values and the accelerometer values to the STMicro MC library. In return the library provides compensation values to be used on the magnetometer values. These compensated values are then passed to the Motion EC library. But before they are passed, the comments say that the X, Y & Z magnetometer axes values need to be changed to East-North-Up. Which appears to be simply switching the X and Y axis.

All that is fine and good. But I am using the LSM9DS1, not the LSM6DSO. The difference? Well the Y magnetometer axis is flipped! So, naturally I decided to "un-flip" the LSM9DS1's Y axis by multiplying it with -1. That did not work. The Motion MC library was never able to calculate working compensation values! Therefore the compass never worked!

What eventually work? Well, I found that if I gave STMicro's Motion MC library the un-flipped Y magnetometer value, -then- flipped the compensated Y magnetometer value before giving it to the STMicro's Motion EC library, the compass would work as expected.

But how?

How could the STMicro's Motion MC library properly calibrate the LSM9DS1 magnetometer values when the Y value on the LSM9DS1's magnetometer is backwards with respect to the Y value on the LSM6DSO???

Is there something in the STMicro's Motion MC library that knows what chip is being used??

Further, why does the compensated Y magnetometer value need to be flipped before giving it to the STMicro's EC library?? The question begging for an answer is - if the STMicro MC library knows what magnetometer chip is being used, then why is the STMicro EC library in need of "external corrections"??

-thanks

2 REPLIES 2
Miroslav BATEK
ST Employee

Hello,

all libraries are sensor agnostic, so they don't need to know and also they don't know which sensor part is used. But some of the libraries need to know sensor orientation usually with reference to device frame. Some libraries work with specific sensor orientation (e.g. ENU ... X = East, Y ... North, Z ... Up).

In you particular case the MotionMC don't need to know the orientation so you can pass the data without any modification.

But MotionEC works with the ENU system, so accelerometer and magnetometer data needs to be transformed into this system to get correct output.

Rstua.1
Senior

Thank you for your response @Miroslav BATEK​. What you say makes much sense and clears how the libraries works for me. I still have one question. I was not able to get the STMicro Motion MC library to calibrate when I flipped the magnetometer's Y value (multiplied it with -1) of the LSM9DS1. I say "not calibrate" as I was looking at the Unicleo-GUI Scatter Plot and saw 3 distinctive balls which never merged into 1 ball.

-thanks