# Gyroscope Primer

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

## Introduction

A MEMS (microelectrical-mechanical system) gyroscope is a device that is used for measuring orientation. Accelerometers can perform a similar function when they are stationary by measuring the components on each axis of Earth's gravitational field. However, if the accelerometer is experiencing acceleration other than gravity it will not be able to distinguish and consequently will not be able to determine orientation. This is where gyroscopes become useful.

## How Gyroscopes Work

Gyroscopes contain small strips of metal that bend when the gyro twists and moves. By measuring the amount of bending the gryo can accurately report what angular velocity it is experiencing. Angular position is often what is desired however. In order to obtain angular position the angular velocity can be integrated over time. This procedure is shown in the C# example "Spatial-wireframe." Once integrated the data will be similar to the data from a 3 axis compass, it is important to note however that the gyro data will be with respect to an arbitrary 0 where as the compass is with respect to the Earth's magnetic field. This means that the gyroscope will more often than not give you different numbers than the compass. The only time this is not true is when the gyro is zeroed directly parallel with the Earth's surface and pointing to the North magnetic pole.

### Basic Use

In general gryoscopes must be calibrated, most are calibrated at the factory where they are manufactured though. Check the data sheets for the gyro you have to see if it requires manual calibration.

Once calibrated you are ready to start using the gyro. When you power it up you need to hold it as still as possible and then use the zero function or button to make the gyro ready to take accurate measurements.

Note that the gyro headings are the roll, pitch and yaw of the gyro with respect to the arbitrary zero point set at the beginning.

## Drift

Gyroscopes drift. It is unavoidable. Even extremely expensive, high end models will have significant drift. For example, a gyroscope rated to drift 0.114°/min, would, over the course of an hour of measurements, report values that are nearly 7° off what they should be. This is obviously quite substantial. In order to compensate for drift there are a few things you can do:

The best thing to do is zero the gyro on a regular basis. Zeroing the gyro will reset the drift back to nothing and you can begin again. The problem with this is that you can only zero the gyro when it is stationary. This means that you will need to stop movement for a period of time (it can take a few seconds to complete the operation) before continuing on with measurements.

The next thing that can be done is to continually correct for the drift. In order to do this the drift rate needs to be measured over as long a period of time as possible. Keep the gyro as stationary as possible and leave it overnight. Check the gyro reading in the morning and you know how much the gyro has drifted over the period of X hours. Now you can divide that down to determine the drift amount for each individual sample, and then in your program you can subtract the drift amount from each and every sample. The issue is that drift is not constant, averaging over a large period of time will help negate any instantaneous ill effects but individual samples still have a margin of error associated with the subtracted drift value.

In practice a combination of the 2 above strategies is the best. Continually subtracting drift from the measurements and zeroing whenever it is possible to do so.

## Noise

Noise is present in gyroscopes just like any other device however with gyroscopes noise is often not as important. Most typical uses of gyroscopes involve detecting large movements and as a result noise is easy to distinguish and ignore. Nevertheless noise can be a concern if it is too large. Noise levels will be different for each axis, because each orientation of sensor is build slightly differently and they are on different chips with different manufacturing procedures. Two of the major types of noise are white noise and random walk.

### White Noise

White noise is the short-term noise that is contributed to from a number of internal and external factors. For example, when a gyroscope is stationary on your desk, it might read 100°/s one sample, 101°/s another sample, and 97°/s in yet another sample. Luckily, white noise is usually fairly consistent which means it can be mitigated quite effectively if you average multiple samples together. With a Phidgets Inc. gyroscope, if you select a data rate slower than its maximum it will automatically average as many samples as it can within that time frame for each value. In applications where you need an extremely fast sampling rate, and can't afford to spend time averaging samples, you should look for a gyroscope with low white noise. Also keep in mind the noisiness of your environment- For example, the engine and road noise on a bus will easily be more noisy than the gyroscope - so there is no point in paying for a low noise device. See the Allan Deviation Primer for more information on spatial noise characteristics.

### Random Walk

Often called drift, random walk is the long-term noise that causes samples to gradually become further and further away from their true values. This type of noise is less important for applications with constant movement and a fast sampling rate, but for applications where values are averaged over longer periods of time, it can cause severe inaccuracies. See the Allan Deviation Primer for more information on accelerometer noise characteristics.