blob: 7e4e40ae75f0a33af2c41db3bc9f7696d52961a5 [file] [log] [blame]
Brian Silverman26e4e522015-12-17 01:56:40 -05001/*----------------------------------------------------------------------------*/
2/* Copyright (c) FIRST 2008. 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 $(WIND_BASE)/WPILib. */
5/*----------------------------------------------------------------------------*/
6#pragma once
7
8#include "SensorBase.h"
9#include "PIDSource.h"
10#include "LiveWindow/LiveWindowSendable.h"
11#include "simulation/SimGyro.h"
12
13#include <memory>
14
15class AnalogInput;
16class AnalogModule;
17
18/**
19 * Use a rate gyro to return the robots heading relative to a starting position.
20 * The Gyro 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 */
28class Gyro : public SensorBase, public PIDSource, public LiveWindowSendable
29{
30public:
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 Gyro(uint32_t channel);
38 virtual ~Gyro() = default;
39 virtual float GetAngle() const;
40 virtual double GetRate() const;
41 virtual void Reset();
42
43 // PIDSource interface
44 void SetPIDSourceType(PIDSourceType pidSource) override;
45 double PIDGet() override;
46
47 void UpdateTable() override;
48 void StartLiveWindowMode() override;
49 void StopLiveWindowMode() override;
50 std::string GetSmartDashboardType() const override;
51 void InitTable(std::shared_ptr<ITable> subTable) override;
52 std::shared_ptr<ITable> GetTable() const override;
53
54private:
55 void InitGyro(int channel);
56
57 SimGyro* impl;
58
59 std::shared_ptr<ITable> m_table;
60};