2017-11-23 04:07 AM
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
2017-11-23 05:17 AM
Yes, the orientation is different.
LSM9DS0
LSM9DS1
You also have to do at least hard iron calibration of the magnetometer.
2017-11-23 07:02 AM
Thanks for responding.
I have hard iron calibration applied to the LSM9DS1I 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.