title: Android TYPE_LINEAR_ACCELERATION sensor - what does it show?
body: <p>I am developing application for car acceleration tracking. I used standard accelerometer, calibrating it in specific position beforehand.</p>
  
  <p>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.</p>
  
  <p>It works rather well, on a straight, horizontal road: error of a few percent.</p>
  
  <p>But then I found out, that in API-level 10 there is a virtual sensor called <code>TYPE_LINEAR_ACCELERATION</code> 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.</p>
  
  <p>BUT in real life..</p>
  
  <p>I made a simple application, that does a little test:</p>
  
  <pre><code>//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) + "\n");
  }
  </code></pre>
  
  <p>I bind a listener with the following parameters:</p>
  
  <pre><code>  mSensorManager.registerListener(linAcc,
                  mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION),
                  SensorManager.SENSOR_DELAY_GAME);
  </code></pre>
  
  <p>It works OK, but when I analyzed data dump, calculating speed like <code>V = V0 + AT</code>, where <code>V0 = 0</code> at first, then - speed of interval before this, <code>A = acceleration (SQRT (x*x+y*y+z*z))</code> (t = time of interval), eventually I get a very low speed - three times less than real speed.</p>
  
  <p>Changing Sensor type to <code>TYPE_ACCELEROMETER</code>, calibrating and using same formula to calculate speed - I get good results, much closer to reality.</p>
  
  <p>So, the question is: </p>
  
  <p>What does <code>Sensor.TYPE_LINEAR_ACCELERATION</code> really show?</p>
  
  <p>Where am I wrong, or is something wrong with <code>Sensor.TYPE_LINEAR_ACCELERATION</code> implementation?</p>
  
  <p>I used Samsung Nexus S phone.</p>