A PID Tuning Guide | Understanding PID Control, Part 4
From the series: Understanding PID Control
Brian Douglas
It can be difficult to navigate all the resources that promise to explain the secrets of PID tuning. Some proclaim that PID tuning is an art that requires finesse and experience, while others are adamant that tuning requires a few rigid rules. Why is there such a vast difference? It is because PID tuning depends on the characteristics of the system. For that reason, a one-size-fits-all tuning method doesn’t exist.
Get an overview of various PID tuning techniques ranging from model-based tuning to heuristic methods such as Ziegler-Nichols and Cohen-Coon.
Published: 9 Jul 2018
To begin this fourth video on PID control, let's start with a crash course in control system design, because I think it will help put the later PID tuning activities in proper context. When you approach designing or tweaking a control system, you start with the requirements. This is what you want your system to do. And it's how you know when the design is good enough, and you can stop fiddling around with it.
Requirements usually boil down to defining how fast and accurate you want the control to be and how stable you want the system to be. Specifically, they can be defined by how you want the system to behave over time. These are things like rise time and overshoot. Or they can be defined by the frequency characteristics you want your system to have. These are things like bandwidth and damping ratio.
Now, you might not always have formally defined requirements. Sometimes it's just a subjective feeling that the design is good enough, especially if you're tuning something like your own personal quadcopter that you want to fly. Once you like the way that it behaves, then you're done.
Once you know what you're trying to accomplish, the next step is to understand the system that you're trying to control. Is it something that behaves like an integrator, like a motor, in which case you might not need an integrator in your controller. Is the open loop system stable? Is it highly nonlinear? Is it non-minimum phase? And so on.
Each of these characteristics will affect how you approach choosing an initial controller architecture and how you go about tuning. Now, at this point, you have enough information to start an initial design and tune your controller. And once you think you have a suitable set of gains, you go through the process of verification and validation to determine if the system is what you wanted it to be.
Here, you might find that the controller and gains you chose don't actually meet the requirements. Or you might find that you don't have the correct requirements in the first place, and you circle back around, and make adjustments, and eventually spiral in on an appropriate design. So with all that in mind, for this video, we're focusing specifically on the PID controller and different ways to tune it. I'm Brian, and welcome to a MATLAB Tech Talk.
If you've previously tried to learn the secrets of PID tuning, you probably found a dozen sources, with some telling you that PID tuning is an art that requires finesse and experience, while others explain that you just need to follow a few simple rigid rules, and you're good to go. The reason for this range in ideas is because PID tuning is dependent on the characteristics of the system and the situation, which is why a one-size-fits-all tuning method doesn't exist.
So rather than present just a single method that only applies to a narrow set of problems, in this video, I'll present a tuning guide that will help you navigate and understand the overall picture. Remember, I said that before you choose a controller architecture, you want to spend a little time investigating the characteristics of the system. That's because the first thing we should do is determine whether the system is well behaved.
There isn't a strict definition of well behaved. It's definitely subjective. But I'm claiming the system is not well behaved if it is highly nonlinear such that a linear controller isn't adequate; it's unstable, and you're trying to stabilize it; if there's a lot of delay in the system; or if it's non-minimum phase, which, for the Laplace domain folks out there, means that there is a zero in the right half plane.
In each of these cases, typical PID tuning approaches may work. But it's likely the system requires more advanced tuning methods or control architectures. For the remainder of this flowchart, we're going to focus on well-behaved systems. These are systems that are stable, nearly linear, have minimum phase and a manageable amount of delay.
From here, we have two general situations. First, let's say that you're given a model of your system. A model is a mathematical description that could be presented as a set of transfer functions, states-based matrices, equations of motion, or a more complex simulation. Perhaps you got it from a textbook. Or maybe the company you're working for has a team that developed the model for you.
In this case, you have the ability to tune the gains using a model-based approach. Or the other situation is that you don't have a model, but you have access to physical hardware, either the real hardware or some prototype or mockup that you can use for testing and design. This is the case if you purchased a consumer-grade quadcopter or some industrial machinery, like a commercial thermal chamber that allows you to change the PID gains.
More than likely, you're not going to get a mathematical model of these systems. But that's OK, because the beauty of PID control is that the gains can be tweaked manually so that you can adjust them while running the hardware, then observe the response in real time and make changes to gradually hone in on a set that you're happy with. Want to decrease rise time? Add more proportional gain. Need more stability or decrease the overshoot? Add more derivative gain.
This approach is definitely more art than science and requires a good understanding of how each path affects the system response. But unlike other control architectures, there is some intuition about how PID gains affect the system. And that allows you to adjust them in a way that isn't just trial and error. I've put a link in the description below for a handy chart that describes how the P, I, and D terms each affect different requirements.
Another more systematic approach would be to run some predefined input sequence on your hardware and then observe the open loop response. Often, this is a step input. But it can be any arbitrary command. From the response, you can use a heuristic technique, like the Ziegler-Nichols or Cohen-Coon method. These methods are nice because you don't need a model. You just need to measure certain aspects of the response, like the time constant or oscillation period, and then use that value to calculate an initial gain set.
For a thermal chamber example with the Cohen-Coon method, you could start with the oven at room temperature, step up the heater command to fully on, and then watch how the chamber temperature rises and eventually settles out. From this response, you could measure the delay or the dead time, the gain, and the time constant and then plug those into an equation to get your initial gains.
You have to be careful with the Ziegler-Nichols method on real hardware, because it requires you to get your system oscillating on the verge of instability. And that's dangerous for a lot of systems. And maybe you're not comfortable doing that.
Either way, these heuristic methods only provide an initial guess. Hopefully it's a close guess. But your system may still require manually tweaking the gains to get the performance that you're looking for.
All right, perhaps you only have physical hardware, but you really want to use model-based techniques to tune your controller. In this case, you need to develop a mathematical model yourself. And one way to do this is to derive a model from first principles. This means that you understand the kinematics and dynamics of your system well enough that you can write out the equations of motion directly, and from them, develop a model that closely simulates the physical hardware. This works relatively well for simple systems, but can be very challenging for something complex.
An alternative way to develop a model is to use system identification techniques. System ID uses a measured response from the hardware, often a step response, and then finds an optimal set of model coefficients to match as close as possible the two responses. For simple system ID tools, the model structure needs to be defined ahead of time. For example, you tell it to fit the system to a first-order transfer function.
More advanced tools will find the optimal model structure for you as well as the coefficients. And the nice thing about system ID is that you can generate a model without knowing all of the detailed kinematics and dynamics of your system, which is often a limitation we have, and instead just think about the general behavior.
At this point, you have a mathematical representation of your hardware, whether you used system identification, you derived it from first principles, or you were just given a model. And the next question is how to go about tuning the PID gains using model-based design. There are two very broad approaches that I'll summarize.
The first is manual tuning. Manual tuning is basically using your knowledge of control theory to choose the proper gains. There are far too many ways to accomplish this to call them all out individually in this video. But I'll quickly describe three popular methods.
First, we can determine where we want to place the closed loop poles so that the dominant poles produce the system stability and the response that we're looking for. Solving the equation for the proper gains with pole placement is pretty straightforward. However, the downside with this method is that it requires you to know where you want the poles to be and how the zeros in the system are going to affect the response.
Another method is to use the open loop transfer function and our knowledge of things like Bode and Nyquist plots to shape the loop function so that our closed loop system has the frequency or time domain response that we need. This method requires that you understand how the open loop system compares to the closed loop behavior and how adjusting the two zeros of a PID controller affects that behavior.
Finally, if you choose to, you can abandon the reliance on intimate knowledge of control theory and instead rely on the people and the methods that have come before you by once again using heuristic methods. Ziegler-Nichols and Cohen-Coon methods can be used with a simulation of our systems to get an initial gain set. This is similar to what we did with the physical hardware, but it's much safer, since causing the model to go unstable is less detrimental than causing the physical hardware to do the same.
Lastly, we can turn to software to automatically generate optimal PID gains based on the requirements of the system. Even within the realm of automatic tuning, there is not one technique to rule them all. You may not know the specifics of what the software is doing. But most autotune programs are using the exact same techniques and heuristic methods that we just talked about, but they're wrapped up in a nice, neat function.
In fact, autotuning can be done using a model of the system, or it can combine system identification by using the input and output responses directly. Autotuning can even run real time on the hardware, constantly adjusting and optimizing the gains. Regardless of the technique used to generate the initial gain set, often, as a designer, you still end up having to tweak the gains manually to get the exact response that you want. This can be done using the model or while it's running on the physical hardware.
And I can't stress this enough. Being able to tweak the gains is a strong reason to use PID rather than another controller form, because it can be an intuitive process for well-behaved systems. You can send your hardware out with an initial gain set. And then the users later on can tweak them for their particular situation. And they can do that without much control theory knowledge.
All right, I hope this overview gives you a better understanding of how to approach PID tuning and allows you to make sense of all the different methods you may have come across. Links are in the description below for some helpful resources on the specifics of PID tuning.
In the next video, we're going to explore this tuning flowchart in a bit more detail and show you how you can accomplish each of these techniques using MATLAB and Simulink. 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.