Brian Silverman | f7f267a | 2017-02-04 16:16:08 -0800 | [diff] [blame^] | 1 | /*----------------------------------------------------------------------------*/ |
| 2 | /* Copyright (c) FIRST 2015-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 "HAL/cpp/priority_mutex.h" |
| 14 | #include "Notifier.h" |
| 15 | #include "SPI.h" |
| 16 | |
| 17 | namespace frc { |
| 18 | |
| 19 | /** |
| 20 | * Use a rate gyro to return the robots heading relative to a starting position. |
| 21 | * The Gyro class tracks the robots heading based on the starting position. As |
| 22 | * the robot rotates the new heading is computed by integrating the rate of |
| 23 | * rotation returned by the sensor. When the class is instantiated, it does a |
| 24 | * short calibration routine where it samples the gyro while at rest to |
| 25 | * determine the default offset. This is subtracted from each sample to |
| 26 | * determine the heading. |
| 27 | * |
| 28 | * This class is for the digital ADXRS450 gyro sensor that connects via SPI. |
| 29 | */ |
| 30 | class ADXRS450_Gyro : public GyroBase { |
| 31 | public: |
| 32 | ADXRS450_Gyro(); |
| 33 | explicit ADXRS450_Gyro(SPI::Port port); |
| 34 | virtual ~ADXRS450_Gyro() = default; |
| 35 | |
| 36 | double GetAngle() const override; |
| 37 | double GetRate() const override; |
| 38 | void Reset() override; |
| 39 | void Calibrate() override; |
| 40 | |
| 41 | private: |
| 42 | SPI m_spi; |
| 43 | |
| 44 | uint16_t ReadRegister(int reg); |
| 45 | }; |
| 46 | |
| 47 | } // namespace frc |