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

08.Car upright control (PD)

Car upright control (PD)

Car upright control (PD)Physical analysisPD controllerImplementation codeSoftware code

The tutorial mainly introduces the upright control of the balance car.

Physical analysis

Assuming that when the car tilts to the right, the wheels of the car are controlled to make the car accelerate, and the acceleration is a.

Force analysis diagram

image-20240812181107286

Force analysis

If the force of the inverted pendulum is analyzed with the wheel of the car as the reference system (non-inertial reference system), the ball above the car will be subjected to an inertial force that is opposite to the acceleration of the wheel and proportional to the acceleration.

F=mgsinθ−macosθ≈mgθ−mk1θ
xxxxxxxxxx
θ is very small → sinθ = 0, cosθ = 1; k_1 is the proportionality coefficient between acceleration a and the inclination angle of the car

If k1 > g, the direction of the restoring force is opposite to the direction of displacement.

In order to allow the inverted pendulum to return to the vertical position and stabilize as quickly as possible, it is necessary to increase the damping force; the increased damping force is proportional to the speed of the deflection angle and in the opposite direction, so the formula can be changed to:

F=mgθ−mk1θ−mk2θ′=mgθ−m(k1θ+k2θ′)
xxxxxxxxxx
(k_2 is the proportionality coefficient between damping force and angular velocity, θ' is the differential of the angle (i.e. angular velocity))

According to the inverted pendulum model, the algorithm for controlling the acceleration of the car wheel can be obtained: as long as k1 > g, k2 > 0, the car can be balanced.

a=k1θ+k2θ′

According to the above content, establish the proportional differential negative feedback control of the speed to make the balance car maintain stable conditions through closed-loop control.

xxxxxxxxxx
The MPU6050 measures the tilt angle θ and angular acceleration θ' of the balance car. The PD controller calculates the control signal based on the measured tilt angle and angular acceleration to adjust the speed of the balance car so that the vehicle can remain upright.

PD controller

The main function of differential (D) control in PID control is to reduce the dynamic error and oscillation of the system, and the main function of integral (I) control is to eliminate static error.

Proportional control (P) can quickly reach the set speed, and differential (D) control is equivalent to damping force, which can effectively suppress the vibration of the car model.

Implementation code

​x
int Balance_PD(float Angle,float Gyro)
{
float Angle_bias,Gyro_bias;
int balance;
Angle_bias=Mid_Angle-Angle; //Find the median value of the balance angle and mechanical related
Gyro_bias=0-Gyro;
balance=-Balance_Kp/100*Angle_bias-Gyro_bias*Balance_Kd/100; //Calculate the motor PWM PD control for balance control kp is the P coefficient kd is the D coefficient

return balance;
}

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
Balance principle of car
Car speed ​​control (PI)

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/中文