WPILibC++  2020.3.2-60-g3011ebe
AnalogGyro.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) 2008-2019 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 #include "frc/smartdashboard/Sendable.h"
16 #include "frc/smartdashboard/SendableHelper.h"
17 
18 namespace frc {
19 
20 class AnalogInput;
21 
35 class AnalogGyro : public GyroBase {
36  public:
37  static constexpr int kOversampleBits = 10;
38  static constexpr int kAverageBits = 0;
39  static constexpr double kSamplesPerSecond = 50.0;
40  static constexpr double kCalibrationSampleTime = 5.0;
41  static constexpr double kDefaultVoltsPerDegreePerSecond = 0.007;
42 
49  explicit AnalogGyro(int channel);
50 
63  explicit AnalogGyro(AnalogInput* channel);
64 
75  explicit AnalogGyro(std::shared_ptr<AnalogInput> channel);
76 
87  AnalogGyro(int channel, int center, double offset);
88 
103  AnalogGyro(std::shared_ptr<AnalogInput> channel, int center, double offset);
104 
105  ~AnalogGyro() override;
106 
107  AnalogGyro(AnalogGyro&& rhs);
108  AnalogGyro& operator=(AnalogGyro&& rhs);
109 
122  double GetAngle() const override;
123 
131  double GetRate() const override;
132 
139  virtual int GetCenter() const;
140 
147  virtual double GetOffset() const;
148 
158  void SetSensitivity(double voltsPerDegreePerSecond);
159 
169  void SetDeadband(double volts);
170 
178  void Reset() override;
179 
185  virtual void InitGyro();
186 
187  void Calibrate() override;
188 
189  protected:
190  std::shared_ptr<AnalogInput> m_analog;
191 
192  private:
193  hal::Handle<HAL_GyroHandle> m_gyroHandle;
194 };
195 
196 } // namespace frc
frc::AnalogGyro
Use a rate gyro to return the robots heading relative to a starting position.
Definition: AnalogGyro.h:35
frc::AnalogGyro::InitGyro
virtual void InitGyro()
Initialize the gyro.
frc::AnalogGyro::GetCenter
virtual int GetCenter() const
Return the gyro center value.
frc::AnalogGyro::GetAngle
double GetAngle() const override
Return the actual angle in degrees that the robot is currently facing.
frc::AnalogGyro::GetOffset
virtual double GetOffset() const
Return the gyro offset value.
frc::AnalogGyro::AnalogGyro
AnalogGyro(int channel)
Gyro constructor using the Analog Input channel number.
frc::AnalogGyro::SetDeadband
void SetDeadband(double volts)
Set the size of the neutral zone.
frc::AnalogGyro::GetRate
double GetRate() const override
Return the rate of rotation of the gyro.
frc::AnalogGyro::Reset
void Reset() override
Reset the gyro.
frc::AnalogInput
Analog input class.
Definition: AnalogInput.h:37
frc
A class that enforces constraints on the differential drive kinematics.
Definition: PDPSim.h:16
frc::GyroBase
GyroBase is the common base class for Gyro implementations such as AnalogGyro.
Definition: GyroBase.h:22
frc::AnalogGyro::Calibrate
void Calibrate() override
Calibrate the gyro by running for a number of samples and computing the center value.
frc::AnalogGyro::SetSensitivity
void SetSensitivity(double voltsPerDegreePerSecond)
Set the gyro sensitivity.