Can anyone help on removing the g factor from accelerometer readings?
I am using SensorEventListener with onSensorChanged()
method for getting Sensor.TYPE_ACCELEROMETER data. I need only pure acceleration values in all directions. So at any state if the device is stable (or in constant speed), it should give (0.0,0.0,0.0) roughly.
Currently, depending on its pitch and roll, it gives me variable output depending on the g forces acting on each axis.
I hope there is some formula to remove this, as I also get orientation values (pitch and roll) from Sensor.TYPE_ORIENTATION listener. I have used some but it didn't work.
You can use a low-pass filter.
Do this for each of your sensor values:
g = 0.9 * g + 0.1 * v
Where v
is your current sensor value and g
is a global variable initially set to zero. Mind that you'll need as many g variables as you have axes.
With v = v - g
you can eliminate the gravity factor from your sensor value.