0

I want to calculate the distance from one point to another point, when I start capturing accelerometer data, and till I stop that, it should gather all samples and should give me distance based on velocity, roll, pitch, yaw and displacement.

I have tried following code based on this link1 and link2 for double integration.

 for (int i = 1; i < [arrXData count]; i++)
 {
     //========================================================================
     //Old Velocity
     double v0 = [[arrVelocity objectAtIndex:(i-1)] doubleValue];

     //Time Data
     double t0 = [[arrTimeData objectAtIndex:(i-1)] doubleValue];
     double t1 = [[arrTimeData objectAtIndex:(i)] doubleValue];

     //Acceleration Data
     double x0 = [[arrXData objectAtIndex:(i-1)] doubleValue];
     double x1 = [[arrXData objectAtIndex:(i)] doubleValue];

    //NewVelocity
    double v1 = v0 + (t1 - t0) * (x0 + x1)/2;
    //========================================================================

    //Old Distance
    double d0 = [[arrDistance objectAtIndex:(i-1)] doubleValue];

    //New Distance
    double d1 = d0 + (x1 - x0) * (v0 + v1)/2;
    //========================================================================
    //Store Distance & Velocity

    [arrVelocity addObject:[NSNumber numberWithDouble:v1]];
    [arrDistance addObject:[NSNumber numberWithDouble:d1]];
   //========================================================================
}

But the above code gives negative values sometimes, and not sure, whether this gives 100% correct result based on x acclearation values. Here we used x acceleration values after applying filter on it. We used high pass filter for reducing noise on x acceleration.

Does anyone know any algorithm on which we can rely?

Any help will be appreciated.

Community
  • 1
  • 1
Dipen
  • 268
  • 1
  • 14

0 Answers0