Pages: [1]   Go Down
Author Topic: Deriving speed and distance from acceleration  (Read 1918 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
I Love YaBB 2!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?


« Last Edit: January 30, 2009, 06:19:13 am by cmegens » Logged

0
Offline Offline
God Member
*****
Karma: 1
Posts: 513
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  
« Last Edit: January 30, 2009, 07:14:09 am by dcb » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
I Love YaBB 2!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

0
Offline Offline
God Member
*****
Karma: 1
Posts: 513
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

absolutely smiley

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)
« Last Edit: January 30, 2009, 07:17:16 am by dcb » Logged

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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).

-j

Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 223
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

6G is 58.8m/s^2 (6x9.smiley-cool, 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.

-Z-
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 24
I Love YaBB 2!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

0
Offline Offline
Faraday Member
**
Karma: 8
Posts: 2526
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
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.

-j

Logged

Pages: [1]   Go Up
Jump to: