STM32 wildfire open source balance car (5) externally built PID and MPU6050 initialization

Wildfire open source balance bike official website section

https://www.firebbs.cn/forum.php?mod=forumdisplay&fid=129&page=1

Reference

No

Reference video (this group leader is good)

https://www.bilibili.com/video/BV1j7411z7uX

Hardware platform

Development Platform

KEIL5, STM32F103X main control, SWD download for the program (any downloader will do, you can download it, and you can download it with a serial port)

Development (1) 

P ratio: Improve the response speed and reduce the static error (because the EP value is larger than EI and ED, the larger the value will contribute to the larger value, if it is too large, it will hit the street directly, and if it is too small, it will never reach the set point)

(Static error refers to the difference between the ideal value and the true value. If the ratio is too large, it will cause the system to oscillate, but if you want to reach the target value, you must oscillate around this target value, and then gradually reduce the oscillation amplitude through other I and D. It's too big, he just shakes it off (not controlled by ID))

 

I Integral: Eliminate steady-state errors (integration is accumulation, seeking area, mainly accumulating errors)

A small amount of error will become very large due to accumulation, until your error is eliminated to 0

 

D Differential: reduce oscillation, and overshoot (differentiation is derivative, derivative is the rate of change)

The greater the differential, the greater the resistance and the weaker the amplitude value of the previous EP ratio (may also contain the EI integral value)

 

Some netizens concluded

Proportion is to consider the current, integration is to review history (cumulative error), and differentiation is to predict the future

 

 

The upright ring makes the angle of the trolley approach 0, and the trolley stands upright (PD: Proportional Differential Control)

Vertical ring: input (1. given angle. 2 angle feedback), output (PWM directly controls the car)

 

Speed ​​loop, let the motor speed approach 0, the motor does not rotate (PI: proportional integral control)

Speed ​​loop: input (1. given speed. 2 speed feedback), output (angle value, desired speed input for vertical loop)

 

Do MPU6050 first

PB8 and 9 are used

 

\

MPU6050 here sets the interrupt frequency to 50HZ, (10ms interrupt once to update the motor PWM)

 

Handle the interrupt of MPU6050 every 10ms (we use PD2)

Upright ring PD control

Speed ​​loop PI control

The steering ring restricts the steering of the car when it is upright

Continue to write 10ms MPU6050 interrupt content

 

Now change the following OLED pins PB10 and PB11

 

Write the main function

 

 

Guess you like

Origin blog.csdn.net/jwdeng1995/article/details/108177594