SkyPulse UAV V0.1
Loading...
Searching...
No Matches
gyroacelemeter_gy521.h
Go to the documentation of this file.
1#ifndef GYROACELEMETER_GY521_H
2#define GYROACELEMETER_GY521_H
3
4#include <QObject>
5#include <QThread>
6#include "i2c_device.h"
7
8class MPU6050 : public QObject
9{
10 Q_OBJECT
11
12public:
13 explicit MPU6050 (uint8_t i2cAddress = 0x68, QObject *parent = nullptr);
14 void readAllSensors(float &ax, float &ay, float &az, float &gx, float &gy, float &gz);
15 void calibrateGyro();
16 void calibrateAccel();
17 bool writeByte(uint8_t reg, uint8_t value);
18 bool readBytes(uint8_t reg, uint8_t *buffer, size_t length);
19
20public slots:
21 void readAllMPU6050Reg();
22
23private:
24 I2C_Device *i2cDevice;
25
26 // Calibration offsets
27 float gyroOffset[3] = {0, 0, 0};
28 float accelOffset[3] = {0, 0, 0};
29
30 static constexpr uint8_t PWR_MGMT_1 = 0x6B;
31 static constexpr uint8_t ACCEL_XOUT_H = 0x3B;
32 static constexpr uint8_t GYRO_XOUT_H = 0x43;
33 static constexpr uint8_t INT_ENABLE = 0x38; // Interrupt Enable Register
34 static constexpr uint8_t INT_PIN_CFG = 0x37; // Interrupt Pin/Bypass Enable Configuration Register
35 static constexpr float ACCEL_FS_SEL_2G = 16384.0;
36 static constexpr float GYRO_FS_SEL_250DEG = 131.0;
37
38 bool initializeMPU6050();
39 void applyCalibration(float &ax, float &ay, float &az, float &gx, float &gy, float &gz);
40};
41
42#endif // GYROACELEMETER_GY521_H
Definition i2c_device.h:8
Definition MPU6050.h:21
bool writeByte(uint8_t reg, uint8_t value)
Definition gyroacelemeter_gy521.cpp:41
bool readBytes(uint8_t reg, uint8_t *buffer, size_t length)
Definition gyroacelemeter_gy521.cpp:46
void calibrateGyro()
Definition gyroacelemeter_gy521.cpp:69
void readAllSensors(float &ax, float &ay, float &az, float &gx, float &gy, float &gz)
Definition gyroacelemeter_gy521.cpp:55
MPU6050()
Definition MPU6050.cpp:10
void readAllMPU6050Reg()
Definition gyroacelemeter_gy521.cpp:117
void calibrateAccel()
Definition gyroacelemeter_gy521.cpp:88