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.

The last video showed three different approaches to developing a mathematical model of your physical system. 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. 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. We can feedback the output and wrap a PID controller around it to adjust the way this plant behaves. 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, usually run it on a digital computer, and wrap it around the physical system. 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 tune it?" 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 rearrange a few terms, we get the transfer function in orange. So what can we learn from this? Well, first, there is 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 2 zeros whose placement is given by Kp, Ki, and Kd, and an overall gain term. That’s it! Everything you learn about tuning a PID controller 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 is usually a filtered derivative. Therefore, there is another pole along the real axis that does the 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 we created in the fourth video. Regardless of whether you have a model or not, you always have the option tweaking the gains manually with the brute force method of 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 a 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. 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 possibly spent some time learning a bit of control theory, so why are we messing around with random guessing? We have a model and two moveable zeros in our controller, so let’s put our theory to the test!

A quick caveat before we begin. In fact, 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 is more than one way to accomplish tuning. If you’d like more details on any of the 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 two different linear models. Since each one is different, we’d expect the final PID gains to be slightly different from each other depending on the model 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’ll check that by the end of this video. Going forward, I’m going to just use the model we developed through linearization.

As I mentioned, from a 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.

What is pole placement? If you know where you want your closed loop poles to be - that is, you know how you want your system to behave and you’ve figured out locations 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 to generate the driving forces and the sensors that allow you measure the state of the system.

For our SISO 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. For what I 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, 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 those methods in a traditional sense using math and writing out the solution we’re looking for. That’s a perfectly great way to solve for the gains, and it's a way you’re probably used to from course work. But in this video, I want to do something that is 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 to the Control System Designer app and set it up to allow me to graphically tune the PID controller block and 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 give you something to watch as I move these zeros around so you can see their impact.

OK, here's is the root locus and it has a bit going on. There are the two open loop poles from the plant, the two zeros from the PID controller, and two more poles from the PID controller - one is the integrator at the origin and the other is the filter derivative pole. Now, the closed loop poles on the lines off to the left aren’t contributing too much to the solution because they are so much faster then the ones closer to the origin. So I’m 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. 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.

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 and get to a response that I’m happy with. Watching the step response in real time is a good way to know when you you’ve placed the poles in a desired location if you don’t quite know exactly where you want them. OK, approaching PID pole placement by moving these things around by hand is not as precise as just solving the math, but a lot of times this might be good enough and you get to instantly see the affects 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. 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.

I want to show you something else real quick that might get you in trouble if you’re not careful. Lets 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. Now I’ll populate my Simulink PID block with the resulting gains and run the simulation to verify 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 is wrong with this design, let’s plot the output of the PID controller for this step input and see what voltage we’re commanding in order to get this response.

Wow! That’s like 350 volts! Way, way too high. Our system saturates at 24 volts. So what looks like an awesome controller with a linear model was 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 this 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 could 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 will still amplify low amplitude noise and cause our system to follow that noise. Not ideal.

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

Back inside the PID block parameters, there is 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 I can see that my new design won’t saturate the controller. Again, the dashed line shows that my design 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? If your requirements are given in the frequency domain then you also have the option of changing the bandwidth and phase margin. 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 response; a nice smooth rise, with very little overshoot, and no steady state error. Plus, the voltage is never saturated. That’s exactly what I wanted.

So this looks pretty good, but I’m only running it with the linearized model - which is the model that I used to auto tune in the first place. The question is, how does this behave with the model we got with system identification or the nonlinear model from first principles? 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 auto tuned on one model, did in fact work for all three.

Alright, this video along with the previous video showed several different ways 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 are trying to tune your PID controller.

In the next video, we will 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. I’ll see you next time.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web siteYou can also select a web site from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

- América Latina (Español)
- Canada (English)
- United States (English)

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)