From the series: Understanding PID Control
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.
To begin this 4th 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 may not always have formally defined requirements, sometimes it’s just a subjective feeling that the design is good enough, especially if you are tuning something like your own personal quadcopter that you want to fly. Once you like the way 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 non-linear? Is it non-minimum phase? and so one. Each of these characteristics will affect how you approach choosing an initial controller architecture and how you go about tuning. 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 that in mind, for this video, we’re focusing specifically on the PID controller and the 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 is a lot of delay in the system, or if it’s non-minimum phase - which, for the Laplace domain folks out there means 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 flow chart, we’re going to focus on well-behaved systems; stable, nearly linear, have minimum phase, and a manageable amount of delay.
From here, we have two general situations. First, let’s say you’re given a model of your system. A model is a mathematical description that could be presented as a set of transfer functions, state space matrices, equations of motion or a more complex simulation. Perhaps you got it from a textbook or 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 mock up that you can use for test 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 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 the 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 pre-defined 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 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 on instability. And that’s dangerous for a lot of systems and maybe something you’re not comfortable doing.
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 you’re looking for.
Alright, 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. 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 for relatively well 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 1st order transfer function. More advanced tools will find the optimal model structure for you as well as the coefficients. The nice thing about system ID is that you can generate a model without knowing the all of 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 chose the proper gains. There are far too many ways to accomplish this to call out 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 response that we are looking for. Solving the equation for the proper gains with pole placement is pretty straight forward, however the down side with this method is that it requires that you 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 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 at 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 auto tune programs are using the exact same techniques and heuristic methods that we talked about, but just wrapped up in a nice, neat function. In fact, auto tuning can be done using a model of the system, or it can combine system identification by using the input and output response directly. Auto tuning 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 you want. This could 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 the users later on can tweak them for their particular situation. And they can do that without much control theory knowledge.
Alright, I hope this overview gives you a better understanding of how to approach PID tuning and allows you to make sense of all of 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 flow chart in a bit more detail and show 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, 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 site
You 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.