Gyroscope Guide: Difference between revisions

From Phidgets Support
No edit summary
No edit summary
Line 1: Line 1:
<metadesc>Gyroscopes can measure the rotation of the object or vehicle that contains it, which is useful for navigation. Learn more at Phidgets.com.</metadesc>
[[Category:Primer]]
[[Category:Primer]]
==Introduction==
{{TOC limit|2}}
[[File:1042_0.jpg|link=|right|400px]]
==Gyroscopes and Their Uses==
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.
===Introduction===
<br clear="all">
[[File:Gyroscope_Intro.jpg|400px|link=|thumb|Gyroscopes Measure Rotation in 3 Axes]]
==How Gyroscopes Work==
In the context of sensors, gyroscopes are used to measure rotations. More specifically, they measure the rate at which the sensor is rotating, called angular velocity. At Phidgets, we represent this rotation in terms of degrees per second. By adding up, or integrating all the readings of angular velocity over time, you can track the angle of rotation from where the sensor started.
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===
===Considerations===
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.
Gyroscopes can only be used to track a change in angular position. Unlike magnetometers and accelerometers, there is no fixed frame of reference that can be measured by the gyroscope itself to determine a starting angle. To make sense of your gyro readings, you will need to start from a known frame of reference. This either means starting the sensor in a known, fixed orientation, or using an accelerometer and compass to get a more general sense of orientation before factoring in the gyroscope.


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.
===Drift===
All gyroscopes drift. Even the expensive ones. Of course, a good gyro will drift less than a cheaper one, but both will drift. Essentially, the readings from the gyro while it is at rest will change slightly over time. Since gyroscope readings are integrated to obtain meaningful results, even small drift can lead to large discrepancies in measured vs actual position over longer timescales. Either the sensor must be routinely reset or “zeroed” to compensate, or the sensor can be slowly corrected to a known frame of reference, such as one measured by a combination of accelerometer and compass 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.
===Temperature Effects===
One contributor to gyroscope drift is changes in temperature. If your Phidget incorporates temperature stabilization, as is found on the [{{SERVER}}/products.php?product_id=MOT0109 MOT0109 Spatial Phidget], your system can be hardened against the effects of gradual changes in temperature.


==Drift==
===So Why Gyroscopes?===
Gyroscopes drift.  It is unavoidable.  Even extremely expensive, high end models will have significant drift.  For example, a gyroscope rated to drift 0.114&deg;/min, would, over the course of an hour of measurements, report values that are nearly 7&deg; off what they should be.  This is obviously quite substantial. In order to compensate for drift there are a few things you can do:
To this point, we’ve covered a range of disadvantages and limitations of gyroscopes, and continually brought up the idea of correcting them via outside sources, like accelerometers and magnetometers. Why not just use those? The area where gyroscopes shine is measuring rotations over short periods of time, while the rest of the system is in motion. Gyroscopes are designed to ignore all outside factors except rotation. This means they provide an accurate sense of the sensor’s change in orientation over short timescales, which is useful when used in combination with other sensors to limit the effects of short-term outside factors on the measurement of orientation.


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. 
===This All Sounds Really Complicated===
So if gyroscopes are only really useful when used with other sensors, the next question is logically how do you go about doing so? Luckily, using the [[Spatial_Primer|Phidget Spatial]] AHRS functionality, on newer Phidget Spatial devices, we can do those calculations for you. Check out our guide on AHRS to find out how!


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. 
==Demonstrations Using the Control Panel Example==
To more cleanly see the effects we have been describing, we can use the Control Panel example for your Phidgets Gyroscope to do some demonstrations.
[[File:Gyroscope_Example.jpg|400px|link=|thumb|The Phidgets Control Panel Accelerometer Example]]


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.
The gyroscope example provides three dials showing the axes of rotation. For ease of demonstration, the example code is integrating the rotations in each axis and displaying the overall rotation in each.  


==Noise==
Once your example is open, we recommend sliding the DataInterval slider all the way to the left for the highest data rates from your sensor.


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.
If your sensor supports temperature stabilization, a checkbox will be available to enable heating. For best results, check the box to enable heating and wait for the temperature measurement to turn green. You will notice the readings tending closer to zero as the device heats up.


===White Noise===
The first thing you may notice is that the angles are already slowly drifting while the device is sitting still. This is caused by gyro drift, and cleanly demonstrates why gyroscopes need to be routinely zeroed. Place your gyro on a solid, flat surface and press the Zero Gyro button on the example now.


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&deg;/s one sample, 101&deg;/s another sample, and 97&deg;/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.
You should notice that the angle indicators for all three axes have moved to zero, and are staying relatively stable. If you leave the device for a minute or two, you will start seeing the measurement diverge by a few degrees. Again, gyroscope measurements need to be handled with care.


===Random Walk===
After you have zeroed your gyro, you can slowly rotate your gyroscope while leaving it flat on your desk. The Z axis should track your movements. If you turn the gyroscope 90 degrees, the Z-position dial should also rotate 90 degrees, and generally follow your movements. ''It is very important this rotation be slow for this demonstration, as the low-rate high-precision gyro is much more accurate, but capped at a far lower than the maximum rotational speed measurable by the device.''


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.
Similarly, you can turn your sensor on its edge, and see Y-position rotate if you rotate the sensor about the cable, and X-position move by turning the sensor in the remaining direction.
 
Remember that these angles of rotation are all obtained through post-processing calculations, and not direct read-outs from the sensor. The other thing to remember is that these are all incredibly simple calculations done individually for each axis, which is not enough to actually keep track of the orientation of the sensor. Once the sensor rotates in one axis, rotations in all others must account for this change. ''We do not recommend diving into this problem unless you have very clear reasons to need to.''
 
The main takeaway you should get from this example is how the gyroscopes respond to short-term rotations, and how they drift over time. To actually get the orientation of your sensor calculated for you, we recommend using the [[Spatial_Primer|Spatial]] object in your code, and reading out the calculated device orientation directly.

Revision as of 16:38, 13 January 2022

Gyroscopes and Their Uses

Introduction

Gyroscopes Measure Rotation in 3 Axes

In the context of sensors, gyroscopes are used to measure rotations. More specifically, they measure the rate at which the sensor is rotating, called angular velocity. At Phidgets, we represent this rotation in terms of degrees per second. By adding up, or integrating all the readings of angular velocity over time, you can track the angle of rotation from where the sensor started.

Considerations

Gyroscopes can only be used to track a change in angular position. Unlike magnetometers and accelerometers, there is no fixed frame of reference that can be measured by the gyroscope itself to determine a starting angle. To make sense of your gyro readings, you will need to start from a known frame of reference. This either means starting the sensor in a known, fixed orientation, or using an accelerometer and compass to get a more general sense of orientation before factoring in the gyroscope.

Drift

All gyroscopes drift. Even the expensive ones. Of course, a good gyro will drift less than a cheaper one, but both will drift. Essentially, the readings from the gyro while it is at rest will change slightly over time. Since gyroscope readings are integrated to obtain meaningful results, even small drift can lead to large discrepancies in measured vs actual position over longer timescales. Either the sensor must be routinely reset or “zeroed” to compensate, or the sensor can be slowly corrected to a known frame of reference, such as one measured by a combination of accelerometer and compass measurements.

Temperature Effects

One contributor to gyroscope drift is changes in temperature. If your Phidget incorporates temperature stabilization, as is found on the MOT0109 Spatial Phidget, your system can be hardened against the effects of gradual changes in temperature.

So Why Gyroscopes?

To this point, we’ve covered a range of disadvantages and limitations of gyroscopes, and continually brought up the idea of correcting them via outside sources, like accelerometers and magnetometers. Why not just use those? The area where gyroscopes shine is measuring rotations over short periods of time, while the rest of the system is in motion. Gyroscopes are designed to ignore all outside factors except rotation. This means they provide an accurate sense of the sensor’s change in orientation over short timescales, which is useful when used in combination with other sensors to limit the effects of short-term outside factors on the measurement of orientation.

This All Sounds Really Complicated

So if gyroscopes are only really useful when used with other sensors, the next question is logically how do you go about doing so? Luckily, using the Phidget Spatial AHRS functionality, on newer Phidget Spatial devices, we can do those calculations for you. Check out our guide on AHRS to find out how!

Demonstrations Using the Control Panel Example

To more cleanly see the effects we have been describing, we can use the Control Panel example for your Phidgets Gyroscope to do some demonstrations.

The Phidgets Control Panel Accelerometer Example

The gyroscope example provides three dials showing the axes of rotation. For ease of demonstration, the example code is integrating the rotations in each axis and displaying the overall rotation in each.

Once your example is open, we recommend sliding the DataInterval slider all the way to the left for the highest data rates from your sensor.

If your sensor supports temperature stabilization, a checkbox will be available to enable heating. For best results, check the box to enable heating and wait for the temperature measurement to turn green. You will notice the readings tending closer to zero as the device heats up.

The first thing you may notice is that the angles are already slowly drifting while the device is sitting still. This is caused by gyro drift, and cleanly demonstrates why gyroscopes need to be routinely zeroed. Place your gyro on a solid, flat surface and press the Zero Gyro button on the example now.

You should notice that the angle indicators for all three axes have moved to zero, and are staying relatively stable. If you leave the device for a minute or two, you will start seeing the measurement diverge by a few degrees. Again, gyroscope measurements need to be handled with care.

After you have zeroed your gyro, you can slowly rotate your gyroscope while leaving it flat on your desk. The Z axis should track your movements. If you turn the gyroscope 90 degrees, the Z-position dial should also rotate 90 degrees, and generally follow your movements. It is very important this rotation be slow for this demonstration, as the low-rate high-precision gyro is much more accurate, but capped at a far lower than the maximum rotational speed measurable by the device.

Similarly, you can turn your sensor on its edge, and see Y-position rotate if you rotate the sensor about the cable, and X-position move by turning the sensor in the remaining direction.

Remember that these angles of rotation are all obtained through post-processing calculations, and not direct read-outs from the sensor. The other thing to remember is that these are all incredibly simple calculations done individually for each axis, which is not enough to actually keep track of the orientation of the sensor. Once the sensor rotates in one axis, rotations in all others must account for this change. We do not recommend diving into this problem unless you have very clear reasons to need to.

The main takeaway you should get from this example is how the gyroscopes respond to short-term rotations, and how they drift over time. To actually get the orientation of your sensor calculated for you, we recommend using the Spatial object in your code, and reading out the calculated device orientation directly.