How to remove Gravity factor from Accelerometer readings in Android 3-axis accelerometer

后端 未结 7 1712
天命终不由人
天命终不由人 2020-12-29 08:16

Can anyone help on removing the g factor from accelerometer readings?

I am using SensorEventListener with onSensorChanged() method for getting Sensor.TY

7条回答
  •  执笔经年
    2020-12-29 08:49

    you need to assume two coordinate systems: 1- fixed global system. 2- moving coordinate system in which the origin moves & rotates as sensor does. in global system, g is always parallel to z axis but in moving system it is not. so all you have to do is to compute 3*3 rotation matrix from orientation angles or yaw, pitch & roll. (you can find formulas everywhere). then multiply this rotation matrix by 3*1 acceleration vector measured by sensor. this will transform coordinates and declare the values in fixed global system. the only thing afterward is to simply subtract g from z value.

提交回复
热议问题