WPILibC++  2018.4.1-20180923204725-1195-g5c6b78e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
AnalogGyro.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
3 /* Open Source Software - may be modified and shared by FRC teams. The code */
4 /* must be accompanied by the FIRST BSD license file in the root directory of */
5 /* the project. */
6 /*----------------------------------------------------------------------------*/
7 
8 #pragma once
9 
10 #include <memory>
11 
12 #include <hal/Types.h>
13 
14 #include "frc/GyroBase.h"
15 
16 namespace frc {
17 
18 class AnalogInput;
19 
33 class AnalogGyro : public GyroBase {
34  public:
35  static constexpr int kOversampleBits = 10;
36  static constexpr int kAverageBits = 0;
37  static constexpr double kSamplesPerSecond = 50.0;
38  static constexpr double kCalibrationSampleTime = 5.0;
39  static constexpr double kDefaultVoltsPerDegreePerSecond = 0.007;
40 
47  explicit AnalogGyro(int channel);
48 
61  explicit AnalogGyro(AnalogInput* channel);
62 
73  explicit AnalogGyro(std::shared_ptr<AnalogInput> channel);
74 
85  AnalogGyro(int channel, int center, double offset);
86 
101  AnalogGyro(std::shared_ptr<AnalogInput> channel, int center, double offset);
102 
103  virtual ~AnalogGyro();
104 
117  double GetAngle() const override;
118 
126  double GetRate() const override;
127 
134  virtual int GetCenter() const;
135 
142  virtual double GetOffset() const;
143 
153  void SetSensitivity(double voltsPerDegreePerSecond);
154 
164  void SetDeadband(double volts);
165 
173  void Reset() override;
174 
180  virtual void InitGyro();
181 
182  void Calibrate() override;
183 
184  protected:
185  std::shared_ptr<AnalogInput> m_analog;
186 
187  private:
188  HAL_GyroHandle m_gyroHandle = HAL_kInvalidHandle;
189 };
190 
191 } // namespace frc
void SetSensitivity(double voltsPerDegreePerSecond)
Set the gyro sensitivity.
WPILib FRC namespace.
Definition: SPIAccelerometerSim.h:18
virtual int GetCenter() const
Return the gyro center value.
AnalogGyro(int channel)
Gyro constructor using the Analog Input channel number.
double GetAngle() const override
Return the actual angle in degrees that the robot is currently facing.
void Reset() override
Reset the gyro.
void SetDeadband(double volts)
Set the size of the neutral zone.
Use a rate gyro to return the robots heading relative to a starting position.
Definition: AnalogGyro.h:33
double GetRate() const override
Return the rate of rotation of the gyro.
GyroBase is the common base class for Gyro implementations such as AnalogGyro.
Definition: GyroBase.h:21
virtual double GetOffset() const
Return the gyro offset value.
void Calibrate() override
Calibrate the gyro by running for a number of samples and computing the center value.
Analog input class.
Definition: AnalogInput.h:32
virtual void InitGyro()
Initialize the gyro.