Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2008-2016. 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 "GyroBase.h" |
| 11 | #include "simulation/SimGyro.h" |
| 12 | |
| 13 | #include <memory> |
| 14 | |
| 15 | class AnalogInput; |
| 16 | class AnalogModule; |
| 17 | |
| 18 | /** |
| 19 | * Use a rate gyro to return the robots heading relative to a starting position. |
| 20 | * The AnalogGyro class tracks the robots heading based on the starting position. As the robot |
| 21 | * rotates the new heading is computed by integrating the rate of rotation returned |
| 22 | * by the sensor. When the class is instantiated, it does a short calibration routine |
| 23 | * where it samples the gyro while at rest to determine the default offset. This is |
| 24 | * subtracted from each sample to determine the heading. This gyro class must be used |
| 25 | * with a channel that is assigned one of the Analog accumulators from the FPGA. See |
| 26 | * AnalogInput for the current accumulator assignments. |
| 27 | */ |
| 28 | class AnalogGyro : public GyroBase |
| 29 | { |
| 30 | public: |
| 31 | static const uint32_t kOversampleBits; |
| 32 | static const uint32_t kAverageBits; |
| 33 | static const float kSamplesPerSecond; |
| 34 | static const float kCalibrationSampleTime; |
| 35 | static const float kDefaultVoltsPerDegreePerSecond; |
| 36 | |
| 37 | explicit AnalogGyro(uint32_t channel); |
| 38 | virtual ~AnalogGyro() = default; |
| 39 | float GetAngle() const; |
| 40 | void Calibrate() override; |
| 41 | double GetRate() const; |
| 42 | void Reset(); |
| 43 | |
| 44 | private: |
| 45 | void InitAnalogGyro(int channel); |
| 46 | |
| 47 | SimGyro* impl; |
| 48 | |
| 49 | std::shared_ptr<ITable> m_table; |
| 50 | }; |