blob: 6ae2f6544f08af7f2bdf6055323b3bb1ac7d5ab4 [file] [log] [blame]
Brian Silvermanf7f267a2017-02-04 16:16:08 -08001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2014-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
10namespace frc {
11
12/**
13 * Interface for yaw rate gyros
14 */
15class Gyro {
16 public:
17 virtual ~Gyro() = default;
18
19 /**
20 * Calibrate the gyro by running for a number of samples and computing the
21 * center value. Then use the center value as the Accumulator center value for
22 * subsequent measurements. It's important to make sure that the robot is not
23 * moving while the centering calculations are in progress, this is typically
24 * done when the robot is first turned on while it's sitting at rest before
25 * the competition starts.
26 */
27 virtual void Calibrate() = 0;
28
29 /**
30 * Reset the gyro. Resets the gyro to a heading of zero. This can be used if
31 * there is significant drift in the gyro and it needs to be recalibrated
32 * after it has been running.
33 */
34 virtual void Reset() = 0;
35
36 /**
37 * Return the actual angle in degrees that the robot is currently facing.
38 *
39 * The angle is based on the current accumulator value corrected by the
40 * oversampling rate, the gyro type and the A/D calibration values. The angle
41 * is continuous, that is it will continue from 360 to 361 degrees. This
42 * allows algorithms that wouldn't want to see a discontinuity in the gyro
43 * output as it sweeps past from 360 to 0 on the second time around.
44 *
45 * @return the current heading of the robot in degrees. This heading is based
46 * on integration of the returned rate from the gyro.
47 */
48 virtual double GetAngle() const = 0;
49
50 /**
51 * Return the rate of rotation of the gyro
52 *
53 * The rate is based on the most recent reading of the gyro analog value
54 *
55 * @return the current rate in degrees per second
56 */
57 virtual double GetRate() const = 0;
58};
59
60} // namespace frc