blob: 61b77044851e13be2162200391427f14a2932754 [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"
Austin Schuhcc1010e2019-05-12 20:38:01 -070010#include "frc971/queues/gyro.q.h"
Brian Silverman07ec88e2014-12-28 00:13:08 -080011#include "frc971/wpilib/gyro_interface.h"
12
13namespace frc971 {
14namespace 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.
20class GyroSender {
21 public:
Austin Schuhdf6cbb12019-02-02 13:46:52 -080022 GyroSender(::aos::EventLoop *event_loop);
Brian Silverman07ec88e2014-12-28 00:13:08 -080023
24 // For ::std::thread to call.
25 //
Brian Silverman5f17a972016-02-28 01:49:32 -050026 // Initializes the gyro and then loops until Quit() is called taking readings.
Brian Silverman07ec88e2014-12-28 00:13:08 -080027 void operator()();
28
29 void Quit() { run_ = false; }
30
31 private:
Austin Schuhdf6cbb12019-02-02 13:46:52 -080032 ::aos::EventLoop *event_loop_;
33 ::aos::Fetcher<::aos::JoystickState> joystick_state_fetcher_;
Austin Schuhcc1010e2019-05-12 20:38:01 -070034 ::aos::Sender<::frc971::sensors::Uid> uid_sender_;
Brian Silverman07ec88e2014-12-28 00:13:08 -080035
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_