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 | |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 8 | #include "aos/events/event-loop.h" |
| 9 | #include "aos/robot_state/robot_state.q.h" |
Brian Silverman | 07ec88e | 2014-12-28 00:13:08 -0800 | [diff] [blame] | 10 | #include "frc971/wpilib/gyro_interface.h" |
| 11 | |
| 12 | namespace frc971 { |
| 13 | namespace wpilib { |
| 14 | |
| 15 | // Handles reading the gyro over SPI and sending out angles on a queue. |
| 16 | // |
| 17 | // This is designed to be passed into ::std::thread's constructor so it will run |
| 18 | // as a separate thread. |
| 19 | class GyroSender { |
| 20 | public: |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 21 | GyroSender(::aos::EventLoop *event_loop); |
Brian Silverman | 07ec88e | 2014-12-28 00:13:08 -0800 | [diff] [blame] | 22 | |
| 23 | // For ::std::thread to call. |
| 24 | // |
Brian Silverman | 5f17a97 | 2016-02-28 01:49:32 -0500 | [diff] [blame] | 25 | // Initializes the gyro and then loops until Quit() is called taking readings. |
Brian Silverman | 07ec88e | 2014-12-28 00:13:08 -0800 | [diff] [blame] | 26 | void operator()(); |
| 27 | |
| 28 | void Quit() { run_ = false; } |
| 29 | |
| 30 | private: |
Austin Schuh | df6cbb1 | 2019-02-02 13:46:52 -0800 | [diff] [blame] | 31 | ::aos::EventLoop *event_loop_; |
| 32 | ::aos::Fetcher<::aos::JoystickState> joystick_state_fetcher_; |
Brian Silverman | 07ec88e | 2014-12-28 00:13:08 -0800 | [diff] [blame] | 33 | |
| 34 | // Readings per second. |
| 35 | static const int kReadingRate = 200; |
| 36 | |
| 37 | GyroInterface gyro_; |
| 38 | |
| 39 | ::std::atomic<bool> run_{true}; |
| 40 | }; |
| 41 | |
| 42 | } // namespace wpilib |
| 43 | } // namespace frc971 |
| 44 | |
| 45 | #endif // FRC971_WPILIB_GYRO_H_ |