Accelerometer to pitch and roll

This tutorial describes how an accelerometer can be used to determine an aircraft’s 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 earth’s gravity is also an acceleration (a falling stone keeps going faster and faster). So: with an accelerometer, we can measure the earth’s gravity! This image shows how we do it:

The red arrow represents the earth’s 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 earth’s 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’ll need some more advanced physics to estimate these other forces so we can compensate for them. The 2-argument inverse tangents make sure the resulting angle is in the correct quadrant. we’ll continue with gyroscopes (other names: gyro. angular rate is nothing more than the speed the angle is changing. Great! Let’s start with some theory: As you probably remember from you physics class. Over a longer period of time. angular rate sensor). Pretty easy. They are fabricated using MEMS (iMEMS) technology by big companies like Analog Devices. there are some low-cost and small sized alternatives which are good enough. Gyroscope to roll. The inverse sinus can’t 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. We’ll need gyroscopes to correct this over short period of time (also useful to eliminate the effect of vibrations on the accelerometer). z / gravity) Now you know most about using accelerometers to calculate pitch and roll. We only need an extra accelerometer with an axis perpendicular to the pitch-accelerometer. I’ll write later about the different approaches you can use to do this. pitch and yaw Now you know most practical things you need to know about accelerometers.We calculated the pitch orientation of our airplane using an accelerometer. huh? Calculating the roll angle is pretty much the same. We’ll need an extra accelerometer to distinguish these cases. position. Maybe less obvious. Reality is a bit different from this simplified example. That’s right: d alpha = angular rate = gyroscope output . don’t 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. The gyroscopes used in very critical applications (like a jumbo jet) are very advanced and complicated. the same holds for angles. While velocity is the speed at which the position is changing. 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. Thus: pitch = atan2(accelerometer / gravity. A gyroscope is a very fancy name for a device that measures the angular rate (how much degrees per second). Fortunately for us.

The raw data (used here) is what we get when we feed the gyroscope’s output (0-5 volt) into a 10-bit ADC (analog to digital convertor).) is integrating (∫). we change our formula’s into: ∫ angular rate = ∫ gyroscope output = alpha We found a relation between angle (attitude!) and our gyroscope’s output: integrating the gyroscope. The following figures all represent the same motion: I took a gyroscope. Here’s 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. and turned it 90 degrees right and back. turned it 90 degrees left and back. This normalization gives us the following figure: . Enough boring theory! Let’s take a look at some figures. So the raw values are between 0 and 1024. It’s starting to look pretty good! Knowing that the inverse of deriving (d . But we’ll 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. gives us our attitude-angle.with alpha being the angle.

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

-) . This means that over time. More about this is in the next article. the value a gyroscope has when in steady position (called bias). During 4500 samples (12 seconds in my setup). gyroscopes are suffering from an effect called drift. the bias drifted about 30 degrees! Remember that we need the bias (about 490 in our example) to normalize our data. A hint: our accelerometer isn’t affected by drift .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. drifts away from its initial steady value: The blue line gives you an idea about the drift. How can we integrate when we have no idea about the correct bias? We’ll need to find a way to get it.

Sign up to vote on this title
UsefulNot useful