Boboter
Loading...
Searching...
No Matches
imu.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include <driver/i2c_types.h>
11#include "types/vector3.h"
12#include "types/quaternion.h"
13#include "include/log_sources.h"
14
15class Robot;
16
17namespace Device {
18 class Imu {
19 private:
20 static constexpr const char* TAG = "Device::Imu";
21 static constexpr log_source LOG_SOURCE = LOG_SOURCE_DEVICE_IMU;
22
23 static constexpr uint8_t I2C_ADDRESS = 0x68;
24 static constexpr uint32_t I2C_CLOCK_SPEED = 100'000;
25 static constexpr uint8_t MPU6050_DEVICE_ID = 0x68;
26 static constexpr uint8_t FIFO_BUFFER_SIZE = 42;
27
28 Robot& robot;
29 i2c_master_dev_handle_t device_handle;
30 quaternion quaternion_values;
31 vector3 gyro_values;
32
33 private:
40 void write_register(uint8_t register_address, uint8_t value) const;
41
49 [[nodiscard]] uint8_t read_register(uint8_t register_address) const;
50
51 private:
52 #include "imu_registers.inc.h"
53 #include "imu_dmp_firmware.inc.h"
54
55 public:
56 explicit Imu(Robot& robot);
57 ~Imu();
58
62 void initialize();
63
67 void read_fifo_buffer();
68
74 [[nodiscard]] quaternion get_quaternion() const { return quaternion_values; }
75
81 [[nodiscard]] vector3 get_gyro_values() const { return gyro_values; }
82 };
83}
~Imu()
Definition imu.cpp:25
void initialize()
Sets up the necessary I2C channel.
Definition imu.cpp:29
void read_fifo_buffer()
Reads the current FIFO buffer from the IMUs DMP (digital motion processor).
Definition imu.cpp:97
Imu(Robot &robot)
Definition imu.cpp:16
quaternion get_quaternion() const
Retrieves the quaternion from the last measurement.
Definition imu.h:74
vector3 get_gyro_values() const
Retrieves the gyro values from the last measurement.
Definition imu.h:81
Class containing all the components of the robot.
Definition robot.h:32
log_source
Definition log_sources.h:12
@ LOG_SOURCE_DEVICE_IMU
Definition log_sources.h:28
Definition battery.cpp:14
A struct to represent a quaternion value.
Definition quaternion.h:13
A struct to represent a value with x, y and z components.
Definition vector3.h:13