AnsweredAssumed Answered

Tilt compensation compass on LSM9DS1

Question asked by Mark Williams on Nov 23, 2017
Latest reply on Nov 23, 2017 by Mark Williams

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;

Outcomes