cancel
Showing results for 
Search instead for 
Did you mean: 

Tilt compensation compass on LSM9DS1

Mark Williams
Associate II
Posted on November 23, 2017 at 13:07

Hi, we are upgrading our product from a LSM9DS0 to a LSM9DS1.

During testing, we are unable to get tilt compensation working with the compass on the LSM9DS1.

We have calibrated the compass.

When using the code below, this works perfectly on the LSM9DS0.

When using on the LSM9DS1, it doesn't compensate.

Is there a difference between the LSM9DS0 and LSM9DS1 which would break this? E.g. Accel and Mag are orientated differently?

//Normalize accelerometer raw values.
 accXnorm = accRawX/sqrt(accRawX * accRawX + accRawY * accRawY + accRawZ * accRawZ);
 accYnorm = accRawY/sqrt(accRawX * accRawX + accRawY * accRawY + accRawZ * accRawZ);
//Calculate pitch and roll
pitch = asin(accXnorm);
roll = -asin(accYnorm/cos(pitch));
//Calculate the new tilt compensated values
magXcomp = magRawX*cos(pitch)+magRawZ*sin(pitch);
magYcomp = magRawX*sin(roll)*sin(pitch)+magRawY*cos(roll)-magRawZ*sin(roll)*cos(pitch);

//Calculate heading
heading = 180*atan2(magYcomp,magXcomp)/M_PI;�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

#e-compasses #lsm9ds1 #imu #lsm9ds0
2 REPLIES 2
Miroslav BATEK
ST Employee
Posted on November 23, 2017 at 14:17

Yes, the orientation is different.

LSM9DS0

0690X00000608w2QAA.png

LSM9DS1

0690X00000608w7QAA.png

You also have to do at least hard iron calibration of the magnetometer.

Posted on November 23, 2017 at 15:02

Thanks for responding.

I have hard iron calibration applied to the LSM9DS1

I did look at that. The Pin 1 indicator is also in a different position in the images which makes it hard to work out what has changed.

I quickly put the image together below, showing the difference between LSM9DS0 and LSM9DS1.

My assumption is that when looking at the images from the documentation, the side where the letter is ( X,Y,Z) will give a positive value if rotated in that direction. And Z is flipped for the MAG.

0690X00000608wIQAQ.png