Go Down

Topic: Deriving speed and distance from acceleration (Read 5351 times) previous topic - next topic


Jan 30, 2009, 12:18 pm Last Edit: Jan 30, 2009, 12:19 pm by cmegens Reason: 1
Just a small question.
I have an analog accelerometer connected to my arduino. Right now I am just measuring acceleration in 1 direction. If I understand right the accelerometer gives me the acceleration to a max of 6 G or 6 m/s2. Is it therefore possible to calculate the speed I am moving, instead of the acceleration? Is that just "time passed * acceleration" ? and is then "time passed2 * acceleration" the total distance traveled? Just wondering if I could create a speedometer like this?


Jan 30, 2009, 01:06 pm Last Edit: Jan 30, 2009, 01:14 pm by dcb Reason: 1
you can measure a change in speed, but it is all relative.  If you turn the unit on while moving at a constant 3 m/s , it will think it is zero m/s and read -3m/s at a stop.  And I would expect some drift also, as rounding and sampling errors creep in.

But it should be doable.  You will likely be in a loop that has to ignore  the first acceleration reading but note the time.  Then as it loops, it takes a new precise time reading and an acceleration reading and computes the change in speed:

[ch8710]t=t-previous t
[ch8710]speed = a * [ch8710]t
speed = speed + [ch8710]speed
goto top

All scaled to whatever units you like.  


So if I start in complete rest it will be even easier, no?

Thanks for your reply. Will try it and let you know.


Jan 30, 2009, 01:15 pm Last Edit: Jan 30, 2009, 01:17 pm by dcb Reason: 1
absolutely :)

Once you have determined the speed you can use the same basic algorythm to determine the change in distance over time (you already have the time computed)


dcb is correct.  Rephrasing the definitions and the code,

Acceleration is the change in velocity over time.  velocity += acceleration * delta_time;

Velocity is the change in position over time.  position += velocity * delta_time;

Mind your units... if you measure delta time in milliseconds, the velocity will be relative to milliseconds.  And as dcb did warn, you will have a LOT of issues with drift, inaccuracy, roundoffs and sensor noise.  You won't be able to dead-reckon your position on a loop race-track and expect the start and end banners to be in the same place every lap.


Also remember that acceleration and velocity are vectors - you'll need to allow for all three axes of acceleration to get accurate velocity and position.  With only one axis, you only get correct speed when you're going in a straight line (i.e. not around curves, or up and down hills).




6G is 58.8m/s^2 (6x9.8), not 6m/s^2.

Also, if you need to go up or down a hill, you need to know the angle of the hill, because gravity will introduce large amounts of drift otherwise.



Well I'm still confused a little bit....

Let's say we have ideal situation, where the moving object moves in 1 direction only, straight forward, without hills or whatever...

Then the speed would be acceleration times time? But how do I then calculate the current speed? Is that total acceleration differences divided by total time? Or is it measuring acceleration over a small amount of time (say 10ms) and then multiply those?


Then the speed would be acceleration times time?

plus the previous speed.

Vnew = Vold + acceleration * delta_time

where delta_time is the difference between the old sample and the new.

Likewise with the position,

Pnew = Pold + velocity * delta_time

This is an iterative process.  Start out at rest with the old velocity and position equal to zero.  Sample, calculate new velocity and position, old velocity and position are replaced with new velocity and position. do something with the data. Repeat forever.

delta_time is IMO the tricky part, as you'll want to sample fast to make the process more accurate, but that makes timing a bit more difficult as the time of the operations (sampling, calculations, output, etc) begin to dominate the time between samples.


Go Up