blob: d41109eae12940d9658129ea3c99fd043b4a6381 [file] [log] [blame]
Brian Silverman07ec88e2014-12-28 00:13:08 -08001#ifndef FRC971_WPILIB_GYRO_H_
2#define FRC971_WPILIB_GYRO_H_
3
4#include <stdint.h>
5
6#include <atomic>
7
Austin Schuhdf6cbb12019-02-02 13:46:52 -08008#include "aos/events/event-loop.h"
9#include "aos/robot_state/robot_state.q.h"
Brian Silverman07ec88e2014-12-28 00:13:08 -080010#include "frc971/wpilib/gyro_interface.h"
11
12namespace frc971 {
13namespace 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.
19class GyroSender {
20 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -080021 GyroSender(::aos::EventLoop *event_loop);
Brian Silverman07ec88e2014-12-28 00:13:08 -080022
23 // For ::std::thread to call.
24 //
Brian Silverman5f17a972016-02-28 01:49:32 -050025 // Initializes the gyro and then loops until Quit() is called taking readings.
Brian Silverman07ec88e2014-12-28 00:13:08 -080026 void operator()();
27
28 void Quit() { run_ = false; }
29
30 private:
Austin Schuhdf6cbb12019-02-02 13:46:52 -080031 ::aos::EventLoop *event_loop_;
32 ::aos::Fetcher<::aos::JoystickState> joystick_state_fetcher_;
Brian Silverman07ec88e2014-12-28 00:13:08 -080033
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_