Go Down

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

cmegens

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?



dcb

#1
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:

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

All scaled to whatever units you like.  

cmegens

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

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

dcb

#3
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)

halley


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.

Go Up