Brian Silverman | 07ec88e | 2014-12-28 00:13:08 -0800 | [diff] [blame] | 1 | #ifndef FRC971_WPILIB_GYRO_H_ |
| 2 | #define FRC971_WPILIB_GYRO_H_ |
| 3 | |
| 4 | #include <stdint.h> |
| 5 | |
| 6 | #include <atomic> |
| 7 | |
| 8 | #include "frc971/wpilib/gyro_interface.h" |
| 9 | |
| 10 | namespace frc971 { |
| 11 | namespace wpilib { |
| 12 | |
| 13 | // Handles reading the gyro over SPI and sending out angles on a queue. |
| 14 | // |
| 15 | // This is designed to be passed into ::std::thread's constructor so it will run |
| 16 | // as a separate thread. |
| 17 | class GyroSender { |
| 18 | public: |
| 19 | GyroSender(); |
| 20 | |
| 21 | // For ::std::thread to call. |
| 22 | // |
Brian Silverman | 5f17a97 | 2016-02-28 01:49:32 -0500 | [diff] [blame^] | 23 | // Initializes the gyro and then loops until Quit() is called taking readings. |
Brian Silverman | 07ec88e | 2014-12-28 00:13:08 -0800 | [diff] [blame] | 24 | void operator()(); |
| 25 | |
| 26 | void Quit() { run_ = false; } |
| 27 | |
| 28 | private: |
| 29 | |
| 30 | // Readings per second. |
| 31 | static const int kReadingRate = 200; |
| 32 | |
| 33 | GyroInterface gyro_; |
| 34 | |
| 35 | ::std::atomic<bool> run_{true}; |
| 36 | }; |
| 37 | |
| 38 | } // namespace wpilib |
| 39 | } // namespace frc971 |
| 40 | |
| 41 | #endif // FRC971_WPILIB_GYRO_H_ |