3d Accelerometer calculate the orientation

后端 未结 5 2013
执念已碎
执念已碎 2020-12-04 12:45

I have accelerometer values for the 3 axes (usually when there is only gravity contains data between -1.0 and 1.0 ):

  float Rx;
  float Ry;
  float Rz;
         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 13:15

    I've tried the recommended solution (matteo's), and while it seemed to work great at first, I noticed that when the pitch approaches 90 degrees (starting at around 70 degrees but not necessarily consistent across different phones), the roll suddenly surges. When the pitch is at 90 the roll that should be around 0 is now at over 100 and keeps increasing to 180. I'm trying to think of a way to mathematically prevent this, if I restrict the roll to +90/-90 it behaves normally but I don't get the range I want (+180/-180): Math.atan2(y, Math.sqrt((xx) + (zz))) * (180/Math.PI))

提交回复
热议问题