calculating distances using accelerometer
Solution 1:
The short answer to your question is you can't do it.
The double integration method is really the only way to get the information you are looking for using only an accelerometer. You found the problem with this method. The error increases over time and generally doesn't give the accuracy many are looking for.
Kalman filtering usually requires 2 devices and basically takes the best of both devices and filters out the bad. See example below.
Kalman filtering is a really tough subject that I tried to dive into for senior design, but never found any meaningful results with my limited testing. A great place to start understanding this subject is with this youtube video series .
This is the guy that won the DARPA challenge with Stanford and explains the topic in an easy to understand way. The whole course is a 6 unit video series about programming robots to move and understand their location in an unknown environment. Worth a watch if you have the time and interest.
It sounds like you're trying to do something similar to what I did for senior design in give really specific relative location information.
Another great Kalman filtering read this (if this link doesn't work google Kalman filter balance bot and click the TKJ blog link). Basically this guy uses an accelerometer and gyroscope to track orientation in the real world.
Something else to look into wiki Real Time Kinematic. This goes on tractors and combines to provide really accurate location information. John Deere sells a system, but it's like $20,000. Here is the poor man's version using GPS and beagleboard
Solution 2:
By a 9-Axis sensor I am assuming that means:
- 3-axis gyro (measures rotational rate)
- 3-axis accelerometer (measures acceleration)
- 3-axis magnetometer (measures heading)
Getting a practical position estimate from this type of 9-axis sensor is not possible without the use of another sensor that uses an external reference such as GPS.
Theoretically, if you know the accelerations of an object in space and its initial position and velocity you will be able to calculate the objects new position by propagating the information about its acceleration and velocity back on to the initial position (i.e. integrating the acceleration twice). The reason that it is not possible in practice is that the accelerometer has noise. This noise will have a non-zero mean, so when integrating the acceleration signal the non-zero mean noise is continuously added and accumulates in the resulting velocity signal. This is seen as sensor drift. The velocity estimate starts out fairly correct but quickly drifts off due to this accumulated noise. Integrating a second time to get the position only worsens the situation by repeating the process.
By using an external reference such as a GPS, the Kalman filter can be used to combine the slow-updating GPS signal, and the fast-updating acceleration signal together to produce a reliable estimate of the position. The GPS has the effect of zeroing the drift that would be accumulated by performing the integration on the acceleration signal.
I would suggest taking a look at the Udacity Youtube videos that Khamey suggested. When learning the Kalman filter it helps to get a clear general overview of what the objective is and what the kalman filter is doing. Then the math and the actual steps of the algorithm will be much easier to understand. Another thing that is helpful when learning the Kalman filter is doing it for one state variable at a time instead of a whole state vector. This just helps focus your attention on what the Kalman filter is actually doing so that you don't get bogged down by the matrix algebra.
Solution 3:
Without considering the rotation:
Let's consider that at time t=t0
you are at position [ x0 , y0 , z0 ]
and a velocity vector of [ vx0 , vy0 , vz0 ]
.
At t=t1
you read an acceleration vector of [ ax1 , ay1 , az1 ]
(The average acceleration from t0
and t1
).
Then, the velocity vector at t=t1
will be:
[ vx1 , vy1 , vz1 ] = [ vx0 + ax1 * (t1 - t0) , vy0 + ay1 * (t1 - t0) , vz0 + az1 * (t1 - t0) ]
The average speed between t0
and t1
will be
[ vx01 , vy01 , vz01 ] = [ (vx0 + vx1) / 2 , (vy0 + vy1) / 2 , (vz0 + vz1) / 2 ]
And the position at t=t1
will be:
[ x1 , y1 , z1 ] = [x0 + vx01 * (t1 - t0), y0 + vy01 * (t1 - t0), y0 + vy01 * (t1 - t0) ]
As you can see, the error propagates with t^2
, so that's why the inertial systems need to be compensated by an external reference like a GPS.