class wpilib.AnalogGyro(channel, center=None, offset=None)[source]

Bases: wpilib.GyroBase

Interface to a gyro device via an AnalogInput

Use a rate gyro to return the robots heading relative to a starting position. The Gyro class tracks the robots heading based on the starting position. As the robot rotates the new heading is computed by integrating the rate of rotation returned by the sensor. When the class is instantiated, it does a short calibration routine where it samples the gyro while at rest to determine the default offset. This is subtracted from each sample to determine the heading.

Gyro constructor.

Also initializes the gyro. Calibrate the gyro by running for a number of samples and computing the center value. Then use the center value as the Accumulator center value for subsequent measurements. It’s important to make sure that the robot is not moving while the centering calculations are in progress, this is typically done when the robot is first turned on while it’s sitting at rest before the competition starts.

  • channel – The analog channel index or AnalogInput object that the gyro is connected to. Gyros can only be used on on-board channels 0-1.
  • center (int) – Preset uncalibrated value to use as the accumulator center value
  • offset (float) – Preset uncalibrated value to use as the gyro offset
class PIDSourceType

Bases: object

A description for the type of output value to provide to a PIDController

kDisplacement = 0
kRate = 1

Return the gyro center value set during calibration to use as a future preset

Returns:the current center value

Return the gyro offset value set during calibration to use as a future preset

Returns:the current offset value
AnalogGyro.kAverageBits = 0
AnalogGyro.kCalibrationSampleTime = 5.0
AnalogGyro.kDefaultVoltsPerDegreePerSecond = 0.007
AnalogGyro.kOversampleBits = 10
AnalogGyro.kSamplesPerSecond = 50.0

Set the size of the neutral zone. Any voltage from the gyro less than this amount from the center is considered stationary. Setting a deadband will decrease the amount of drift when the gyro isn’t rotating, but will make it less accurate.

Parameters:volts (float) – The size of the deadband in volts

Set the gyro sensitivity. This takes the number of volts/degree/second sensitivity of the gyro and uses it in subsequent calculations to allow the code to work with multiple gyros. This value is typically found in the gyro datasheet.

Parameters:voltsPerDegreePerSecond (float) – The sensitivity in Volts/degree/second