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 and 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 tune 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 enter 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 zeroes 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 zeroes 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 in 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 that 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 gonna check that by the end of this video but going forward I'm
just going to use the model we developed through linearization alright now as I mentioned from a
very simplistic viewpoint PID tuning comes down to placing two zeroes and adjusting the gain and with
our linear model I'm gonna 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've 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 to zero so that the root locus lines
go through the area where we want our dominant poles and then we can solve for the game 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 away 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 gonna launch
the control system designer app and send 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 zeroes around so you can see their
impact okay 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 ones
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 there's so much
faster than the ones closer to the origin so I'm just gonna 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 there's 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 okay 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 zeroes 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 gonna populate my simulate 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 actuated in this way let me add saturation to our
controller with clamping for the anti wind-up 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 gonna 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 auto tune 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 auto-tuned on one model did in
fact work for all three alright 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 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