WPILibC++  unspecified
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
AnalogGyro.h
1 /*----------------------------------------------------------------------------*/
2 /* Copyright (c) FIRST 2008-2017. 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 "GyroBase.h"
13 #include "HAL/Types.h"
14 
15 namespace frc {
16 
17 class AnalogInput;
18 
32 class AnalogGyro : public GyroBase {
33  public:
34  static const int kOversampleBits = 10;
35  static const int kAverageBits = 0;
36  static constexpr double kSamplesPerSecond = 50.0;
37  static constexpr double kCalibrationSampleTime = 5.0;
38  static constexpr double kDefaultVoltsPerDegreePerSecond = 0.007;
39 
40  explicit AnalogGyro(int channel);
41  explicit AnalogGyro(AnalogInput* channel);
42  explicit AnalogGyro(std::shared_ptr<AnalogInput> channel);
43  AnalogGyro(int channel, int center, double offset);
44  AnalogGyro(std::shared_ptr<AnalogInput> channel, int center, double offset);
45  virtual ~AnalogGyro();
46 
47  double GetAngle() const override;
48  double GetRate() const override;
49  virtual int GetCenter() const;
50  virtual double GetOffset() const;
51  void SetSensitivity(double voltsPerDegreePerSecond);
52  void SetDeadband(double volts);
53  void Reset() override;
54  virtual void InitGyro();
55  void Calibrate() override;
56 
57  protected:
58  std::shared_ptr<AnalogInput> m_analog;
59 
60  private:
61  HAL_GyroHandle m_gyroHandle = HAL_kInvalidHandle;
62 };
63 
64 } // namespace frc
AnalogGyro(int channel)
Gyro constructor using the Analog Input channel number.
Definition: AnalogGyro.cpp:34
void Calibrate() override
Calibrate the gyro by running for a number of samples and computing the center value.
Definition: AnalogGyro.cpp:184
void SetDeadband(double volts)
Set the size of the neutral zone.
Definition: AnalogGyro.cpp:279
virtual ~AnalogGyro()
AnalogGyro Destructor.
Definition: AnalogGyro.cpp:131
double GetAngle() const override
Return the actual angle in degrees that the robot is currently facing.
Definition: AnalogGyro.cpp:203
virtual double GetOffset() const
Return the gyro offset value.
Definition: AnalogGyro.cpp:232
virtual void InitGyro()
Initialize the gyro.
Definition: AnalogGyro.cpp:150
Use a rate gyro to return the robots heading relative to a starting position.
Definition: AnalogGyro.h:32
virtual int GetCenter() const
Return the gyro center value.
Definition: AnalogGyro.cpp:246
GyroBase is the common base class for Gyro implementations such as AnalogGyro.
Definition: GyroBase.h:24
double GetRate() const override
Return the rate of rotation of the gyro.
Definition: AnalogGyro.cpp:218
void SetSensitivity(double voltsPerDegreePerSecond)
Set the gyro sensitivity.
Definition: AnalogGyro.cpp:263
void Reset() override
Reset the gyro.
Definition: AnalogGyro.cpp:140
Analog input class.
Definition: AnalogInput.h:32