yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
520 Motor📖
1.About motor
  • About motor
2.ROS robot control board drive
  • 2.1 Control motor
  • 2.2 Timer captures encoder data
  • 2.3 PID control robot car
  • 2.4 Kinematic Analysis-Mecanum wheel structure
  • 2.5 Kinematic Analysis-Ackerman structure
  • 2.6 Kinematic Analysis-4WD structure
3.STM32 Self-balancing car tutorials
Get started quickly
  • 03.P, PI, PD controller theory
  • 01.Balancing car assembly
  • 02.Get started quicklyy
  • 03.Balance car interface description
  • 04.Common Problem Analysis
  • 05.Balance Car V2 Library Function Development Manual
Environment construction and development
  • 01.MDK-ARM installation
  • 02.STM32CubeIDE installation
  • 03.Common driver installation
  • 04.Download the program
  • 05.MDK-ARM project usage
  • 06.Program simulation
Robot car PID control course
  • 01.PID basic concept
  • 02.PID example analysis
  • 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)
Robot car basic course
  • 01.Car parameter adjustment
  • 02.Ultrasonic obstacle avoidance
  • 03.Ultrasonic follow
  • 04.Bluetooth remote control
  • 05.Load balance
Robot car LQR control
  • Robot car LQR control
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
Mathematical model
  • Balance car mathematical model
4.4-channel motor drive module
Introduction and Debug
  • 1.Introduction to 4-channel motor drive board
  • 2.Control command
  • 3.Motor introduction and usage
  • 4.PC host
IIC communication
  • For Arduino
  • For ESP32
  • For Jetson NANO
  • For MSPM0G3507
  • For MSPM0G3519new
  • For PICO2
  • For RDK X5
  • For RPi5
  • For STM32
USART communication
  • For Arduino
  • For ESP32
  • For Jetson NANO
  • For MSPM0G3507
  • For MSPM0G3519new
  • For PICO2
  • For RDK X5
  • For RPi5
  • For STM32
5.2-channel motor drive module
For MSPM0G3507
  • 1.AT8236 drive tutorials
  • 2.TB6612 drive tutorials
For MSPM0G3519
  • 1.AT8236 drive tutorialsnew
  • 2.TB6612 drive tutorialsnew
Download
  • Model File
  • Annex_ROS_robot_board
  • Annex_STM32_balancing_car
  • Annex_4channel_motor_drive
  • Annex_2channel_motor_drive
Download ZIP

Welcome to 520 Motor 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
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文