How to remove Gravity factor from Accelerometer re

2019-02-04 11:50发布

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.

7条回答
Melony?
2楼-- · 2019-02-04 12:17

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.

查看更多
祖国的老花朵
3楼-- · 2019-02-04 12:23

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.

查看更多
做自己的国王
4楼-- · 2019-02-04 12:25

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.

查看更多
小情绪 Triste *
5楼-- · 2019-02-04 12:31

Use Sensor.TYPE_LINEAR_ACCELERATION instead of Sensor.TYPE_ACCELEROMETER

查看更多
地球回转人心会变
6楼-- · 2019-02-04 12:34

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.

查看更多
登录 后发表回答