I’m having some trouble with orientation calculation, it’s easiest explained by looking at the video below. I’m using a gy-80, so the accelerometer is an L3G4200D and gyro is a ADXL345. It seems to track movements pretty well, until it’s tilted over + or - 90 degrees, at which point the opposite direction flips 180 degrees (so if Pitch is over 90 then roll flips 180).

The trouble seems to be the accelerometer values, is it possible? I’m calculating pitch and roll as follows, as from Lazurus’s guide - also using his kalman filter:

```
accPitch = (atan2(accValX,accValZ)+PI)*RAD_TO_DEG;
accRoll = (atan2(accValY,accValZ)+PI)*RAD_TO_DEG;
if (accPitch <= 360 & accPitch >= 180){
accPitch = accPitch - 360;
}
if (accRoll <= 360 & accRoll >= 180){
accRoll = accRoll - 360;
}
```

Thanks