Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 1 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 2 | /* Copyright (c) FIRST 2014-2016. All Rights Reserved. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 3 | /* Open Source Software - may be modified and shared by FRC teams. The code */ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 4 | /* must be accompanied by the FIRST BSD license file in the root directory of */ |
| 5 | /* the project. */ |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 6 | /*----------------------------------------------------------------------------*/ |
Brian Silverman | 1a67511 | 2016-02-20 20:42:49 -0500 | [diff] [blame^] | 7 | |
Brian Silverman | 26e4e52 | 2015-12-17 01:56:40 -0500 | [diff] [blame] | 8 | #pragma once |
| 9 | |
| 10 | /** |
| 11 | * Interface for yaw rate gyros |
| 12 | */ |
| 13 | class Gyro { |
| 14 | public: |
| 15 | virtual ~Gyro() = default; |
| 16 | |
| 17 | /** |
| 18 | * Calibrate the gyro by running for a number of samples and computing the |
| 19 | * center value. Then use the center value as the Accumulator center value for |
| 20 | * subsequent measurements. It's important to make sure that the robot is not |
| 21 | * moving while the centering calculations are in progress, this is typically |
| 22 | * done when the robot is first turned on while it's sitting at rest before |
| 23 | * the competition starts. |
| 24 | */ |
| 25 | virtual void Calibrate() = 0; |
| 26 | |
| 27 | /** |
| 28 | * Reset the gyro. Resets the gyro to a heading of zero. This can be used if |
| 29 | * there is significant drift in the gyro and it needs to be recalibrated |
| 30 | * after it has been running. |
| 31 | */ |
| 32 | virtual void Reset() = 0; |
| 33 | |
| 34 | /** |
| 35 | * Return the actual angle in degrees that the robot is currently facing. |
| 36 | * |
| 37 | * The angle is based on the current accumulator value corrected by the |
| 38 | * oversampling rate, the gyro type and the A/D calibration values. The angle |
| 39 | * is continuous, that is it will continue from 360 to 361 degrees. This |
| 40 | * allows algorithms that wouldn't want to see a discontinuity in the gyro |
| 41 | * output as it sweeps past from 360 to 0 on the second time around. |
| 42 | * |
| 43 | * @return the current heading of the robot in degrees. This heading is based |
| 44 | * on integration of the returned rate from the gyro. |
| 45 | */ |
| 46 | virtual float GetAngle() const = 0; |
| 47 | |
| 48 | /** |
| 49 | * Return the rate of rotation of the gyro |
| 50 | * |
| 51 | * The rate is based on the most recent reading of the gyro analog value |
| 52 | * |
| 53 | * @return the current rate in degrees per second |
| 54 | */ |
| 55 | virtual double GetRate() const = 0; |
| 56 | }; |