Emakefun MPU-6050 1.0
Loading...
Searching...
No Matches
mpu6050.h
1#include <stdint.h>
2
3#include "utility/I2cDevice.h"
4
5/**
6 * @class Mpu6050
7 * @example get_acceleration.ino
8 * @example get_euler.ino
9 */
10
11class Mpu6050 {
12 public:
13 /**
14 * @brief Default I2C device address for the MPU6050.
15 */
16 enum : uint8_t { kDefaultDeviceI2cAddress = 0x68 };
17
18 /**
19 * @brief Euler angles (yaw, pitch, and roll).
20 */
21 struct Euler {
22 float yaw; /**< Yaw angle. */
23 float pitch; /**< Pitch angle. */
24 float roll; /**< Roll angle. */
25 };
26
27 /**
28 * @brief Acceleration in x, y, and z directions.
29 */
30 struct Acceleration {
31 int16_t x; /**< Acceleration in the x direction. */
32 int16_t y; /**< Acceleration in the y direction. */
33 int16_t z; /**< Acceleration in the z direction. */
34 };
35
36 /**
37 * @brief Constructor.
38 * @param device_i2c_address The I2C device address for the MPU6050.
39 */
40 explicit Mpu6050(uint8_t device_i2c_address = kDefaultDeviceI2cAddress);
41
42 /**
43 * @brief Sets up the MPU6050.
44 * @return true if setup is successful, false otherwise.
45 */
46 bool Setup();
47
48 /**
49 * @brief Updates information from fifo data of mpu6050.
50 * @return true if the update is successful, false otherwise.
51 */
52 bool UpdateMotionInfo();
53
54 /**
55 * @brief Gets the Euler angles.
56 * @return Euler angles (yaw, pitch, and roll).
57 */
58 Euler GetEuler() const;
59
60 /**
61 * @brief Gets the acceleration values.
62 * @return Acceleration in x, y, and z directions.
63 */
65
66 private:
67 /**
68 * @brief Quaternion representation.
69 */
70 struct Quaternion {
71 float w = 0.0; /**< Quaternion w value. */
72 float x = 0.0; /**< Quaternion x value. */
73 float y = 0.0; /**< Quaternion y value. */
74 float z = 0.0; /**< Quaternion z value. */
75 };
76
77 /**
78 * @brief Gravitational force values.
79 */
80 struct Gravity {
81 float x = 0.0; /**< Gravitational force in the x direction. */
82 float y = 0.0; /**< Gravitational force in the y direction. */
83 float z = 0.0; /**< Gravitational force in the z direction. */
84 };
85
86 /**
87 * @brief Retrieves the number of available FIFO (First In, First Out) bytes.
88 * @return The number of available FIFO bytes.
89 */
90 uint16_t GetFifoCount();
91
92 /**
93 * @brief Retrieves FIFO (First In, First Out) bytes.
94 * @param data A pointer to the buffer to store the FIFO bytes.
95 * @param length The length of the buffer.
96 */
97 void GetFifoBytes(uint8_t *data, uint8_t length);
98
99 /**
100 * @brief Retrieves the current FIFO packet.
101 * @param data A pointer to the buffer to store the FIFO packet.
102 * @param length The length of the buffer.
103 * @return true if the retrieval is successful, false otherwise.
104 */
105 bool GetCurrentFifoPacket(uint8_t *data, const uint8_t length);
106
107 I2cDevice i2c_device_; /**< I2C device for communication. */
108 Quaternion quaternion_; /**< Current quaternion values. */
109 Gravity gravity_; /**< Current gravitational force values. */
110};
Definition mpu6050.h:11
Euler GetEuler() const
Gets the Euler angles.
Definition mpu6050.cpp:3223
bool Setup()
Sets up the MPU6050.
Definition mpu6050.cpp:3123
Acceleration GetAcceleration() const
Gets the acceleration values.
Definition mpu6050.cpp:3242
bool UpdateMotionInfo()
Updates information from fifo data of mpu6050.
Definition mpu6050.cpp:3204
Acceleration in x, y, and z directions.
Definition mpu6050.h:30
int16_t y
Definition mpu6050.h:32
int16_t x
Definition mpu6050.h:31
int16_t z
Definition mpu6050.h:33
Euler angles (yaw, pitch, and roll).
Definition mpu6050.h:21
float pitch
Definition mpu6050.h:23
float yaw
Definition mpu6050.h:22
float roll
Definition mpu6050.h:24