blob: a106a98040616f8ae7b45c3606da79546a6bfe53 [file] [log] [blame]
jerrymf1579332013-02-07 01:56:28 +00001/*----------------------------------------------------------------------------*/
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
7#ifndef GYRO_H_
8#define GYRO_H_
9
10#include "SensorBase.h"
11#include "PIDSource.h"
12#include "LiveWindow/LiveWindowSendable.h"
13
14class AnalogChannel;
15class AnalogModule;
16
17/**
18 * Use a rate gyro to return the robots heading relative to a starting position.
19 * The Gyro class tracks the robots heading based on the starting position. As the robot
20 * rotates the new heading is computed by integrating the rate of rotation returned
21 * by the sensor. When the class is instantiated, it does a short calibration routine
22 * where it samples the gyro while at rest to determine the default offset. This is
23 * subtracted from each sample to determine the heading. This gyro class must be used
24 * with a channel that is assigned one of the Analog accumulators from the FPGA. See
25 * AnalogChannel for the current accumulator assignments.
26 */
27class Gyro : public SensorBase, public PIDSource, public LiveWindowSendable
28{
29public:
30 static const UINT32 kOversampleBits = 10;
31 static const UINT32 kAverageBits = 0;
32 static const float kSamplesPerSecond = 50.0;
33 static const float kCalibrationSampleTime = 5.0;
34 static const float kDefaultVoltsPerDegreePerSecond = 0.007;
35
36 Gyro(UINT8 moduleNumber, UINT32 channel);
37 explicit Gyro(UINT32 channel);
38 explicit Gyro(AnalogChannel *channel);
39 explicit Gyro(AnalogChannel &channel);
40 virtual ~Gyro();
41 virtual float GetAngle();
42 void SetSensitivity(float voltsPerDegreePerSecond);
43 virtual void Reset();
44
45 // PIDSource interface
46 double PIDGet();
47
48 void UpdateTable();
49 void StartLiveWindowMode();
50 void StopLiveWindowMode();
51 std::string GetSmartDashboardType();
52 void InitTable(ITable *subTable);
53 ITable * GetTable();
54
55private:
56 void InitGyro();
57
58 AnalogChannel *m_analog;
59 float m_voltsPerDegreePerSecond;
60 float m_offset;
61 bool m_channelAllocated;
62
63 ITable *m_table;
64};
65#endif