How to use accelaration data of moving object to calculate distance?

I read couple of similar question on this forum and few blogs on web, though I am still confused,I am determined to calculate object displacement using accelerometer data.

So, I tried using www.freescale.com/files/sensors/doc/app_note/AN3397.pdf , which gives nearly 20-50% error.

I also tried this equation on data and got some better results.

V1 = V0 + ((a1) * t)
X2 = abs((V1 * t) + (((a1)/2)*t*t))
X2 = X0 + X2
V0 = V1
X0 = X2


Here t is the time differance between two samples. X0 is the final displacement. V1,a1 current values. V0 previous value.

Here is my graphs for the movement from Android sensors readings.

1)From Linear Acceleration Z axis graph, how do I calculate the distance? 2)Which values should I take and which should not? how many data samples I should use for calculation. For positive acceleration only or for an entire positive negative cycle of acceleration data? 3) What the Linear acceleration graph means. Please explain its values based on movement of object.

1 Answer

You can't calculate the displacement like this. The application note clearly says " When implementing positioning in 3 axes, extra processing is required to null the earth's gravity effect.", and that's the understatement of the month!

Nulling gravity is an enormous problem, unless your accelerometer is perfectly perpendicular to Earth's gravity vector! The accelerations you want to measure are probably on the order of $1m/s^2$ or less, right? That is overlaid by $\vec{g}=9.81m/s^2\vec{z}$. Before you can even estimate the displacement causing acceleration your are interested in, you have to determine angles of your three accelerometer channels relative to $\vec{g}$, then subtract $\vec{g}$. Thankfully that procedure will give you a direction towards the floor... however, you still don't know which way your $\vec{x}$ and $\vec{y}$ axes are pointing! Your accelerometer could be turning around 180 degrees while it is accelerating... and the real displacement could end up in the opposite direction of where you thought it was going. Now, a perfect acceleration sensor would not even be sensitive to this rotation, for that you would need a different sensor that can detect rotations! Such a gyroscope may, or may not be built into your device. Given the way most accelerometer chips are implemented, gyroscopes and accelerometers will not even sample synchronously, which means that you need to have a digital resampling filter in place to correlate the readings of both sensors to get a reliable six axis position/orientation vector. I don't think that the Android platform gives you enough information to do that, right now. iOS might... on newer phones and tablets which have both sensors.

Having said that, if you want to simplify things to the level you are on, right now, you can (theoretically) mount your cell phone on a straight rail, carefully rotate it, until the motion vector points exactly in the direction of one of the accelerometer axes, and that axis is perpendicular to $\vec{g}$ and then you can apply a good numerical integration algorithm to what it measures on one axis, like one of the higher order integrators described by http://mathworld.wolfram.com/NumericalIntegration.html.

I suppose that was your original question, right? I apologize for ruining your day with the description of the real problem, and I promise not to bore you with other goodies like calibration of offsets, gain drift, crosstalk (misaligned axes) and non-linearities.

• +1 for ruining OPs day. This describes (some of) the 99% perspiration that needs to be added to 1% inspiration in order to get to real solutions. I don't think higher order integration needs to come into this until the simpler issues of orientation, offset and gain have been solved. Note that the sensor data (see link in question) did include gyro information... – Floris Sep 12 '14 at 13:53
• @Floris: You are absolutely right. Just like the OP, I tried the naive approach on my phone... and within 10 minutes I was knee deep in the question of how to sense the orientation of my accelerometer without useful gyroscope data. There is, of course, an enormous difference between a real inertial navigation system and the sensors of smartphones: in the real deal the gyroscope is not just an electronic sensor but a rotating element, which keeps a constant direction in space. The accelerometers are inside the gyroscope, so the compensation of rotation is not even necessary to first order! – CuriousOne Sep 12 '14 at 17:10
• @CuriousOne : Thanks for the response. There are a lot of things from your answer that I couldn't fully understand. where x⃗ and y⃗ axes are pointing? -> I have accelerometer and gyro which shows me down direction. I have megnetometer i.e. compass wich shows me north.(Both with very little precision as you mentioned.) There must be a way to calculate device's X,Y and Z axis from this data. Right? – Sunil Shahu Sep 15 '14 at 11:23
• @Sunil: In my answer I was choosing the z-axis in the direction of gravity, and x and y perpendicular to that. Gravity does not define the directions of the remaining two directions, which is why we needs e.g. a compass (which is also part of many devices, it's just not very reliable). Yes, one can calculate these directions... with very little precision, as you said. Whether the results will be "good enough", depends on your purpose. Using the camera and a suitable pattern will probably give much better results for displacement measurements (if you can point it at a test pattern, that is). – CuriousOne Sep 15 '14 at 16:43