Sei sulla pagina 1di 5

Accelerometer to pitch and roll

This tutorial describes how an accelerometer can be used to determine an aircrafts attitude (pitch and roll). An accelerometer measures, as its name hints, acceleration along a predefined axis. As you probably remember from you physics class, the earths gravity is also an acceleration (a falling stone keeps going faster and faster). So: with an accelerometer, we can measure the earths gravity! This image shows how we do it:

The red arrow represents the earths gravity. The blue arrow shows how the accelerometer senses gravity. Note that the axis of this accelerometer is perpendicular to the aircraft (we placed it like that in our aircraft!). The angle theta between the actual gravity vector and the measured gravity is related to the pitch of the aircraft (pitch = theta + 90). If we know theta, we know our pitch! Since we know the magnitude of the earths gravity, simple calculus gives us our pitch angle: accelerometer = cos (theta) * gravity theta = acos (accelerometer / gravity) And since pitch = theta + 90 pitch = asin (accelerometer / gravity)

We calculated the pitch orientation of our airplane using an accelerometer. Pretty easy, huh? Calculating the roll angle is pretty much the same. We only need an extra accelerometer with an axis perpendicular to the pitch-accelerometer. Reality is a bit different from this simplified example. The inverse sinus cant give you the full 360 degrees ranging pitch angle. A plane heading for the sky and one heading for the ground would both result in a 0 (zero) measurement. Well need an extra accelerometer to distinguish these cases. The 2-argument inverse tangents make sure the resulting angle is in the correct quadrant. Thus: pitch = atan2(accelerometer / gravity, z / gravity) Now you know most about using accelerometers to calculate pitch and roll, dont start building your own autopilot system just yet! There are more forces working on a flying airplane then just good old gravity! Just think about the centripetal force when following a circle path. Well need gyroscopes to correct this over short period of time (also useful to eliminate the effect of vibrations on the accelerometer). Over a longer period of time, well need some more advanced physics to estimate these other forces so we can compensate for them. Ill write later about the different approaches you can use to do this.

Gyroscope to roll, pitch and yaw


Now you know most practical things you need to know about accelerometers, well continue with gyroscopes (other names: gyro, angular rate sensor). A gyroscope is a very fancy name for a device that measures the angular rate (how much degrees per second). The gyroscopes used in very critical applications (like a jumbo jet) are very advanced and complicated. Fortunately for us, there are some low-cost and small sized alternatives which are good enough. They are fabricated using MEMS (iMEMS) technology by big companies like Analog Devices. Great! Lets start with some theory: As you probably remember from you physics class, position, velocity and acceleration are related to each other: deriving the position, gives us velocity: dx=vx with x being the position on the x-axis and v x being the velocity along the x-axis. Maybe less obvious, the same holds for angles. While velocity is the speed at which the position is changing, angular rate is nothing more than the speed the angle is changing. Thats right: d alpha = angular rate = gyroscope output

with alpha being the angle. Its starting to look pretty good! Knowing that the inverse of deriving (d .) is integrating (), we change our formulas into: angular rate = gyroscope output = alpha We found a relation between angle (attitude!) and our gyroscopes output: integrating the gyroscope, gives us our attitude-angle. Enough boring theory! Lets take a look at some figures. The following figures all represent the same motion: I took a gyroscope, turned it 90 degrees left and back, and turned it 90 degrees right and back. The raw data (used here) is what we get when we feed the gyroscopes output (0-5 volt) into a 10-bit ADC (analog to digital convertor). So the raw values are between 0 and 1024. Heres a figure of that:

(The red line is just a low-pass filtered version of the blue data) You can clearly see a positive angular rate followed by a negative one. But well need to shift the figure down, to make sure negative values correspond to a negative angular rate. Otherwise the integration (which can be seen as the sum of our y-values) would keep adding up values and never subtracting any! We normalize it by subtracting about 490 from every value. This normalization gives us the following figure:

Now all we need to do, according to our formulas, is integrate it! Some of you may still have nightmares about college and start shivering when they hear the word integration, but its pretty simple. Discrete integration is nothing more than summing up all the values! Basically, integration from 0 to the ith value: integration(i) = integration (i-1) + vali This is the simplest possible integrator. A more advanced one, which also flattens out possible jitter in the data, is the runge-kutta integrator: integration(i) = integration(i-1) + 16 ( vali-3 + 2 vali-2 + 2 vali-1 + vali) Using this runge-kutta integration, we get the following figure:

This is pretty much the exact movement I made! Now we just need to add a scale factor to our data so our result is in degrees:

This pretty much ends my story of the simplified gyroscope! In reality, gyroscopes are suffering from an effect called drift. This means that over time, the value a gyroscope has when in steady position (called bias), drifts away from its initial steady value:

The blue line gives you an idea about the drift. During 4500 samples (12 seconds in my setup), the bias drifted about 30 degrees! Remember that we need the bias (about 490 in our example) to normalize our data. How can we integrate when we have no idea about the correct bias? Well need to find a way to get it. More about this is in the next article. A hint: our accelerometer isnt affected by drift ;-)

Potrebbero piacerti anche