Ravago Jones | e12b790 | 2022-02-04 22:50:44 -0800 | [diff] [blame^] | 1 | #ifndef Y2022_LOCALIZER_IMU_H_ |
| 2 | #define Y2022_LOCALIZER_IMU_H_ |
| 3 | #include "aos/events/shm_event_loop.h" |
| 4 | #include "frc971/wpilib/imu_batch_generated.h" |
| 5 | #include "y2022/constants.h" |
| 6 | |
| 7 | namespace y2022::localizer { |
| 8 | |
| 9 | // Reads IMU packets from the kernel driver which reads them over spi |
| 10 | // from the Raspberry Pi Pico on the IMU board. |
| 11 | class Imu { |
| 12 | public: |
| 13 | Imu(aos::ShmEventLoop *event_loop); |
| 14 | ~Imu(); |
| 15 | |
| 16 | private: |
| 17 | flatbuffers::Offset<frc971::ADIS16470DiagStat> PackDiagStat( |
| 18 | flatbuffers::FlatBufferBuilder *fbb, uint16_t value); |
| 19 | flatbuffers::Offset<frc971::IMUValues> ProcessReading( |
| 20 | flatbuffers::FlatBufferBuilder *fbb, absl::Span<uint8_t> buf); |
| 21 | double ConvertValue32(absl::Span<const uint8_t> data, double lsb_per_output); |
| 22 | double ConvertValue16(absl::Span<const uint8_t> data, double lsb_per_output); |
| 23 | |
| 24 | aos::ShmEventLoop *event_loop_; |
| 25 | aos::Sender<frc971::IMUValuesBatch> imu_sender_; |
| 26 | int imu_fd_; |
| 27 | |
| 28 | uint failed_checksums_ = 0; |
| 29 | }; |
| 30 | } // namespace y2022::localizer |
| 31 | #endif // Y2022_LOCALIZER_IMU_H_ |