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