# Welcome

My virtual playground. Meer info

## Gyroscope to roll, pitch and yaw

Now you know most practical things you need to know about accelerometers, we’ll 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 it is rotating). 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.

As you probably remember from you physics class, position, velocity and acceleration are related to eachother: deriving the position, gives us velocity:

d x = v x

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. That’s right:

d alpha = angular rate = gyroscope output

with alpha being the angle. It’s starting to look pretty good! Knowing that the inverse of deriving (d .) is integrating (∫), we change our formula’s into:

angular rate = ∫ gyroscope output = alpha

Woohoo, we found a relation between angle (attitude!) and our gyroscope’s output: integrating the gyroscope, gives us our attitude-angle.

Enough boring theory! Let’s 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 gyroscope’s output (0-5 volt) into a 10-bit ADC (analog to digital convertor). So the raw values are between 0 and 1024. 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. 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 substracting any! We normalize it by substracting 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 i^th^ 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 it’s 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 currect bias? We’ll need to find a way to get it. More about this in the next article. A hint: our accelerometer isn’t affected by drift ;-)

## Accelerometer to pitch and roll

This tutorial descibes how an accelerometer can be used to determine an aircraft’s attitude (pitch and roll).

An accelerometer measures, as it’s 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 magnetude 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)

Woooow, 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 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 an extra accelerometer to distinguish these cases. The 2-argument inverse tangens makes sure the resulting angle is in the correct quandrant. Thus:

pitch = atan2(accelerometer / gravity, z / gravity)

Now you know most about using accelerometers to calculate pitch and roll, 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. We’ll need gyroscopes to correct this over short period of time (also usefull to eliminate the effect of vibrations on the accelerometer). Over a longer period of time, we’ll need some more advanced physics to estimate these other forces so we can compensate for them. I’ll write later about the different approaches you can use to do this.
The gyroscopes are covered in the next tutorial: gyroscope to roll, pitch and yaw

## What is an IMU

Every good autopilot system needs an IMU-module. IMU stands for Inertial Measurement Unit. Basically, you can look at it as a black box that gives information concerning your current position and orientation. Position could be GPS-coordinates. Orientation could be roll, pitch and yaw. Sometimes you need to calculate it yourself, sometimes the black box calculates it for you. Soooo, since an autopilot needs to know the current position and orientation, it needs an IMU.

 The 6DOF by SparkFun electronics. Notice the 2 gyroscopes standing in upright position. One for each axis!

Every interested mind now wonders “how does this black box work?”
Well, I’ll give you the three most importent sensors.
The first one is, of course the GPS. It gives you your current position and your speed.
The second one is a set of 3 accelerometers. Each one senses acceleration in one direction. Remember from your physics class that gravity is also an acceleration! So the 3 accelorometers give you the 3 components of the gravity vector! Knowing that the gravity vector is supposed to point right to the middle of the earth, you can calculate the orientation! Keep in mind that when an MAV is flying, other forces like centripetal acceleration may badly influence those 3 accelerometers used to sense the gravity vector. As a result those measurements are only correct when averaged over a longer period of time.
The last one is a set of 2 or 3 gyroscopes. Thats a very fancy word for a sensor that senses the speed of rotation (also called angular velocity). With 3 gyroscopes you can sense the speed of rotation around your 3 (x, y, z) axes. Clever readers may notice that the mathematical integration of the values give you the orientation (integration of speed = position)! Unfortunately, there is a lot of drift on those values, so they are only correct for a short period of time…

Readers who payed attention noticed that the orientation given by the accelerometers are correct over a long period of time, and the one given by the gyroscopes are correct over a short period of time. Can’t be combine those two?! Yes we can! A very special filter called the kalman filter does the trick.
Nowadays, every guided vehicle (from a guided missile to a jumbojet) uses those sensors with the kalman filter. Mr. Kalman who invented his filter in the fifties must be so proud!

5 May 2006, 14:24 | Link | Reacties

## Overview: autopilot modules

I tried to list the most interesting autopilot systems.

Name Company Remarks
Paparazzi / A DIY project
AFCSV2.5 Rotomotion For heli’s
MP2028^g^ MicroPilot 28gr incl. GPS!
Phoenix o-navi Not including software?
TGE C. C. & design
Piccolo Cloud Cap Tech
PicoPilot uNav Mostly hobbyist-oriented?

### MP2028^g^

MicroPilot is a company solely focused on miniature autopilot systems. They also offer various add-on modules.

### Phoenix

The o-navi company is specialized in navigation modules using MEMS sensors. Their top product is an integration of their IMU module in a full flight controller engine: the Phoenix

### Tiny Guidance Engine (TGE)

Continental Controls & Design is a small company with one product: a small autopilot system. This includes the IMU-module with microcontrollor and ground control software. Their main client is the US army.

### Piccolo

Cloud Cap Technology is a company with UAV-autopilot related modules as only interest. Their autopilot look very professional but big and heavy, compared to their IMU-modules.

### Parapazzi

This project aims to develop an autopilot under the GNU public license. While not that advanced (eg. stabilization is done using 4 thermophile sensors), it has proven to be very succesfull.

### Rotomotion

The roots of the rotomotion company lie in the autopilot project on sourceforge. Now, they sell a more advanced version of this project. As a plus, they also offer fully equiped UAV helicopters.

### PicoPilot

This company offers a very lightweight autopilot solution as a composition of various modules. It looks oriënted at the advanced RC-hobbyist.

5 May 2006, 13:46 | Link | Reacties [4]

## Overview: commercial IMU's

I tried to list the most interesting commercial available IMU-module. These can be interesting if you plan to develop your own autopilot(-software).

Name Company Size Weight Remarks
TrIMU Mavionics 40×40×14 15g
Atair INU Atair 38×50×19 45g
GyroCube o-navi 38×32×15 8,2g
uNAV Crossbow 57×45×26 33g Open source software
3DM-GX1 MicroStain 42×40×15 26g
TGE C. C. & design 30×30×18 13g Full autopilot?
Crista Sensor Cloud Cap Tech 28×29×15 8,5g
MP2028 MicroPilot 100×40×15 28g Full autopilot
6 DOF Sparkfun El. 51×51×23 21g With bluetooth link
MTi Xsens 58×58×22 50g RS232 & USB

I know this list is far from complete. Please contact me if you know other commercial available IMU’s.

5 May 2006, 12:41 | Link | Reacties [2]