Depth study of algorithms - to abandon the formula, from the principle truly understand PID control

PID control should be regarded as a widely used algorithm of the control. A small element temperature control, large UAV flight attitude control and flight speed, etc., may be used PID control. Here we come to understand the principle of PID control.

PID (proportion integration differentiation) in fact refers to the proportional, integral, derivative control. First pictures and formulas laid out, do not understand it does not matter. (See the beginning of this algorithm, formula can read, how to write code specifically how to use also know that, but just do not know the principle, I do not know why use proportion, differentiation, integration of these three items in order to achieve the best control, with which Why not two, with three items where can Fortunately, what the role of each item each)

Here Insert Picture Description
Here Insert Picture Description
In general, obtained when the output system, the output through proportional, integral and differential three kinds of operation mode, to the input of, whereby the behavior of the control system, following a simple example to illustrate.

Proportional control algorithm

Let's start with the most simple proportional PID control, set aside the other two aside. Or use a classic example of it. Suppose I have a tank, the ultimate aim is to ensure control of water level in the tank is always maintained at a height of 1 meter. Suppose the initial moment, the water level in the tank is 0.2 m, then the error is the existence of an error between the target level and the level at the current time, and the error of 0.8. This time, assume that a person standing next to, to the person by the cylinder Riga way to control the water level. If a simple proportional control algorithm, u refers to the amount of water added is proportional to the error and error.

Soku: u = kp * error

Is assumed to take 0.5 kp, then t = 1 (indicating the first time with water, is first applied to the control system), then u = 0.5 * 0.8 = 0.4, so that amount of water was added to make the basis of the level 0.2 on the ascending 0.4, 0.6 ..

Then, t = 2 time (2nd application control), the current level is 0.6, so the error is 0.4. u = 0.5 * 0.4 = 0.2, the water level will rise again 0.2, 0.8.

So so the cycle continues, it is to run the algorithm method of proportional control. We can see, the water level will eventually reach one meter we need.

However, the proportion of control alone there are some shortcomings, one of which is - steady-state error! (I also read a lot and think a long time before what figured why there is a steady-state error and the steady-state error).

Like the above example, kp according to different values, the system will last up to 1 meter, but the quick arrival of large kp, kp a little slower to arrive. There will be no steady-state error. However, consider another case, assume that the process of adding water in the tank, the presence of water leakage, it is assumed during each addition of water, the water will miss the height of 0.1 m.

Still assuming 0.5 kp take, then there will be some kind of case, assuming that after several add water, the water level in the tank to 0.8, the water level will not be converted! ! ! Because the water level is 0.8, the error error = 0.2. Therefore, the amount of each added to the tank water is u = 0.5 * 0.2 = 0.1. At the same time, each addition of water tank 0.1 m will flow out of the water! ! ! Added water and the water flows out of phase offset, the water level will not change! !

In other words, my goal is to one meter, but in the end the system reaches 0.8 meters of water is no longer changed, and the system has stabilized. The resulting error is a steady state error.

(In reality, the situation is similar to tank leaks tend to be more common, such as motion control car, friction is the equivalent of "leaking" to control the robotic arm, UAV flight, and consumption of all types of resistance can understand in the present embodiment the "leakage")

Therefore, a separate proportional control, and in many cases insufficient.

Integral control algorithm

Or with the above example, if only proportional, transient errors can be found, on the card in the final level of 0.8. Thus, in the control, we re-introduced a component, the integral component and is proportional error. So, proportional + integral control algorithm is:

u=kp*error+ ki∗∫ error

Is described with the above example, the first error of errors is 0.8, the error is 0.4 second, so far, the integration error (discrete case cumulative integration is actually doing), ∫error = 0.8 + 0.4 = 1.2. control the amount of this time, except for that part of the scale, there is a part of the integral term is multiplied by the coefficient ki. The error due to the integral term will be accumulated in front of several, it is possible to eliminate the steady state error is very good (assuming in the case where only the proportional term, the steady state error in the card system, i.e. in the above example 0.8, since Add the integral term is present, the input will be increased, so that the water level in the tank may be greater than 0.8, 1.0 and gradually reach the target.) What is the role of the integral term.

Differential control algorithm

For a further example, consider the case where the brakes. Smooth driving of the vehicle, when found in front of a red light, in order to make a smooth ride, tens of meters ahead substantially relax the accelerator and brakes. When the vehicle from the stop line is very close, then hard on the brakes, stop the vehicle. The whole process can be seen as a strategy to control the differential added.

Differential plainly in discrete case, as the difference of error, it is the difference between time t and time t-1 of the error, i.e., u = kd * (error (t) -error (t-1)), where kd is the a coefficient term. It can be seen during braking, because the error is getting smaller and smaller, so this differential controls must be negative, adding a negative item in control, his role is to prevent the presence of vehicles because of brake untimely break through the line. It is understood from the common sense, the more close to the stop line, the more we should pay attention to the brakes, the car can not get over the line, so the effect of the differential term, it can be understood as a brake when the car speed away from the stop line and also quickly close when the absolute value of the derivative term (actually a negative number) will be great, thus indicating that the brakes should be forced to allow the car to stop.

Water was added to the above example to switch to the tank, that is, when found in the water tank 1 is about to close when the differential term is added, the water supply tank can be prevented more than 1 m of water was added to a height, that the white-reducing control process concussion.

Now look back to this formula, it is clear

Here Insert Picture Description
The first term in parentheses is the ratio, the second term is an integral term, the third term is a derivative term, just in front of a coefficient. In many cases, only need to use the discrete time, the control can be turned into
Here Insert Picture Description
the front of each item has coefficients that are needed to experiment to try and determine, for convenience, these coefficients unified look:
Here Insert Picture Description
this to see a lot clearer, and each item in front of proportion, differentiation, integration has a coefficient and discrete formula, it is suitable programming.

Talking about this, the principles and methods of PID say finished, and the rest is practice. In true engineering practice, the most difficult is to determine if the coefficient of three items, which requires a lot of experiments and experience to decide. Through trial and correct way of thinking, you can select the appropriate coefficient to achieve good control.

If you have any comments or ideas, please leave me a message, we explore together, progress together! ! !

Published 72 original articles · won praise 159 · views 70000 +

Guess you like

Origin blog.csdn.net/weixin_44212493/article/details/104334244