Search code examples
c++accelerometerandroid-sensors

Android sensor data displacement


I have sensor data that I've calculated from an Android phone. I take and perform transformations using a matrix on the xyz coordinates. I then take the acceleration that I got from the phone to find the velocity and displacement. Here is my code to find displacement and velocity. It is always the be the corresponding previous value:

 velocity[e]   = (accel[e-3]) * (time[i]-time[i-1])+velocity[e-3];

 velocity[e+1] = (accel[e-2]) * (time[i]-time[i-1]) +velocity[e-2];

 velocity[e+2] = (accel[e-1]) * (time[i]-time[i-1])+ velocity[e-1];



      displacement[e] = (velocity[e-3])*(time[i]-time[i-1])+.5*(accel[e-3])*pow((time[i]-time[i-1]),2) + displacement[e-3];
      displacement[e+1] = (velocity[e-2])*(time[i]-time[i-1])+.5*(accel[e-2])*pow((time[i]-time[i-1]),2) + displacement[e-2];
      displacement[e+2] = (velocity[e-1])*(time[i]-time[i-1])+.5*(accel[e-1])*pow((time[i]-time[i-1]),2) + displacement[e-1];

However i am getting getting numbers like -3436.0 19206.2 11373.5 for the displacement which should not be nearly that high. I even made a test file to test my formula and everything was right in terms of the numbers I got. However, it doesn't work the same with real data. Also, I read something about removing the mean from the acceleration, velocity, and displacement but don't quite understand that so can someone explain a solution please to getting the right numbers?


Solution

  • It won't work, these sensors are not accurate enough to calculate the position.

    It's amazing how many times this question comes up.