How to tune a PID Controller_1 2023.07.31. 18분 13초 장서린 Video: 00:02 Hey everyone. Today I'm going to show you how to tune a PID controller from scratch. This video is geared towards those who already have a basic understanding of a PID controller and want to learn how to actually set one up from the beginning. Video: 00:18 Normally a controller whether it be a PLC, a microcontroller or another device is going to come with default values. Those default values are good but not perfect for every application. Video: 00:29 So whether you don't like the default values whether you don't have them somebody's been in there playing with the values already or you just want to start from scratch here's how we do it. Video: 00:38 Always start with the proportional so set the P, I and D to zero and start with your proportional. Video: 00:45 We're going to start small because I'm not really sure how this controller is going to react yet. Starting with a value of 10, let's see what happens. A small increase in the proportional the output is low and the actual value is nowhere near the set point. Now let's bring this proportional up. Video: 01:07 The idea when setting up the proportional value is to keep increasing and increasing the value until your controller becomes unstable. By unstable, I mean it goes into oscillations and the oscillations become larger and larger. If the oscillations become smaller and smaller the controller is stable. Video: 01:25 We want the breakpoint between the two. So let's find that. Video: 01:37 Okay, at around 1000 proportional, we have an unstable controller. If I bring that down to 900, let's see what happens, because we want that breakpoint where it becomes stable and unstable. At 900 the oscillations get smaller, so that's actually a stable controller. Let's go to 950. Video: 02:01 950 is slightly on the high side so we're going to say 900 is the value that we want to use. Take that value on the break point between stable and unstable and divide it into two. That's your starting point for the proportional. Video: 02:16 Normally this is a value that you can run with for a long time and just have to fine tune it later to get the actual reaction you want. After we have the proportional notice how the actual value hasn't reached the set point. Video: 02:29 Some controllers will, depending on what the set point is, what the actual value is, and what the device is or the controller is. Video: 02:37 In our situation, with the output being only at 32 the actual value hasn't reached the set point but that's common with a proportional value. To get the actual value there we need the integral. The integral is going to increase that output over time accumulative to bring the actual value to the set point. Video: 02:58 The idea in tuning the integral value is to slowly increase until you have a reaction time that you like. So let's change the set point, watch our reaction, and adjust as necessary. I'm still not reaching the set point. So this integral is far too low. Video: 03:22 Bringing the integral up. Video: 03:27 Okay now I have some overshoot on the set point. Video: 03:35 but still a little bit low and a little bit slow to reach where I want it to be. So I'll continue increasing this. Video: 03:48 Changing the set point and just tuning that system. A lot of controllers will work with just a P and an I and not a D value. Video: 03:57 So you can tune the proportional then tune the integral and have a controller that works for you. This reaction time is better but I want to see what it does with a larger set point change. Video: 04:11 With a large set point change we have a little bit of overshoot from the proportional. But then with the integral, it's not actually accumulating as fast as I like and keeps us a little below the set point. I’m increasing it again and trying again. Video: 04:28 There's no set formula for a PID control loop other than changing the values, changing the game factors on the P, the I, and the D and watching the reaction. Okay let's look at this loop. The reaction time is great with a proportional, with the output of the controller dropping right down to bring the value down. Increasing, slight oscillation but very stable within one cycle returning. Video: 04:48 The integral brings us to the set point where we want to be. But we have an overshoot here. Or an undershoot. In some applications that might be all right. Video: 05:06 We say okay this is fast acting it's stable and it reaches the set point where we want it to. I'm happy with the controller. But in other applications that are finnicky, you see this overshoot and the undershoot and you say I need to smooth that out. Video: 05:15 That's where the derivative is going to come into play. Not a lot of people understand the derivative value. Its job is to take this overshoot and minimize it as little as it can. Video: 05:30 How the derivative does that? It looks at how fast is my actual value reaching my set point. The faster it reaches the set point, the more the derivative pulls back on the controller to stop that overshoot. Let's see how that works. Video: 05:52 We added a bit of a derivative. We still have an overshoot. Let's increase that more. Video: 06:06 Much better. But still a bit of an overshoot. Let me increase it again. Video: 06:19 Now that is a very stable, fast acting and accurate controller with very little overshoot. I would be more than happy with this. We can increase the derivative a little more to see if we can take that overshoot and bring it right down to nothing. Video: 06:38 But the issue with the derivative is if you go too high it can actually cause your controller to become unstable. Video: 06:45 Or if you have distortion in the system, the derivative is going to do the opposite of what you want it to do and it's going to negatively affect the controller. So be careful in tuning the derivative. Video: 06:52 Bring it to reaction time that works for you: a stability that works for you, without actually causing too much negative effects on the controller. Video: 07:00 We can bring it to 60 in this case anyway, just to see what happens. It is a simulator after all so, we're not going to affect anything or negatively impact anything in the real world. Let's try it. Video: 07:15 and I'm going to say that's just about perfect. Fast acting, stable, and extremely accurate controller. That's great. Now let's say that this PID controller is controlling an engine. An engine is fast acting, fast reacting to the output. Video: 07:35 If the throttle valve opens the engine speed reacts extremely fast to that. But not every application's the same. If this was a heating loop where you either have water or air that you're heating up, the reaction is slower. When you increase that flame or increase the heat on. Video: 07:50 The time of the water or the air to react and heat up is slower than that of an engine. So these PID values may not work for that. Video: 08:01 With this simulator there's a ton of advanced options here that you can use to change it to match whatever industry you're in, whatever controller you're trying to mimic, you can set it up that way. Video: 08:09 You can change the ramp rate at the set point. You can add load steps to the system to see how the controller reacts. You can change the graph speed to notice the actual PID values and how each one of them changes, with your value changes. Video: 08:19 The reaction time of the controller, which we're going to set lower to simulate that slow reacting heating loop. Video: 08:28 And you can add distortion to your system. Either distortion on the loop from interference from other devices, or if you have a heating loop with air in it, if you have an engine loop that's misfiring, you can add that distortion in and see how the controller's going to react. Video: 08:47 This simulator is fantastic and I recommend it to anybody. Okay, let's go to our heating loop. We have a slower reaction time, same PID values. Video: 08:58 Let's change the set point and see what happens. Video: 09:03 Notice the actual value doesn't react quite as fast as we would have liked or as we would have saw with the engine. And it doesn't recover quite as fast with that delayed change in state for the water or the air. These values are good though. It's not unstable. Video: 09:22 It does react, and it does eventually make its way to the set point. But when looking at this, I'm saying there's a fairly large undershoot on the temperature, and I want to see that brought in a little bit. Not only do I want to see it brought in, but I would rather reach the set point slower then have my controller undershoot or overshoot by that far. Video: 09:41 We can either use the values that we have here and start adjusting and adjusting not knowing which way to go, to get the controller we want, or we can use the method where we start from scratch again and find those values that are going to work best for our controller. Video: 10:04 Start with the proportional. Okay, it's not unstable yet. Remember what we have to do? Increase that proportional to become unstable. But the 1000 is still stable. 1250 is still stable. Video: 10:18 Let's see if we can change that set point a little bit to throw it into an oscillation. And at 3500, now we have an unstable controller. Notice the oscillation slowly getting larger and larger and further away? That's our unstableness. So, cut that in half, and we have a proportional starting point. Video: 10:42 Let's do the reaction time on that. Video: 10:50 It does react but it stays slightly below the set point and we don't want that. Because actually without an integral, that proportional and the output are going to stay exactly where they're at, and you may never reach the set point. The integral's job is not the immediate reaction, but it follows the proportional and brings the actual value to the set point. Video: 11:21 So we can increase the integral, watching our reaction time on that. Video: 11:30 Now that's better. With an integral of 10, now we have a reaction time that we like. We meet the set point but we have a slight overshoot. Let's see what happens when we increase. Video: 11:52 Okay, the only thing with this now is we're slightly under still. So I'm going to say that integral is a little bit low. The reason it was closer to the line here is because we're actually below the set point on that. Video: 12:19 That integral looks a little bit better. Video: 12:33 But still hanging out on the lower side of the set point and taking a little bit of time to get up to where we wanted to. Now with the integral it does compound over time. Video: 12:43 So you'll notice the output slowly increasing and increasing. Our actual value is increasing and increasing, bringing us to where we want to be with that integral increasing. But I'd like that reaction a little bit faster. Video: 13:00 Let's try that. Video: 13:13 Okay Video: 13:24 And that's just about a perfect reaction time. We reach the set point, very very minimal overshoot compared to in the beginning with that large droopy overshoot with the engine PID values and maintaining set point perfectly. Video: 13:41 With this controller, we have a PI controller. No derivative values, no derivative input on the controller. A very stable fast acting for what the control loop is: a Controller. Do we need to add a derivative? No. A lot of control loops are a PI loop only. Video: 13:59 If we want to try a derivative action to see if we can get rid of that tiny overshoot? Hey, it's a simulator, we can try whatever we want. Sometimes it causes it to become more unstable and you set the derivative back to zero. But if it does help, then keep it. Video: 14:19 adding our derivative in. Video: 14:27 Let's watch our overshoot. Still overshooting and not perfect. Video: 14:37 Increase the derivative a little more. Video: 14:46 Again, a little bit of an overshoot. Now remember: we risk causing the controller to become unstable, or react to distortion in a negative way if we go too high with the derivative. But since we're playing let's play. Video: 15:27 Okay I'm going to say that derivative has definitely brought the oscillation down, or that overshoot down. So by adding that derivative into our control loop, we've now taken that very minimal overshoot we had and brought it to almost nothing. Video: 15:45 If you want to see the difference in the reaction you can pause it. This is with the derivative on the increase. Now let's increase again without the derivative and see if there's a difference. Video: 16:14 While this PI loop is stable and doesn't need a derivative function, you can notice when you add the derivative in it does buffer out or smooth out that small overshoot. Now with this controller once you have all of that in play we have our P or I and set out D back. Video: 16:34 Now we can start playing and tuning to different scenarios. So, if we decide to add a bit of distortion into the loop, distortion can also simulate load changes. So the more you increase the distortion, the larger the load changes in the actual building or the actual scenario that you're in. Video: 16: 55 And let's see how the controller reacts to that. Video: 17:01 The output seems a little bit crazy for up and down but notice how with the changes in the actual value, it's actually bringing it back to the set point so it's doing what it's supposed to. That's perfect. Take the distortion away, and the controller should smooth out. Video: 17:20 Fantastic. Add a load step, and see what the reaction is when you add a load step to the system Video: 17:29 A very good fast acting and smooth controller. So now we've found two different examples, two completely different PID values, but values that are very stable and great for the controller that we're in. Video: 17:46 I hope after watching this video you now have a better idea and understanding of how to tune a PID loop from scratch or retune a loop that's been set up but not working correctly. Video: 17:56 To conclude, there really is no set values that are going to work for every PID loop. But by following the steps in this video and some practice, you'll be well on your way to tuning. Video: 18:04 And if you want to practice at home, you can always download the simulator in this video from the Microsoft store. Thanks for watching everybody and enjoy automating.