Welcome to MSPM0 Smart Robot Car repository
11.MPU6050 data fusion
MPU6050 Data Fusion
MPU6050 Data Fusion1. Software and Hardware2. Basic Principles2.1 Hardware Schematic2.2 Physical Connection Diagram2.3 Control Principle3. Project Configuration3.1 Description3.2 Pin Configuration4. Main Functions4.1 User Functions5. Experimental Phenomenon
This tutorial demonstrates: how to print MPU6050 data fusion through serial port.
1. Software and Hardware
KEIL5
MSPM0G3507 Development Board
MPU6050 Module
Type-C data cable or DAP-Link
For programming download or simulation to the development board
Serial Port Assistant
Receive and print serial port data
2. Basic Principles
2.1 Hardware Schematic
.png)
2.2 Physical Connection Diagram
.png)
2.3 Control Principle
| (Schematic Name) | Control Pin | Specific Meaning |
|---|---|---|
| I2C2_SCL | PB10 | I2C Clock End |
| I2C2_SDA | PB11 | I2C Data End |
| ADO | PE1 | Controls the lowest bit of I2C address |
| INT | PE0 | Whenever MPU6050 has data output, the INT pin has corresponding level changes. It can trigger external interrupt as control cycle. |
Attitude Angles (Euler Angles) pitch yaw roll The aircraft's attitude angles do not refer to a specific angle, but are a general term for three angles. They are: pitch, roll, yaw. You can imagine them as the angles formed by the aircraft rotating around the X, Y, and Z axes respectively.
pitch: pitch, rotating the object around the X axis (localRotationX)
yaw: heading, rotating the object around the Y axis (localRotationY)
roll: roll, rotating the object around the Z axis (localRotationZ)

We read six data from MPU6050 through I2C (three-axis acceleration AD values, three-axis angular velocity AD values) and obtain Pitch, Roll, Yaw angles after attitude fusion.
The fusion algorithm used in this experiment is Quaternion Method:
Quaternions, a mathematical concept invented by Irish mathematician [William Rowan Hamilton] (1805-1865) in 1843. Quaternion multiplication does not follow the commutative law.
A quaternion is a number of the form
,
is a real number
is called the two-norm of the quaternion.
3. Project Configuration
3.1 Description
You can refer to the basic tutorial to complete the development environment setup.
3.2 Pin Configuration



4. Main Functions
4.1 User Functions
Function: MPU6050_Pose()
| Function Prototype | void Get_EulerAngles(void) |
|---|---|
| Function Description | Get MPU6050 data and send through serial port |
| Input Parameters | None |
| Return Value | None |
Function: MPU6050_Init
| Function Prototype | char MPU6050_Init(void) |
|---|---|
| Function Description | MPU6050 initialization |
| Input Parameters | None |
| Return Value | Judge whether MPU6050 is detected |
5. Experimental Phenomenon
After downloading the program, open the serial port assistant and set the parameters as shown in the figure below. Then open the serial port to receive the raw data of MPU6050.
For program download, refer to 【3. Development Environment Setup and Usage: 3. Uniflash burning】
The effect is as follows:
