Search code examples
androidaccelerometercalibration

Trying to calibrate accelerometer


I am writing an app that will use the accelerometer to calculate the average geforce exerted on the phone. Thinking about the problem, I came to the conclusion that when the phone is in rest, adding all of the axis values together will give me an answer of +9.8 (acceleration due to gravity).

I now assumed that if I subtract 9.8 from the sum of all axes, it will give me the combined force being exerted on the phone without taking gravity into account. So if the phone was to be in a fixed position it would return the value 0.

Now this does work out to be true if the phone is lying directly on one axis, but if the phone were to lie against something at a ~45 degree angle, it returns a value of 4-5 (roughly half that of gravity) the closer the angle gets to an axis, the smaller the registered force is (going to go ahead and assume that it is proportional)

From my understanding, this shouldn't happen, it should return a 0 as all of the axis would cancel each other out, no? as the phone is stationary there should be no force recorded with the phone right?


Solution

  • A value of 4-5 m/s2 indicates either a little bug in your calculation or a hardware defect. You said that you are adding all values, but how do you do it? You have to calculate the magnitude as sqrt(x*x + y*y + z*z). This is because acceleration like velocity, position, ... are vectors and their length is calculated according to the Pythagorean theorem.

    In general these sensors are not that exact as you might expect. On iPhone I measured g-force values between 9.75 and 9.87. Values depend on temperature (put it in the fridge and you get lower values - I checked it ;-) and there are indeed differences when changing the orientation. I found value deltas of 0.3 m/s2. In order to get this fixed you will need heavy maths (Kalman-Filter or similar stuff) and of course a second sensor (gyroscope because magnetometer i.e. compass reacts too slow).