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