Gyroscope - quasics/quasics-frc-sw-2015 GitHub Wiki

A gyroscope, or “gyro,” is a sensor that is used to measure "an angular rate of turn" (i.e., how fast you're turning in one direction or another along a given axis).

They don't usually track your actual direction (i.e., relative to some absolute fixed point like the North pole), but only the change in direction over time; however, that often can be used to compute a heading relative to some known starting point (e.g., the direction you were pointing when they were turned on).

All gyros support at least one axis of rotation, while some support up to three. One way to visualize the different axes can be to think of an airplane:

  • "Yaw" is rotation when the plane is steering on the ground (conventionally, around the "Z" axis, in the "X/Y" plane), where the plane is changing its compass bearing.
  • "Roll" is rotation around the long, center line of the plane (around the "X" axis, in the "Y/Z" plane), with the wings tipping from side to side.
  • "Pitch" is rotation around the plane's midsection (around the "Y" axis, in the "X/Z" plane), with the nose/tail of the plane tipping up or down.

In FRC, the kind of rotation that we normally care about is "yaw", and can be used to do things like "drive straight ahead", or "turn N degrees to the right", etc.

WPILib natively provides specific support for the some gyro hardware. For example, the ADXRS450 gyro is directly supported, while more general support for a wider variety of analog gyros is provided through the AnalogGyro class; all of these implement a standard interface that is conveniently called "Gyro". Some other gyros may require additional libraries to be added to your code in order to use them (e.g., the Pigeon2 hardware from CTRE uses a library they call "Phoenix"), but the core functionality and interface is usually pretty similar to the "stock" versions.

Note: gyros are also sometimes talked about in the same category as "inertial measurement units" (or "IMUs"). An IMU is an electronic device that measures the specific forces working on an object (e.g., due to gravity or other acceleration) and angular rate (the gyro part), possibly along with its orientation (direction), using a combination of accelerometers, gyroscopes, and sometimes magnetometers.

Resources

  • Analog Device's gyros for FRC
    • Links to data sheets, brief discussions of pros/cons for each, and summaries of how they're installed/used
  • FRC control system docs on Gyros
    • This includes sample code for creating and interacting with a gyro in C++/Java
  • Some classes to use with gyros in software:
    • Gyro class from WPILib (C++, Java)
    • ADXRS450_Gyro class from WPILib (C++, Java)
    • AnalogGyro class from WPILib (C++, Java
    • Pigeon2 class from CTRE (C++, Java)