Thread Content
The importance of PID goes without saying, as it is widely used in the field of automatic control. Jason demonstrates the classic PID algorithm by recording the process of Xiaoming filling the bucket with water, providing beginners with another way to understand PID through examples. Jason hopes to explain the following five concepts through vivid examples: 1. Provide a simple description of what PID is, why it is needed, and what functions it can perform; 2. Understand the role of P (proportional element): The basic proportional element has the drawback of causing steady-state error. Question: What is steady-state error? Why does steady-state error occur? 3. Understand the role of I (integration stage): to eliminate steady-state error. Disadvantages: Increases overshoot. Question: Why can integration eliminate steady-state error? 4. Understand the role of D (the differential element): It increases the speed of inertial response and reduces the tendency for overshoot. Question: Why does it reduce overshoot? 5. Understand the role of each proportional coefficient. http://yunrun.com.cn/upload/201908/20/201908200109200498.png Now we will get to the main topic. 1. What is PID and why is it needed? The following is the overall block diagram of PID control. The process is as follows: a target output value is set, the feedback system returns the actual output value; if this value differs from the target, an error arises, and the PID adjusts the input value based on this error until the output reaches the set value. http://yunrun.com.cn/upload/201908/20/201908200211063978.png Question: Then why do we need a PID? For example, when I control the temperature, I can’t monitor the actual temperature value – does it stop as soon as that value is reached? Here we need to clarify our goal first, because all of our control efforts are aimed at achieving the values we have set. In other words, if we set a target temperature value, what kind of temperature change do we want to see? For example, if the target temperature is set at 30°C, the goal is simply to achieve the effect shown in Figure 1: to reach 30°C quickly and without any fluctuations. http://yunrun.com.cn/upload/201908/20/201908200221422995.png Figure 1: The target response of the PID control system. With this, everyone should understand that if one uses a method that stops operation once the desired temperature is reached, it might work fine for low requirements; however, it certainly cannot meet the standards shown in Figure 1. After the temperature reaches the set value, the remaining heat will continue to raise the temperature, and the temperature itself also loses heat through the air. Summary: The reason we need PID is simply that conventional control methods are unable to bring the output to the set value quickly and stably. If you are still unsure about this, let’s start by using a common example to illustrate it in detail. 2. Understand PID through the example of Xiaoming filling the bucket with water: yunrun.com.cn/tech/2683.html. Before we start, we need to write down the formula: At first glance, this formula seems quite complicated. In fact, you can understand it as long as you know the basic definitions of differentiation and integration. And in the end, all our efforts are aimed at understanding this formula; otherwise, no matter how clever the metaphors may be, they won’t enable you to truly understand and use it. Here we discretize it (if this step seems a bit too quick, an explanation will be added later): In the formula, Kp is the proportional constant, Ki = (Kp×T)/Ti is the integral constant, and Kd = (Kp×Td)/T is the differential constant. Next, Jason will illustrate in detail how this equation works through an example. ①Xiao Ming received a task: there is a bucket that needs to be kept at a height of 1 meter at all times. Currently, there is 0.2 meters of water in the bucket. So Xiao Ming uses a proportional method to add water – that is, he measures the error relative to 1 meter and adds an amount of water that is proportional to that error. For example, if Kp is set to 0.5, for the first addition of water: the error is 1–0.2 = 0.8 m; therefore, the amount of water to add is Kp×0.8 = 0.4 m ; For the second addition of water, the error is 1 – 0.4 = 0.6 m; therefore, the amount of water to be added is Kp × 0.6 = 0.3 m ; ...... http://yunrun.com.cn/upload/201908/20/201908200252454737.png http://yunrun.com.cn/upload/201908/20/201908200252553253.png We found that this is perfect; thus, the proportion issue can be resolved perfectly. But wait, before reaching this conclusion, let’s take a look at Xiao Ming’s new task. ② Xiao Ming’s new task: There is a bucket with a hole in its bottom, and it is still necessary to maintain a height of 1 meter. Currently, there is 0.2 meters of water in the bucket, but every time water is added, 0.1 meter of it flows out. This example is closer to real-world engineering scenarios, such as the resistance and losses caused by motor friction. Let’s go ahead and solve the problem for Xiao Ming. The first approach still involves using P (proportional control) with U = Kp × e; we’ll set Kp to 0.5. Thus, U = 0.5 × e, and L (the final water level) is equal to the current value of U plus the previous water level. First addition of water: the error is 1 – 0.2 = 0.8 m; therefore, the amount of water to add is Kp × 0.8 = 0.4 m. The final water level will be 0.4 + 0.2 – 0.1 = 0.5 m. Second water addition: the error is 1 – 0.5 = 0.5 m, so the amount of water to add is Kp × 0.5 = 0.25 m. The final water level is then 0.5 + 0.25 – 0.1 = 0.65 m...... We noticed a problem: the water level eventually stabilized at 0.8 m, which is easy to understand. When the error is 0.2 m, the amount of water added is 0.1 m, meaning that the amount added each time is exactly equal to the amount that leaks away. Here, the concept of steady-state error is introduced: steady-state error refers to the error between the system and the target when it reaches a steady state. So when we increase Kp, we find that the error decreases ; Let’s keep increasing it then; we find that the system starts to oscillate. Excel line charts are used here; users can adjust the parameters to observe the resulting changes. Conclusion: Proportional control introduces steady-state error, and this error cannot be eliminated. Increasing the proportional constant can reduce the steady-state error, but if it is too large, it causes oscillations in the system, leading to instability. To eliminate steady-state error, Option 2 involves adding integration to the proportional control element, using PI (proportional-integral control). Integral control involves adding up all past errors and multiplying the result by an integral constant. What does this formula mean, and why can it eliminate steady-state error? Let’s set Kp=0.5 and Ki=0.3 for now (these values are arbitrarily chosen by me). For the first addition of water, the error is 0.8; the proportional term is Kp×0.8=0.4m, and the integral term is Ki×0.8=0.24m. Thus, the amount of water added is 0.4+0.24=0.64m, and the final water level becomes 0.2+0.64-0.1=0.74m. For the second addition of water, the error is 0.26; the proportional term is Kp×0.26=0.13m, and the integral term is Ki×0.26=0.318m. Therefore, the amount of water added in this case is 0.13+0.318=0.448m. The final water level is 0.74 + 0.448 – 0.1 = 1.088 m. http://yunrun.com.cn/upload/201908/20/201908201410588056.png We find that, despite the complicated process, it is possible to stabilize at the set value in the end. What if we increase Ki? Here, Excel line charts are used; users can adjust the parameters to observe the changes. Conclusion: ① As long as there is a deviation, the integral keeps accumulating until the error becomes 0; at that point, the integral term stops increasing and turns into a constant, which can offset the steady-state error. As can be seen from Table 2, after the system reaches stability, the integral term is approximately 0.1. ②Introducing integration can eliminate steady-state error, but it increases overshoot; moreover, as Ki increases, the overshoot also increases. To eliminate overshoot, we introduce differential action. Now the formula becomes: Let’s still set Kp=0.5, Ki=0.5, and Kd=0.3. For the first addition of water, the error is 0.8 m; the proportional term is Kp×0.8 = 0.4 m, the integral term is Ki×0.8 = 0.24 m, and the derivative term is 0 (since the water level difference before adding water was already 0.8 m). The amount of water added is 0.4 + 0.4 = 0.8 m, resulting in a final water level of 0.2 + 0.8 – 0.1 = 0.9 m. For the second addition of water, the error is 0.1 m; the proportional term is Kp×0.1 = 0.5 m, the integral term is Ki×0.1 = 0.45 m, and the derivative term is Kd×0.1 = -0.21 m. The amount of water added is 0.5 + 0.45 – 0.21 = 0.29 m, giving a final water level of 0.9 + 0.29 – 0.1 = 1.09 m. http://yunrun.com.cn/upload/201908/20/201908201501401752.png As we can see, compared to the graph with Kp=0.5 and Ki=0.5 shown earlier, the oscillations in this graph are reduced – this is precisely the effect of the derivative term. In Table 3, when the error is 0.1 for the second time, while it was 0.8 previously, the derivative term is negative, which prevents rapid changes in the result. Conclusion: Differentiation can reduce the overshoot trend. However, this waveform is still oscillating. Yes, don’t forget that this value was set arbitrarily; we can’t expect the PID control to work perfectly just by choosing some random values. If you try simulating it using Excel, you’ll find that if Ki and Kd are set to high values, the system will oscillate significantly. Therefore, we need to tune Kp, Ki, and Kd, which essentially means trying to determine how to make the output meet the requirements shown in Figure 1. Of course, in this example PI can actually be used; we are doing this here to understand the principle behind its function. The ability to skillfully tune PID parameters and put automatic control systems into automatic mode reflects the automation skills of engineering technicians; however, many people do not truly master PID control and PID parameter tuning. On the CHANGHUI Instrument Network’s product page for PID regulators, the book \"Analysis of Automatic Control Systems and PID Tuning\", written by Engineer Bai Zhigang, is available for free. The book contains no complex theoretical formulas; instead, it offers practical insights. By understanding the essence of this book, even those with a high school education in the field of instrumentation can tune PID parameters and master PID control thoroughly! It’s useful to you and it’s free – go to the product page on Changhui Instrument Network under “PID Regulators” to get this book for free right away! http://yunrun.com.cn/upload/201908/19/201908192101476884.png