Callibration is done by taking the sensor and measuring the outputs with the sensor perfectly level. Then tip it on its side and it will measure G 9.81m/s/s. That will be a reference. A robot might accelerate at 1/10 of this.
You need to sample the acceleration value frequently and at least many times a second. Also, the movement needs to be very smooth - any bumps or jerks are going to upset the readings unless you are sampling very fast and can take them into account.
Say the robot starts at rest and starts moving and you sample a reading 1/20 of a second later and read a value that you know is 1 m/s/s, ie about 1/10 of G.
As BeanieBots says, v=u+at, so velocity at this point will be 0+1x0.05=0.05 m/s. Distance = velocity x time, so the distance travelled = 0.05 x 0.05 = 0.0025 metres.
Now lets say we wind up the power to the motors. The 'a' value rises. We measure again 1/20 of a second later and get a reading of 2 m/s/s. v=u+at and u is the initial speed. v=0.05+2*0.05=0.15 m/s. The distance we travel in this time sample is 0.15*0.05=0.0075m. Add this to the distance from the first sample to find the distance from the starting point.
If we decide to coast at a constant speed v=u+at, a will be zero so v=u, ie the speed doesn't change. The distance values keep adding up at a constant rate.
If we slow down then a will be negative, ie v=u-at, and the speed will decrese. If we are slowing down because we are driving the motors backwards, eventually the speed will go under zero, and then the distance values are subtracted rather than added, ie we are now moving back towards the starting point.
You will have to do the calculations in both the x and y direction, and then use pythagoras to work out the direct distance. Also the calculations are not going to work if there are any slopes. There is a lot of floating point maths involved, and on a picaxe cunning tricks are needed like multiplying by 100, doing the maths and dividing by 100, and making sure there are no overflows.
It is also really easy to make silly mistakes with this sort of maths and end up with values 10x or 100x what they should be. Apologies in advance if I've made one of these errors.
The big unknown is how quickly will errors accumulate and it probably will only be a few seconds. But with other sensors it is possible to correct these errors - eg magnetometers, angular gyros, GPS and sonar. It is possible to do all this in real time and in 3 dimensions - check out <A href='http://autopilot.sourceforge.net/faq.html' Target=_Blank>External Web Link</a>. But probably years of work!
Edited by - Dr_Acula on 03/05/2007 01:29:08