yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
Self-balancing Robot Car📖
00.Get started quickly
  • 01.Balance car manual
  • 02.Balancing car assembly
  • 03.Get started quickly
  • 04.Balance car interface description
  • 05.Common Problem Analysis
  • 06.Balance Car V2 Library Function Development Manual
01.Environment development
  • 01.MDK-ARM installation
  • 02.STM32CubeIDE installation
  • 03.Common driver installation
  • 04.Download the program
  • 05.MDK-ARM project usage
  • 06.Program simulation
  • 07. VSCode Installation
02.STM32 getting started course
  • 01.Project creation
  • 02.LED Control(GPIO)
  • 03.Buzzer control(GPIO)
  • 04.Button control(EXTI)
  • 05.Serial communication(USART)
  • 06.Voltage detection(ADC)
  • 07.Basic timer(TIM)
  • 08.Universal timer(TIM)
  • 09.Advanced Timer(TIM)
  • 10.I2C Communication(I2C)-OLED
  • 11.SPI communication(SPI)-2.4G handle
  • 12.Independent Watchdog (IWDG)
  • 13.Window Watchdog (WWDG)
  • 14.DMA-USART
  • 15.DMA-I2C
03.STM32 expansion course
  • 01.Battery voltage detection (ADC)
  • 02.Ultrasonic module-measuring distance (TIM)
  • 03.Motor drive+encoder (TIM)
  • 04.OLED Data-Display(I2C)
  • 05.MPU6050-Data Read (I2C)
  • 06.Bluetooth module-Data reading (USART)
  • 07.2.4G handle-Data reading (SPI)
  • 08.Tracking module-Read status (GPIO)
  • 09.CCD module-Reading data (ADC)
  • 10.Electromagnetic module-Reading data (ADC)
  • 11.K210 module-Serial communication (USART)
  • 12.Tmini-Plus lidar-Reading data (USART)
04.Robot car PID control course
  • 01.PID basic concept
  • 02.PID example analysis
  • 03.P, PI, PD controller theory
  • 04.Position PID
  • 05.Incremental PID
  • 06.Cascade PID
  • 07.Balance principle of car
  • 08.Car upright control (PD)
  • 09.Car speed ​​control (PI)
  • 10.Car steering control (PD)
  • 11.Got angle and angular velocity (DMP algorithm)
  • 12.Got angle and angular velocity (Kalman filter algorithm)
  • 13.Got angle and angular velocity(Complementary filter algorithm)
05.Robot car basic course
  • 01.Car parameter adjustment
  • 02.Ultrasonic obstacle avoidance
  • 03.Ultrasonic follow
  • 04.Bluetooth remote control
  • 05.Load balance
06.Robot car advanced course
  • 01.4-channel tracking
  • 02.4-channel tracking avoid
  • 03.2.4G handle control
  • 04.CCD tracking
  • 05.CCD tracking avoid
  • 06.Electromagnetic tracking
  • 07.K210-QR code recognition
  • 08.K210-Color line tracking
  • 09.K210-Color follow
  • 10.K210-Self learning
  • 11.K210-Number recognition
  • 12.Lidar avoid
  • 13.Lidar guard
  • 14.Lidar follow
  • 15.Lidar patrol
  • 16.Lidar wall tracking-straight line
  • 17.Lidar wall tracking-multiple walls
  • 18. DIY Automatic driving car
07.Robot car LQR control
  • Robot car LQR control
08.Circuit design
  • 01.Overall circuit design
  • 02.STM32 minimum system
  • 03.Serial port circuit design
  • 04.Power circuit design
  • 05.MPU6050 Circuit Design
  • 06.Motor drive circuit design
09.Mathematical model
  • Mathematical model
10.Expand course
  • Autonomous Driving
Download
  • APP(Android)
  • Codes
  • Hardware-Info
  • SCH
  • Software Tools
  • STM32_Chip_DataSheet
  • 3D_Model_File
  • Video_PPT
Download ZIP

Welcome to Self-balancing Robot Car repository

11.Got angle and angular velocity (DMP algorithm)

Got angle and angular velocity (DMP algorithm)

Got angle and angular velocity (DMP algorithm)DMP algorithmQuaternion solutionQuaternion to Euler angleQuaternionEuler angleConversion formulaSolution codeSoftware code

The tutorial introduces the use of DMP algorithm to calculate the attitude angle.

xxxxxxxxxx
The MPU6050 module can detect the motion data of the three-axis acceleration, the three-axis gyroscope, and the temperature data.

DMP algorithm

DMP is the motion engine inside the MPU6050, the full name of which is Digital Motion Processor. It directly outputs quaternions, which can reduce the workload of the peripheral microprocessor and avoid tedious filtering and data fusion.

Motion Driver is a software package for its motion sensors from Invensense. It is not all open source. The core algorithm part is compiled into a static link library for ARM processors and MSP430 processors, and is suitable for sensors such as MPU6050, MPU6500, MPU9150, and MPU9250.

Quaternion solution

Using the MPU6050 driver library provided by InvenSense, the raw data will be converted into quaternion output. We need to calculate the quaternion and finally get the attitude data (Euler angle): heading angle (Yaw), roll angle (Roll) and pitch angle (Pitch).

image-20240806150245483

Quaternion to Euler angle

Quaternion

Quaternion is a mathematical tool used to represent three-dimensional rotation, but it is not very intuitive to observe.

Quaternions consist of four real numbers, and the basic representation is as follows:

q=q0+q1∗i+q2∗j+q3∗k

Euler angle

Euler angle is a way to describe the rotation state of an object in three-dimensional space. It is usually composed of three angle values: yaw, roll, and pitch, which is convenient for observing posture.

Conversion formula

xxxxxxxxxx
pitch = asin(-2 * q1 * q3 + 2 * q0* q2)
roll = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1)
yaw = atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3)

Solution code

MPU6050 DMP outputs the quaternion after attitude settlement, in q30 format, magnified 2^32 times (q30 = 2^32 = 1073741824).

​x
void Read_DMP(void)
{
unsigned long sensor_timestamp;
unsigned char more;
long quat[4];

dmp_read_fifo(gyro, accel, quat, &sensor_timestamp, &sensors, &more); //Read DMP data
if (sensors & INV_WXYZ_QUAT )
{
//Quaternion
q0=quat[0] / q30;
q1=quat[1] / q30;
q2=quat[2] / q30;
q3=quat[3] / q30;
Roll = asin(-2 * q1 * q3 + 2 * q0* q2)* 57.3; //Calculate the roll angle
Pitch = atan2(2 * q2 * q3 + 2 * q0 * q1, -2 * q1 * q1 - 2 * q2* q2 + 1)* 57.3; //Calculate the pitch angle
Yaw = atan2(2*(q1*q2 + q0*q3),q0*q0+q1*q1-q2*q2-q3*q3) * 57.3; //Calculate the yaw angle
}
}

Software code

Balance car PID control basics: 08-13 tutorial only provides one project file.

Product supporting materials source code path: Attachment → Source code summary → 3.PID_Course → 08-13.Balanced_Car_PID
Car steering control (PD)
Got angle and angular velocity (Kalman filter algorithm)

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文