[Balance car production] (7) Cascade PID tuning and balance results display (super detailed)

  Hello everyone, I am Xiaozheng. In this article, I will give a detailed explanation of PID tuning , so that each friend can have a clearer understanding of how to adjust the three parameters of proportional, integral, and derivative.

1. Tuning steps

  1. Establishing the mechanical median
  2. Upright ring (inner ring)-Kp polarity, Kp size, Kd polarity, Kd size
  3. Speed ​​loop (outer loop)-Kp&Ki polarity, Kp&Ki size
  4. Steering ring-coefficient polarity, coefficient size

Second, the mechanical median

  Put the trolley on the bottom surface, rotate the balance trolley around the motor shaft from front to back and from back to front, and the median value of the angle that the trolley falls to the other side twice is the mechanical median.
Example: Pour backwards at 2 degrees, and backwards at about -3 degrees. Here I take the mechanical median value of -1 degrees .

float Med_Angle=-1.0;      // 机械中值,能使得小车真正平衡住的角度 

Insert picture description here

Figure 1 Falling backwards at about 2 degrees (Y-axis, ie Roll)

Insert picture description here

Figure 2 Pour forward at about -3 degrees (Y axis, namely Roll)

Three, upright ring

1. Kp polarity:

Wrong polarity : When the car falls, the wheels will turn in the opposite direction, which will cause the car to accelerate and fall down.
The polarity is correct : which way the trolley falls, the wheels are driven to ensure that the trolley tends to stand upright.

2. Kp size:

Kp keeps increasing until there is a large low frequency oscillation. (I.e. the car shakes when the car is balanced)
Note: The absolute value of Kp ranges from 150 to 350. When I set it to 320, there will be low-frequency oscillations, and Kp can be slightly increased. When large-scale low-frequency oscillations occur, it means that Kp is sufficient Big, it's time to introduce the differential term.

3. Kd polarity:

Incorrect polarity : pick up the trolley and rotate it around the motor shaft, the wheels rotate in the reverse direction, without following.
The polarity is correct : pick up the trolley and rotate it around the motor shaft, the wheels rotate in the same direction, and follow.

4.Kd size:

Kd keeps increasing until a high frequency oscillation occurs. (That is, the trolley will vibrate violently when touched.)
Note: The absolute value of Kd is within the range of 0.1 to 0.9. When I set it to 0.8, high-frequency oscillation occurs. At this time, the motor should be turned off in time to prevent the motor and drive from burning.
  After the upright ring is debugged, multiply all the established parameters by 0.6 as the final parameter.
  Reason : The parameters obtained before are all the maximum values ​​of Kp and Kd. According to engineering experience, the ideal parameter of the balance trolley is the maximum parameter multiplied by 0.6.
  Result : After taking 0.6, the car shake disappeared, but at the same time the erection effect became worse. You can get better performance by adding the speed loop below.
I finally adjusted the Kp and Kd parameters of the upright ring:

float 
  Vertical_Kp=200,
  Vertical_Kd=0.5;     // 直立环Kp、Kd

Fourth, the speed loop

1. Points to note

(1)
 When adjusting [speed loop parameter polarity], you need to remove [vertical loop calculation];
 when adjusting [speed loop parameter size], you need to introduce [vertical loop calculation].
(2)
 [Steering ring operation] is always a state that is removed. If the steering ring has been adjusted in advance, it will not have a big impact if it is not commented.

2.Kp & Ki :

Linear relationship : Ki=(1/200)*Kp, just adjust Kp.

3. Kp&Ki polarity: (upright ring note)

Incorrect polarity : Manually rotate one of the wheels, and the other wheel will rotate in the opposite direction at the same speed-typical negative feedback.
The polarity is correct : turn one of the wheels manually, and the two wheels will accelerate in the same direction until the maximum motor speed-typical positive feedback.

4.Kp & Ki Large / Small:

Increase Kp&Ki until: While the trolley maintains balance, the speed is close to 0, and the return effect is good.
Note: The absolute value of Kp ranges from 0.1 to 0.9.

I finally adjusted the Kp and Kd parameters of the speed loop:

float 
  Velocity_Kp=0.30,
  Velocity_Ki=0.0015;   // 速度环Kp、Ki(正反馈)

Five, steering ring

1. Kp polarity:
wrong polarity : pick up the trolley and rotate the trolley around the Z axis. The rotation trend of the two wheels is consistent with the rotation trend of the trolley-typical positive feedback.
The polarity is correct : pick up the trolley and rotate the trolley around the Z axis. The rotation trend of the two wheels is opposite to the rotation trend of the trolley-typical negative feedback
2. Kp size:
increase Kp until the effect of walking in a straight line is better without violent Jitter.
Note: Kp is approximately in the range of 0.1 to 0.9.

I finally adjusted the Kp and Kd parameters of the steering ring:

float 
  Turn_Kp=-0.6;

Six, display

After the PID parameter adjustment is completed, the physical display is as follows:

Balance trolley (pure balance)

Seven, summary

  The above series of articles are all the teaching of the balance car (pure balance) series, and the detailed explanation of using the Bluetooth module to remotely control the balance car will be updated in the future . Interested friends, please pay attention!
(1) Hardware schematic:
URL: https://pan.baidu.com/s/12LstSbIAEuiyO8rI9XfSFg
Extraction code: rddh
(2) Program code:
https://download.csdn.net/download/weixin_44270218/15201156
(no points Friends of you can leave a message in the comment area, and the Xiaozheng will send it to you privately)

  The above is the seventh lecture of the balance car series-Cascade PID tuning. If there is an error in the article or your friends have questions about the above content, you are welcome to leave a message in the comment area. Xiaozheng will reply to you as soon as possible after seeing it!
[Balance car production] (8) Bluetooth remote control and balance results display (super detailed)
https://blog.csdn.net/weixin_44270218/article/details/113806544

Guess you like

Origin blog.csdn.net/weixin_44270218/article/details/113786386