C++ DevKit
C++ set of OOP library
Loading...
Searching...
No Matches
mpu6050.h
Go to the documentation of this file.
1
11#pragma once
12
13#include "pico/stdlib.h"
14#include "hw/i2c/hw_i2c.h"
15#include "config_MPU6050.h"
16
22{
24 uint8_t MPU_ADDR = 0x68;
26 uint16_t SAMPLE_RATE = 100;
28 uint8_t DLPF_BW = 50;
30 uint8_t EXT_SYNC = EXT_SYNC_SET_DISABLED;
32 uint16_t GYRO_OUT_RATE = 1000;
34 uint16_t GYRO_FULL_SCALE_RANGE = 250;
38 uint8_t FIFO_SELECTED_SENSORS = GYRO_FIFO_EN | ACCEL_FIFO_EN;
40 uint8_t INT_PIN_CFG = INT_LEVEL | LATCH_INT_EN | INT_RD_CLEAR;
42 uint8_t INT_ENABLE = DATA_RDY_EN;
44 uint8_t SIGNAL_PATH_RESET = NO_PATH_RESET;
46 uint8_t FIFO_OP = FIFO_EN;
48 uint8_t PWR_MGMT_1 = CLKSEL_Z_PLL;
49};
50
56{
58 int16_t g_x;
60 int16_t g_y;
62 int16_t g_z;
64 int16_t temp_out;
66 int16_t gyro_x;
68 int16_t gyro_y;
70 int16_t gyro_z;
71};
72
78{
80 float g_x;
82 float g_y;
84 float g_z;
86 float temp_out;
88 float gyro_x;
90 float gyro_y;
92 float gyro_z;
93};
94
101{
102private:
104 HW_I2C_Master *master;
106 struct_ConfigMPU6050 device_config;
108 float acceleration_factor{};
110 float gyro_factor{};
112 float temperature_gain = 1.0 / 340.0;
114 float temperature_offset = 36.53;
116 float accel_x_offset{};
118 float accel_y_offset{};
120 float accel_z_offset{};
122 float gyro_x_offset{};
124 float gyro_y_offset{};
126 float gyro_z_offset{};
127
132 void init_mpu();
138 struct_I2CXferResult read_registers_all_raw_data();
142 void calibrate();
146 void convert_raw_to_measure();
148 void read_FIFO_g_accel_raw_data();
150 void read_FIFO_accel_raw_data();
151
152public:
159 MPU6050(HW_I2C_Master *master, struct_ConfigMPU6050 default_config);
165 uint16_t get_FIFO_count();
174 float get_MPU_temperature();
181 bool is_data_ready();
191};
this is a C++ wrapper for the original pico SDK i2c master API
Definition hw_i2c.h:129
float get_MPU_temperature()
Get the MPU temperature object.
Definition mpu6050.cpp:183
struct_MPUData data
the set of measures from sensors
Definition mpu6050.h:167
MPU6050(HW_I2C_Master *master, struct_ConfigMPU6050 default_config)
Construct a new MPU6050 object.
Definition mpu6050.cpp:7
struct_I2CXferResult get_measures()
Get the raw data, fill the internal struct_RawData, converts raw data to real measures according to o...
Definition mpu6050.cpp:191
bool is_data_ready()
the flag that indicates if sensors data are ready
Definition mpu6050.cpp:206
struct_RawData raw
the set of raw data from sensors
Definition mpu6050.h:169
uint16_t get_FIFO_count()
Get the FIFO count object.
Definition mpu6050.cpp:199
void read_FIFO_all_raw_data()
read raw data from FIFO
Definition mpu6050.cpp:31
minimal set of MPU configuration data
Definition mpu6050.h:22
uint8_t SIGNAL_PATH_RESET
Reg 0x68: default no reset.
Definition mpu6050.h:44
uint8_t INT_ENABLE
Reg 0x38: INT each time a sensor register write occurs.
Definition mpu6050.h:42
uint16_t GYRO_FULL_SCALE_RANGE
Reg 0x1B: values in { 250, 500, 1000, 2000} DegreePerSecond.
Definition mpu6050.h:34
uint8_t ACCEL_FULL_SCALE_RANGE
Reg 0x1C:values in { 2, 4, 8, 16} G.
Definition mpu6050.h:36
uint8_t EXT_SYNC
Reg 0x1A: external synchronisation via FSYNC pin.
Definition mpu6050.h:30
uint8_t PWR_MGMT_1
Reg 0x6B:
Definition mpu6050.h:48
uint8_t FIFO_OP
Reg 0x6A: FIFO enable.
Definition mpu6050.h:46
uint8_t FIFO_SELECTED_SENSORS
Reg 0x23:
Definition mpu6050.h:38
uint8_t MPU_ADDR
MPU address, assuming AD0 pin is low otherwise = 0x69.
Definition mpu6050.h:24
uint8_t INT_PIN_CFG
Reg 0x37: Active LO, open drain, pulsed 50us, cleared any read operation.
Definition mpu6050.h:40
uint16_t SAMPLE_RATE
Reg 0x19: set sensors sample rate in Hz.
Definition mpu6050.h:26
uint16_t GYRO_OUT_RATE
Reg 0x1A: in Hz, depending on DLPF value.
Definition mpu6050.h:32
uint8_t DLPF_BW
Reg 0x1A: Digital Low-Pass Filter bandwidth. values in { 250, 200, 100, 50, 20, 10,...
Definition mpu6050.h:28
this data structure collects result when an I2C transfer is done. It gives a more verbose error descr...
Definition hw_i2c.h:33
measured sensor value after scale correction
Definition mpu6050.h:78
float gyro_x
rotation speed(x)
Definition mpu6050.h:88
float g_z
acceleration (z)
Definition mpu6050.h:84
float g_y
acceleration (y)
Definition mpu6050.h:82
float temp_out
chip temperature
Definition mpu6050.h:86
float gyro_z
rotation speed(z)
Definition mpu6050.h:92
float g_x
acceleration (x)
Definition mpu6050.h:80
float gyro_y
rotation speed(y)
Definition mpu6050.h:90
raw data as they are captured by sensor
Definition mpu6050.h:56
int16_t gyro_x
rotation speed(x)
Definition mpu6050.h:66
int16_t g_y
acceleration (y)
Definition mpu6050.h:60
int16_t temp_out
chip temperature
Definition mpu6050.h:64
int16_t g_z
acceleration (z)
Definition mpu6050.h:62
int16_t g_x
acceleration (x)
Definition mpu6050.h:58
int16_t gyro_y
rotation speed(y)
Definition mpu6050.h:68
int16_t gyro_z
rotation speed(z)
Definition mpu6050.h:70