AnalogGyro

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.

Parameters:
  • 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
AnalogGyro.calibrate()[source]
See:Gyro.calibrate()
AnalogGyro.free()[source]
See:Gyro.free()
AnalogGyro.getAngle()[source]
See:Gyro.getAngle()
AnalogGyro.getCenter()[source]

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

Returns:the current center value
AnalogGyro.getOffset()[source]

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

Returns:the current offset value
AnalogGyro.getRate()[source]
See:Gyro.getRate()
AnalogGyro.kAverageBits = 0
AnalogGyro.kCalibrationSampleTime = 5.0
AnalogGyro.kDefaultVoltsPerDegreePerSecond = 0.007
AnalogGyro.kOversampleBits = 10
AnalogGyro.kSamplesPerSecond = 50.0
AnalogGyro.reset()[source]
See:Gyro.reset()
AnalogGyro.setDeadband(volts)[source]

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
AnalogGyro.setSensitivity(voltsPerDegreePerSecond)[source]

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