WPILibC++  unspecified
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 "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 
41  explicit AnalogGyro(int channel);
42  explicit AnalogGyro(AnalogInput* channel);
43  explicit AnalogGyro(std::shared_ptr<AnalogInput> channel);
44  AnalogGyro(int channel, int center, double offset);
45  AnalogGyro(std::shared_ptr<AnalogInput> channel, int center, double offset);
46  virtual ~AnalogGyro();
47 
48  double GetAngle() const override;
49  double GetRate() const override;
50  virtual int GetCenter() const;
51  virtual double GetOffset() const;
52  void SetSensitivity(double voltsPerDegreePerSecond);
53  void SetDeadband(double volts);
54  void Reset() override;
55  virtual void InitGyro();
56  void Calibrate() override;
57 
58  protected:
59  std::shared_ptr<AnalogInput> m_analog;
60 
61  private:
62  HAL_GyroHandle m_gyroHandle = HAL_kInvalidHandle;
63 };
64 
65 } // namespace frc
Definition: RobotController.cpp:14
AnalogGyro(int channel)
Gyro constructor using the Analog Input channel number.
Definition: AnalogGyro.cpp:28
void Calibrate() override
Calibrate the gyro by running for a number of samples and computing the center value.
Definition: AnalogGyro.cpp:170
void SetDeadband(double volts)
Set the size of the neutral zone.
Definition: AnalogGyro.cpp:265
virtual ~AnalogGyro()
AnalogGyro Destructor.
Definition: AnalogGyro.cpp:118
double GetAngle() const override
Return the actual angle in degrees that the robot is currently facing.
Definition: AnalogGyro.cpp:189
virtual double GetOffset() const
Return the gyro offset value.
Definition: AnalogGyro.cpp:218
virtual void InitGyro()
Initialize the gyro.
Definition: AnalogGyro.cpp:137
Use a rate gyro to return the robots heading relative to a starting position.
Definition: AnalogGyro.h:33
virtual int GetCenter() const
Return the gyro center value.
Definition: AnalogGyro.cpp:232
GyroBase is the common base class for Gyro implementations such as AnalogGyro.
Definition: GyroBase.h:20
double GetRate() const override
Return the rate of rotation of the gyro.
Definition: AnalogGyro.cpp:204
void SetSensitivity(double voltsPerDegreePerSecond)
Set the gyro sensitivity.
Definition: AnalogGyro.cpp:249
void Reset() override
Reset the gyro.
Definition: AnalogGyro.cpp:127
Analog input class.
Definition: AnalogInput.h:31