My Project
 All Classes Functions Variables Pages
MPU6050.h
1 #ifndef MAIN_MPU6050_H_
2 #define MAIN_MPU6050_H_
3 
4 #include <math.h>
5 #include "I2C.h"
6 #include <driver/gpio.h>
7 
18 class MPU6050 {
19 public:
20  MPU6050();
21  virtual ~MPU6050();
22 
26  short getAccelX() const {
27  return accel_x;
28  }
29 
33  short getAccelY() const {
34  return accel_y;
35  }
36 
40  short getAccelZ() const {
41  return accel_z;
42  }
43 
47  short getGyroX() const {
48  return gyro_x;
49  }
50 
54  short getGyroY() const {
55  return gyro_y;
56  }
57 
61  short getGyroZ() const {
62  return gyro_z;
63  }
64 
73  uint32_t getMagnitude() {
74  return sqrt(accel_x * accel_x + accel_y * accel_y + accel_z * accel_z);
75  }
76 
77  void init(gpio_num_t sdaPin = I2C::DEFAULT_SDA_PIN, gpio_num_t clkPin = I2C::DEFAULT_CLK_PIN);
78  void readAccel();
79  void readGyro();
80 
81 private:
82  I2C* i2c;
83  short accel_x, accel_y, accel_z;
84  short gyro_x, gyro_y, gyro_z;
85  bool inited;
86 
87 };
88 
89 #endif /* MAIN_MPU6050_H_ */
short getAccelZ() const
Get the Z acceleration value.
Definition: MPU6050.h:40
void init(gpio_num_t sdaPin=I2C::DEFAULT_SDA_PIN, gpio_num_t clkPin=I2C::DEFAULT_CLK_PIN)
Initialize the MPU6050.
Definition: MPU6050.cpp:87
static const gpio_num_t DEFAULT_SDA_PIN
The default SDA pin.
Definition: I2C.h:24
short getGyroY() const
Get the Y gyroscopic value.
Definition: MPU6050.h:54
short getGyroX() const
Get the X gyroscopic value.
Definition: MPU6050.h:47
short getGyroZ() const
Get the Z gyroscopic value.
Definition: MPU6050.h:61
Driver for the MPU6050 accelerometer and gyroscope.
Definition: MPU6050.h:18
short getAccelY() const
Get the Y acceleration value.
Definition: MPU6050.h:33
static const gpio_num_t DEFAULT_CLK_PIN
The default Clock pin.
Definition: I2C.h:29
short getAccelX() const
Get the X acceleration value.
Definition: MPU6050.h:26
void readAccel()
Read the acceleration value from the device.
Definition: MPU6050.cpp:38
Interface to I2C functions.
Definition: I2C.h:19
uint32_t getMagnitude()
Get the magnitude of the acceleration.
Definition: MPU6050.h:73
virtual ~MPU6050()
Destory the class instance.
Definition: MPU6050.cpp:27
MPU6050()
Construct an MPU6050 handler.
Definition: MPU6050.cpp:16
void readGyro()
Read the gyroscopic values from the device.
Definition: MPU6050.cpp:62