I am developing application for car acceleration tracking. I used standard accelerometer, calibrating it in specific position beforehand.
Then, assuming phone's orientation is not changing, I logged the accelerometer data for a specified time and calculated move parameters, one of which is the car's speed at the end of the test.
It works rather well, on a straight, horizontal road: error of a few percent.
But then I found out, that in API-level 10 there is a virtual sensor called TYPE_LINEAR_ACCELERATION
and, as far as I understand, it must do what I need: filter gravity, orientation changes - so I may use it and get pure linear acceleration of mobile device.
BUT in real life..
I made a simple application, that does a little test:
//public class Accelerometer implements SensorEventListener { ...
public void onSensorChanged(SensorEvent se)
{
if(!active)
return;
lastX = se.values[SensorManager.DATA_X];
lastY = se.values[SensorManager.DATA_Y];
lastZ = se.values[SensorManager.DATA_Z];
long now = System.currentTimeMillis();
interval = now - lastEvetn;
lastEvetn = now;
out.write(Float.toString(lastX) + ";" +
Float.toString(lastY) + ";" +
Float.toString(lastZ) + ";" +
Long.toString(interval) + "
");
}
I bind a listener with the following parameters:
mSensorManager.registerListener(linAcc,
mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
SensorManager.SENSOR_DELAY_GAME);
It works OK, but when I analyzed data dump, calculating speed like V = V0 + AT
, where V0 = 0
at first, then - speed of interval before this, A = acceleration (SQRT (x*x+y*y+z*z))
(t = time of interval), eventually I get a very low speed - three times less than real speed.
Changing Sensor type to TYPE_ACCELEROMETER
, calibrating and using same formula to calculate speed - I get good results, much closer to reality.
So, the question is:
What does Sensor.TYPE_LINEAR_ACCELERATION
really show?
Where am I wrong, or is something wrong with Sensor.TYPE_LINEAR_ACCELERATION
implementation?
I used Samsung Nexus S phone.
Question&Answers:
os