Understanding and Implementation of PID Algorithm

One of the most typical examples of understanding the PID control algorithm is the problem of a leaking water tank. There are many posts on the Internet explaining PID that will cover this example. Here I also illustrate my own understanding of PID with this example.

        There is a leaking tank, and the rate of leaking is not constant. Then we have a bucket, and we can control adding water to the tank or scooping water out of the tank. Additionally we can detect horizontal planes. Now our purpose is to control the horizontal plane to stabilize on any plane we want.

        Note that we need to be in a closed loop system to use PID. What is a closed-loop system, that is, there is input and feedback, the input is the ability to input a quantity to influence and control our system, and the feedback is that we need to be able to know the state of the things we ultimately control. In this leaky water tank system, the input is the water bucket. We can add water to the water tank or scoop out water from the water tank to affect the level of our water tank. In the case of feedback, we must be able to measure the level of the water tank. , know what the level is. The schematic diagram of the control system is as follows:

        Let's look at the formula:

        Where Kp is the proportional coefficient, Ti is the integral time constant, and Td is the integral time constant.

Proportional Control Understanding

        The first is proportional control. Proportional control is like adding or scooping water from a bucket to a tank. Suppose we need to stabilize the horizontal plane on the A plane, and the actual horizontal plane is on the B plane, then the horizontal plane difference Err=AB, then the amount of water we need to add to it at this time is Kp*Err, and Kp is our proportional control coefficient.

        If A>B, Err is positive, add water to the tank; if A<B, Err is negative, scoop water out of the tank. Then as long as there is a difference between the expected level and the actual level, we will adjust the system by adding or subtracting water through the bucket. At the same time, the size of Kp also affects the performance of the system. If the value of Kp is relatively large, the advantage is that the speed from the B plane to the A plane is fast, and the disadvantage is that the system will generate relatively large oscillations when the B plane is already close to the A plane. If the value of Kp is relatively small, the advantage is that the system oscillation is small when the B plane is close to the A plane, and the disadvantage is that the speed from the B plane to the A plane is slow.

        Some people may have doubts here. If the proportional control coefficient Kp is directly set to 1, then the amount of water added is directly Err=AB. In practice, however, many systems cannot do this. For example, in the temperature control system, the actual temperature is 10 degrees. I want to increase the temperature to 40 degrees by heating. Can we accurately add 30 degrees to the system at one time? Obviously this can't be done. Then the final result of proportional control is that the value of Err tends to 0. The formula of the proportional control part is as follows:


Differential control understanding

        Then we first look at differential control. Under the action of our proportional control, Err begins to decrease (assuming that the expected level A is greater than the actual level B at the beginning, that is to say, Err is a positive value), then Err is a slope less than 0 with time. Curve, then in the cycle time, the larger the Err is, the larger the absolute value of the differential is, then it also inhibits the decreasing speed of Err, and the differential will not stop until the final slope is 0. The differential formula is as follows:


    Then with the influence of the differential, the slope of the Err curve eventually tends to 0, as shown in the following figure:

Integral control understanding

        The function of the integral control part is mainly used to eliminate the static error. So how does the integral eliminate the static difference?

        Proportional control can only adjust Err to 0 as much as possible, and the function of differential is to control the slope of the curve to 0 and stop acting on it, but Err is not necessarily 0 when the slope is 0.

        这个时候我们就需要积分来起作用了。我们知道曲线的积分相当于曲线与x轴围出来的面积。如下图,积分作用的目的是使红色部分的面积和蓝色部分的面积的和为0,那么即使系统在比例控制和微分控制部分已经趋于稳定,只要Err不为0就会存在静差,只要存在静差那么积分就会对系统产生影响,直到系统的Err值为0。那么这样我们的PID控制在理论上就可以达到一个非常精确的控制效果。

        来看看我们的积分公式部分:


PID算法离散化

        假设采样时间间隔为T,则在k时刻:

        偏差为e(k);

        积分为e(k)+e(k-1)+e(k-2)+...+e(0);

        微分为(e(k)-e(k-1))/T;

        从而公式离散化后如下:



        比例系数:Kp,

        积分系数:Kp*T/Ti,可以用Ki表示;

        微分系数:Kp*Td/T,可以用Kd表示;

        则公式可以写成如下形式:

        PID算法的离散形式就是这样了,这就是我们平时说的位置式PID。

        接下来我们继续推算增量式PID,根据上面公式我们可以求得:

        上式就是增量式PID的表现形式,计算出来的增量只跟最近三次的偏差值有关。注意这里计算出来的是增量值,也就是说如果我们要求u(k)的话应该是

        那么PID的离散化就长不多是这样了,接下来我们看看PID的程序实现。







这里有些关于PID相关的资料也讲得非常好,大家也可以学习下。

http://wenku.baidu.com/link?url=XtnOjEGrIev7ZUmlwAIR7IEMG0YTvxV3YKpZMsVbEu8FWRsgAeVTLmJCe2K99fjsHuAGHq1c6_s6pqv6JJdYoiA1KcSQVLkV6HIW-_0w88m

http://wenku.baidu.com/link?url=DliKXRLALX6O-uW6glxLb5xW4RWIQm0Ia1PAR4nN4cguFAChMyoYk2XOaikcbIKBWCgmVnVsYnBLN1Ephm7Ly2SHvWioAN3drWlUgvvbFmi

http://blog.gkong.com/liaochangchu_117560.ashx


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324626199&siteId=291194637