blob: 338ad323047d47f03a524d67be941362e8b39d5a [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_;
Austin Schuh1ea89bb2019-05-27 16:59:59 -070035 ::aos::Sender<::frc971::sensors::GyroReading> gyro_reading_sender_;
Brian Silverman07ec88e2014-12-28 00:13:08 -080036
37 // Readings per second.
38 static const int kReadingRate = 200;
39
40 GyroInterface gyro_;
41
42 ::std::atomic<bool> run_{true};
43};
44
45} // namespace wpilib
46} // namespace frc971
47
48#endif // FRC971_WPILIB_GYRO_H_