Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Tracking Distance on one Axis with an Accelerometer

  1. Jun 27, 2012 #1
    I need to track Distance on one Axis with an Accelerometer for a rocket project (i know there are bettor ways t do this but i am dead set on this one) I was thinking as follows,

    Code (Text):

    Read Accelerometer
    Accelerometer*Δt=Δv
    Current speed+Δv=New speed
    distance+New speed*Δt=New distance
     
     
  2. jcsd
  3. Jun 27, 2012 #2
    distance+New speed*Δt=New distance

    Isn't "New speed" the speed only at the end of the interval "delta t", not for the whole duration of delta t?
     
  4. Jun 27, 2012 #3
    This function is repeated many times so that is the speed that is dirived from the inatil meshurment and the Δt is the time since the last meshurment so were assuming that your travling at a constant speed for the time it takes to exicute the pice of code
     
  5. Jun 27, 2012 #4

    A.T.

    User Avatar
    Science Advisor
    Gold Member

    Yes. It will still work, but is inaccurate. A better simple method is averaging accelerations and velocities at the ends of the interval:

    PHP:

    velocityX[0] = 0 // we assume the device was static when we started recording acc
    positionX[0] = 0

    for every sample i > 0:
        dt = time[i-1] - time[i] // if sampling rate is constant simply use 1 / frequency here
        velocityX[i] = velocityX[i-1] + (accX[i] + accX[i-1]) / (2 * dt)  
        positionX[i] = positionX[i-1] + (velocityX[i] + velocityX[i-1]) / (2 * dt)  
     
    Better is:
    http://doswa.com/2009/01/02/fourth-order-runge-kutta-numerical-integration.html
     
  6. Jun 27, 2012 #5
    Thank you I was hesitant about posting code because I dident know how many people wold be able to interpret it
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook