开发者

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

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 wor开发者_StackOverflowk.


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.


Use Sensor.TYPE_LINEAR_ACCELERATION instead of Sensor.TYPE_ACCELEROMETER


Take a look of the following link.

http://developer.android.com/reference/android/hardware/SensorEvent.html


Just subtract out g (~9.8m/s^2) times the z direction of the rotation matrix. Or to be more explicit about it, let

a = your accelerometer reading,
R = your rotation matrix (as a 9-long vector).

Then what you want is

(a[0]-g*R[6], a[1]-g*R[7], a[2]-g*R[8]).


Differentiating with respect to time a function of time rids you of the constants.

So by taking the derivative of the accelerometer's signal you'll get the "Jerk", which you can then re-integrate in order to get the non-constant part of the acceleration you're looking for.

In Layman's terms, take a sample from the accelerometer every 1 second, and subtract it from the previous sample. If the answer is (very close to) zero, you're not accelerating relatively to earth. If the result is non-zero, integrate it (in this case, multiply by one second), you have your acceleration.

Two things, though : -Look out for noise in the signal, round off your input. -Don't expect hyper-accurate results from on-chip accelerometers. You can use them to detect shaking, changes in orientation, but not really for knowing how many G's you're experiencing while making sharp turns in your car.


One way (for devices only with accelerometer) is to remove gravity vector from accelerometer data by subtracting the values that would come in static case for same orientation. But as orientation is again calculated by taking acceleration readings and not independently, its not very accurate.

Gyroscope may help in this case. But few androids still have a true gyroscope. And using its raw readings is not so simple.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜