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 games 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 and 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 0 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 gonna 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 state space
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 games using a model based approach or the other situation is
that you don't have a model but you have access to physical hardware the real hardware or some
prototype or mock-up 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 Koon 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 Cowan Kuhn 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 hols so that the
dominant poles produced the system stability and the response that we're looking for solving the
equation for the proper games 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 Kuhn method 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 auto-tune 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 auto tuning can be done using a model of the system or it
can combine system identification by using the input and output responses 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 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 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