Source code for wpilib.gyrobase

# validated: 2017-12-24 DS f9bece2ffbf7 edu/wpi/first/wpilibj/GyroBase.java
#----------------------------------------------------------------------------
# Copyright (c) FIRST 2008-2017. All Rights Reserved.
# Open Source Software - may be modified and shared by FRC teams. The code
# must be accompanied by the FIRST BSD license file in the root directory of
# the project.
#----------------------------------------------------------------------------


from .interfaces import PIDSource
from .sensorbase import SensorBase

__all__ = ['GyroBase']

[docs]class GyroBase(SensorBase): ''' GyroBase is the common base class for Gyro implementations such as :class:`.AnalogGyro`. ''' PIDSourceType = PIDSource.PIDSourceType def __init__(self): super().__init__() self.pidSource = self.PIDSourceType.kDisplacement self.valueEntry = None
[docs] def calibrate(self): raise NotImplementedError()
[docs] def reset(self): raise NotImplementedError()
[docs] def getAngle(self): raise NotImplementedError()
[docs] def getRate(self): raise NotImplementedError()
[docs] def setPIDSourceType(self, pidSource): """Set which parameter of the gyro you are using as a process control variable. The Gyro class supports the rate and angle parameters. :param pidSource: An enum to select the parameter. :type pidSource: :class:`.PIDSource.PIDSourceType` """ if pidSource not in (self.PIDSourceType.kDisplacement, self.PIDSourceType.kRate): raise ValueError("Must be kRate or kDisplacement") self.pidSource = pidSource
[docs] def getPIDSourceType(self): return self.pidSource
[docs] def pidGet(self): """Get the output of the gyro for use with PIDControllers. May be the angle or rate depending on the set :class:`.PIDSourceType` :returns: the current angle according to the gyro :rtype: float """ if self.pidSource == self.PIDSourceType.kRate: return self.getRate() elif self.pidSource == self.PIDSourceType.kDisplacement: return self.getAngle() else: return 0.0
[docs] def initSendable(self, builder): builder.setSmartDashboardType("Gyro") builder.addDoubleProperty("Value", self.getAngle, None)