# Accelerometer help

Hey, my programming team (by which I mean my programming team–) wants to use an accelerometer for determining speed of the robot during autonomous mode and to determine if we’ve crashed, but the problem is I’m not sure how to handle the accelerometer in the code. I know the physics of it: Final Velocity=Initial Velocity+Acceleration*Time I don’t know what the accelerometer returns and…that’s about it. Could someone enlighten me. Thanks.

You’re more than half way there.

Since you understand the physics, you just need to translate that into program code. Using an interrupt-based timer will give you a good stable time interval.

To get acceleration, you simply need to read an ADC channel. That will give you a 10-bit representation of the voltage coming out of the accelerometer. Then, this number needs to be shifted and scaled to translate that 10-bit number into an acceleration.

Next, you need to view the velocity problem as the integration of acceleration. The physics you mention are a good approximation, and may work for the 15 seconds of autonomous/hybrid. Essentially, you need to have some variable in your program (probably a long) to accumulate the a-t product. That means to add the acceleration at each interval to the previous sum to get the velocity. If you want a more accurate result, there are many options. Read up on “numerical integration” in a calculus or signal processing book.

There are some caveats, though.

First, stick to the integer (and related) data types. Resist the temptation to go to floating point to track the velocity, as floating point math is very inefficient on the PIC.

Second, if you turn, it will not be easy to translate the data after the turn to the data before the turn. Here, you would need a gyro to tell you the angle relative to your start.

Third, the accelerometer can be sensitive to noise and vibration. You’ll probably need to build a filter to get rid of the noise, and you’ll have to mount it on foam or other dampening material to minimize vibration.

-JEE

The kit accelerometer returns a voltage proportional to acceleration.

It’s described on page 3 of the 2008 Sensors Manual

There is also a link there to the Product Webpage.

Bottom line: 2.5V output = no acceleration and it deviates from that at roughly 1000 mv/g.

I would not recommend using accelerometer if all you want is speed. Shaft encoders + the yaw-rate sensors will probably find you more success for autonomous navigation.

There are a large number of other threads on this exact topic. The search function is wonderful

Thanks guys.