Manual and Automatic Tuning Methods | Understanding PID Control, Part 6 - MATLAB
Video Player is loading.
Current Time 0:00
Duration 13:30
Loaded: 1.21%
Stream Type LIVE
Remaining Time 13:30
 
1x
  • Chapters
  • descriptions off, selected
  • en (Main), selected
    Video length is 13:30

    Manual and Automatic Tuning Methods | Understanding PID Control, Part 6

    From the series: Understanding PID Control

    Brian Douglas

    The previous video showed three different approaches to developing a mathematical model of your physical system. Now that we have this model, we can use it to tune a PID controller that will work to control the physical system.  

    PID tuning can be thought of in two ways: Adjusting the three path gains (Kp, Ki, and Kd), or placing two moveable zeros and adjusting the loop gain to get the desired response. This video shows how thinking of PID tuning using moveable zeros allows you to approach the problem with loop shaping and pole placement methods. These methods provide a more systematic approach over the brute force method of guessing gain values and checking the response.

    In addition to manually tuning a controller, this video introduces how automatic tuning can be a way to quickly get a controller design to meet the system requirements.

    Published: 1 Aug 2018

    The last video showed three different approaches to developing a mathematical model of your physical system. And now that we have this model, we have the ability to tune our PID controller in a more systematic way. So in this video, I'm going to introduce you to a couple of PID tuning techniques that use a mathematical model.

    Now, we have a lot to cover. So without further ado, let's get to it. I'm Brian, and welcome to a MATLAB Tech Talk.

    Let's start with a block diagram. When I draw a box and label it plant, as I've said before, this is the system that we're trying to control. And we can feed back the output and wrap a PID controller around it to adjust the way that this plant behaves. Now, when we have a model, this plant is replaced with a mathematical description of the system. And we can use that description to tune the PID controller-- that is, to get our model to behave in a certain way.

    Once we have a tuned system, we can take that controller design, which usually runs on a digital computer, and wrap it around the physical system. And if the model was good enough, then the gains we derived using the model will work for the physical system as well. That's the goal, anyway.

    So the question might be, how do you tune a PID controller? Not how do you get the right values, but what are you doing when you actually tune it? Well, to answer that, let's look at the structure of an ideal PID controller in the time domain.

    We have the three paths. And we can adjust KP, KI, and KD to change the relative amounts that each path contributes to the control. But another way to think of this is in the s domain. If we take the Laplace transform of the PID controller and then rearrange a few terms, we get the transfer function that I've written here in orange.

    So what can we learn from this? Well, first, there's a single pole at the origin. We don't have control over that. It's just an integrator that exists in the controller. But if you look in the numerator, there are two zeros, whose placement is given by KP, KI, and KD, and then an overall gain turn.

    And that's it. Everything you learn about PID controller tuning comes down to where to place these two zeros and how much gain to apply. Well, that's for an ideal controller with an ideal derivative. If you recall from the third video in this series, we don't implement a pure derivative. It's usually a filtered derivative. Therefore, there is actually another pole along the real axis that does that filtering. But we'll touch on that in a bit more detail later on.

    Let's start looking at tuning methods. And to do that, we'll go back to the flow chart that we created in the fourth video. Now, regardless of whether you have a model or not, you always have the option of tweaking the gains manually with the brute force method of just guessing some gain values and checking the response.

    This tweaking is often done to fine tune the response after you already have an initial guess of the gains through some other method. But starting with the guess-and-check approach isn't particularly attractive, since it sometimes feels like you're just randomly changing values and hoping to stumble onto something good.

    With that being said, though, practicing manually tweaking gains with a model and a simulation is a good way to get an intuitive feel for how each branch of the PID controller affects the output. And with a model of your system, you can tweak and adjust the gains without fear of harming any physical hardware. Just take a transfer function, wrap a PID controller around it, and see if you can generate a nice response by adjusting the gains. At the very least, you'll get a good feeling for how hard it can be to tune an unruly plant with this method.

    But here's the thing. You've probably spent some time learning a bit of control theory. So why are we messing around with random guessing? We have a model. We have two movable zeros in our controller. So let's put our control theory to the test.

    But a quick caveat before we begin. In fact, it's the same caveat from the last video. The rest of this video isn't intended to explain all of the mathematics, techniques, and nuances of pole placement, loop shaping, and heuristic methods. The goal is to tie together the concepts of multiple control methods to show you that there's more than one way to accomplish tuning. If you'd like more details on any of these methods I cover here, please check out the links below.

    From the last video, we have these three mathematical models that we can choose from to tune our PID controller. We have a nonlinear model and then the two different linear models. And since each one is different, we would expect the final PID gains to be slightly different from each other, depending on the model that we use for tuning.

    The hope, however, is that these models are all close enough to each other that tuning on one will produce similar results for the other two as well. We're going to check that by the end of this video. But going forward, I'm just going to use the model we developed through linearization.

    All right, now, as I mentioned, from a very simplistic viewpoint, PID tuning comes down to placing two zeros and adjusting the gain. And with our linear model, I'm going to highlight two different methods for accomplishing this-- pole placement and loop shaping.

    So what is pole placement? Well, if you know where you want your closed-loop poles to be-- that is, you know how you want the system to behave, and then you figured out the location of the poles that generate that behavior-- then you can devise a controller that places those poles right where you want them. Of course, this is within reason, because the system itself has to be capable of producing that response, both the actuators that generate the driving forces and the sensors that allow you to measure the state of the system.

    For our single-input, single-output model, we can approach pole placement using a root locus plot. That is, we can draw the root locus for our linear model, which is the open-loop plant. Now, from what I've drawn in green, this root locus doesn't go through our desired pole locations. So no amount of gain will suffice.

    But once we add the integrator and the two zeros of the PID controller, we have a lot more control over the root locus lines. Now we can solve for where to place the two zeros so that the root locus lines go through the area where we want our dominant poles. And then we can solve for the gain that places them there.

    Loop shaping, on the other hand, looks at the frequency response of the open-loop system and uses our knowledge of open-loop gain and phase, and crossover frequency, and so on, to predict how the closed-loop system will behave. By adding our PID controller and adjusting the location of the two zeros and the gain, we can shape the open-loop Bode plot to get the desired frequency characteristics that we want.

    Now, we can tackle both of these methods in a traditional sense using math and writing out the solution that we're looking for. And that's a perfectly great way to solve for the gains and a way you're probably used to from coursework. But in this video, I want to do something that's a bit more graphical, because I think it'll help solidify these concepts in your mind. And we'll do this using the Control System Designer app and Simulink.

    Within Simulink, I have my linear model, and I've wrapped a feedback loop around it with a PID controller. I'm going to launch the Control System Designer app and set it up to allow me to graphically tune the PID controller block and to show me the root locus plot from the reference signal, r, to the output, y. Remember, the point here is not to walk through how to use this app. It's just to show you that graphical tuning is possible and then give you something to watch as I move these zeros around so you can see their impact.

    OK, here's the root locus, and it has a bit going on. There's the two open-loop poles from the plant, the two zeros from the PID controller, and then two more poles from the PID controller. One's the integrator at the origin, and the other is the filtered derivative pole. Now, the closed-loop poles on the lines off to the left aren't contributing too much to the solution, because they're so much faster than the ones closer to the origin. So I'm just going to zoom in and focus on this area.

    Now, from within this app, I can just grab one of the zeros and move it around however I want. These are complex pairs. So when I move one zero, the other moves with it in a mirrored fashion. Now, you can see how the lines move with the zeros. And if I can get them to go through the pole locations that I desire, then I can just adjust the gain by dragging the pink squares into that region.

    But before I do that, I want to also plot a closed-loop step response so you can see how moving these zeros impacts the system. Now, I can move the zeros around and drag the gain along the lines to get a response that I'm happy with. And watching the step response in real time is a good way to know when you've placed the poles in a desired location if you don't quite know exactly where you want them.

    OK, now, approaching PID pole placement by moving these things around by hand is not as precise as solving the math. But a lot of times, this might be good enough. And you get to instantly see the effects while you're doing it.

    For loop shaping, it's nearly the same idea. But we'll be using a Bode plot instead so that we can watch the frequency characteristics of the open loop system. Again, I can move the zeros around and drag the gain plot up and down to adjust the gain. And if I had a particular frequency response in mind, I could use the Bode plot and the free parameters of the PID controller to get the loop shape that I desire.

    Now, I want to show you something else real quick that might get you into trouble if you're not careful. Let's go back to the root locus and up the gain a lot to decrease the rise time of the system and make a really fast response. Perfect.

    All right, now I'm going to populate my Simulink PID block with the resulting gains and then just run the simulation to verify that the response is what I predicted. And look at that. It's perfect as well-- a nice, fast response.

    Well, maybe it's not perfect. Let's not be too hasty. To find out what's wrong with this design, let's plot the output of the PID controller for the step input and see what voltage we're commanding in order to get this response. Wow, look at that. That's like 350 volts. That's way, way too high. I mean, our system saturates at 24 volts.

    So what looks like an awesome controller with a linear model was actually misleading. Really, we shouldn't have placed the poles where we did, because our nonlinear system is incapable of actuating in this way. Let me add saturation to our controller with clamping for the anti-windup method and see how that impacts the system.

    Well, as expected, it saturates at 24 volts. And the motor takes almost a full second to reach the commanded speed. So this is the fastest that the motor can accelerate to 100 RPM. But it may not be the most ideal way. This is because we have such a huge gain that even though it's saturating and not making it through the controller, it's still going to amplify low-amplitude noise and cause our system to follow that noise-- not ideal.

    At this point, we could go back to the Control System Designer app and adjust our controller to slow it down back into the region that the actuator can handle. However, I want to demonstrate another powerful way to tune your controller. And that is to just let software automatically do it for you.

    Back inside the PID block parameters, there's this option to select a tuning method. It defaults to a transfer function-based tuning method. And hitting the Tune button launches the PID tuning app. Right when the app opens, you can see two different responses. The dashed line is the response for the system that I tuned with loop shaping. And the solid line is the result of the automatic tuning app.

    I'll also plot the controller effort so that I can see that my new design won't saturate the controller. Again, the dashed line shows that my design earlier required a lot of controller effort. Now, to adjust the tuned gains, I can move the sliders at the top to change the requirements of the system. Do I want a faster or slower rise time? And do I want it to be more aggressive or more robust?

    Now, if your requirements are given in the frequency domain, then you also have the option of changing the bandwidth and phase margin. And once you settle on a step response that you're happy with, you can update the block parameters, and you're good to go.

    Now, look at this. It's a nice response. It has a smooth rise, with very little overshoot and no steady state error. Plus, the voltage is never saturated. And that's exactly what I wanted.

    So this looks pretty good now. But I am only running it with the linearized model, which is the model that I used to autotune in the first place. Now, the question is, how does this behave with the model we got with system identification or the nonlinear model from first principles?

    Well, to find out, I'll play an arbitrary set point through all three closed-loop systems with the exact same PID gains and compare the responses against each other. If we did this correctly, we should see the noisy signal from our nonlinear model lie right on top of the two linear model responses.

    And that's exactly what we have. The yellow line is the reference signal. And the other three lines are the closed-loop responses from our three models. So our PID gains that we autotuned on one model did, in fact, work for all three.

    All right, this video, along with the previous video, showed several different ways that you could model your system and then use that model to tune the PID gains. There are several other methods out there that I didn't mention that could do this as well. But hopefully these videos gave you a better understanding of some of the options you have available to you next time you're trying to tune your PID controller.

    In the next video, we'll move past tuning and cover a few other interesting topics in PID control. So if you don't want to miss the next Tech Talk video, don't forget to subscribe to this channel. Also, if you want to check out my channel, Control System Lectures, I cover more control theory topics there as well. Thanks for watching, and I'll see you next time.