with the overview of PID tuning techniques behind us we can now move on to discussing
two very important concepts with PID control cascaded loops and discrete systems both of
these concepts are fundamental to most practical control systems and they each change the way you
approach and think about your problem therefore I think they are worth spending some time to discuss
in a bit more detail I'm Brian and welcome to a MATLAB Tech Talk what is cascade control well to
answer that let's go back to the example we used in the second video of this series an altitude
controller for a quadcopter drone recall the block diagram for this system we start with a reference
altitude this is the altitude that we want the drone to hover at and then this goes through a
comparator to generate an error term which is then fed into a PID controller that generates a
propeller speed command this is commanded to the propeller which begins to spin up and the output
for this block is the true propeller speed the propeller speed generates a force that acts on
the drone adjusting the altitude and finally the altitude is measured by a sensor and fed
back into the comparator at the beginning this is our classic feedback loop and it has a single PID
controller like we're used to but now let's focus in on the propeller itself again the propeller
command is the input and the resulting speed is the output but if you recall videos 5 and 6 in
this series we talked about motor control and what is a propeller other than a motor with a fancy bit
on one end so instead of a single block labeled propeller this is actually a small feedback loop
itself there's the command which goes through its own comparator and the resulting error is fed into
a PID controller the output of the controller is voltage which is applied to the motor causing the
motor to spin the motor speed is measured by a sensor and fed back into the comparator so now
we have to feedback loops in our system one that controls the motor speed and one that controls
the drone altitude we can call these two loops the inner and outer loops so that we can distinguish
between the two these are cascaded loops or nested loops the outer loop drives the set point of the
inner loop and the inner loop affects the feedback path of the outer loop so they're intimately
connected you would probably expect that with a system with two PID controllers interacting with
each other that this would require a slightly different approach to controlling it versus a
system with just a single loop and you would be right but it may not be as different as you
expect the first question might be why design a system with cascaded loops in the first place
I mean why not stick with a single loop approach that we have so much experience with for example
a single loop approach would be to design one PID controller that takes altitude error and outputs a
motor voltage in this case the altitude directly drives the motor voltage there's no middle step
of first commanding a motor speed well here's two reasons the first is that with a cascaded
approach it can be easier to isolate problems in the system in our single loop example if we have a
problem with the motor then it can be difficult to test just the motor separate from the rest of the
altitude system with the cascaded loop scenario we could run the motor controller closed loop and
determine if the problem exists with the motor or with the rest of the system interacting with
the motor the second reason for cascaded loops is that multiple groups can work separate parts
of the problem one team might build and design the motor controller while another team is responsible
for the altitude controller this is especially the case if you buy a motor with an integrated
motor controller the supplier that built the motor will have already designed the inner loop for you
and you just need to incorporate the outer loop around it but a more important reason to have
cascaded loops is to run them at different speeds to address different problems and sources of error
the motor controller can respond quickly to local disturbances whereas the altitude controller can
be tuned conservatively to reject sensor noise and increase stability for example in cascade
control let's say that the propeller motor takes 10 volts to run a hundred rpm which we'll say is
the speed required to hover the drone now we add some disturbance in our loop maybe the battery
voltage drops because another high current device in the drone is turned on or perhaps
the lubricant and the motor bearings get hot in the resistance drops requiring less voltage for
the same speed in both of these cases the inner loop motor controller can sense this error and
adjust the motor voltage in a fraction of a second so that the propeller speed is barely
affected if the inner loop is fast enough then the motor disturbances wouldn't even be seen
by the outer loop because there wouldn't be a noticeable change in altitude this would allow
the outer loop to be much slower and only respond to relatively slow disturbances like wind gusts
now if there was only a single loop then the altitude controller would have to sense that
tiny change in altitude and quickly adjust the motor voltage in that fraction of a second if we
tuned the outer loop to be that aggressive then it would respond quicker to changes in altitude
but it would also respond quickly to altitude sensor noise and that's not ideal so it's a much
better system to have these cascaded loops with each loop targeting a different set of reference
points and disturbances okay now that we have an understanding of why we need cascaded loops let's
quickly discuss a few ways to tune them first off if the inner loop is much faster than the
outer loop that is the bandwidth of the loop is at least about five to seven times higher then
it is possible to tune them separately for our drone example we could tune the motor controller
first and make sure that when we command a speed the motor spins up quickly with the performance
that we want and then since the inner loop is so fast when the outer loop requests a motor speed
the motor spins to that speed quickly so that to the outer loop it might as well be instantaneous
therefore to tune the outer loop you can make the assumption that the inner loop doesn't exist and
that the command just goes straight through in this way you're essentially tuning two single
loops exactly like you're used to if the two loops must operate at about the same bandwidth
then tuning becomes a little more difficult because we can't claim that the inner loop is
fast enough to be instantaneous now the inner loop formance does affect the outer loop I'm
gonna highlight three different ways to approach tuning here but I'm not gonna go into detail on
any of them if you'd like more information check out the links below alright the first way is just
an iterative approach this method requires you to tune the inner loop first with a guess then tune
the outer loop while the inner loop is running if this isn't sufficient for both loops when
you're done then you go back and tweak the inner loop again and iterate back and forth until you
have the performance that you're looking for an easier way however is to just treat the system
as a multi-input multi-output system rather than two cascaded single input single output systems
using a state space representation you can treat the whole model as a single dynamical system and
tune both loops simultaneously using a variety of states based tuning methods finally we can
use software to auto tune them just like I showed in the last video the auto tuning capabilities of
MATLAB and Simulink can be used to tune the two loops at the same time alright there's obviously
a lot more that I could cover on cascaded loops but right now I want to turn your attention to a
topic that will affect almost every PID controller you create and that is a discrete PID controller
similar to what I just did with cascaded loops for discrete control I just really want to use
this as an opportunity to introduce the topic to you and maybe give just enough information
to explain why learning the topic is important and how a discrete PID controller differs from
a continuous PID controller as always links to more information are below including a series
of videos on discrete control that I made on my channel all right so why discrete control why not
always treat time as a continuous variable like how we experience it in real life the reason is
because the controllers we design are usually run on digital computers and digital computers don't
run continuously but instead update at each sample time for example that means that if a
computer process is running at one Hertz then once a second the controller reads the sensors perform
some calculations and then commands the actuators the actuators keep that command for the full
second before receiving a new command at the next sample time contrast that with a continuous system
or analog computer where the actuator command is changing continuously and smoothly digital
systems also have other unique characteristics like quantization and transport delay but to
explain how digital computers impact a controllers design I'm just going to focus on sample time for
the rest of this video if the sample time is short enough compared to the dynamics of your system
then it behaves very similarly to the continuous system this is because the controller can read
the sensors and update the actuators so fast that it appears practically continuous however
as the sample time increases the discrete result differs more and more from the continuous result
to understand why let's imagine this scenario you want to walk from point A to point B and to do
so you have to walk through a winding hallway if the lights are on in your eyes are open then this
is analogous to the continuous time domain you can see everything as it happens and constantly
adjust your path in fact you could probably even run through the hallway now if we swap
the continuous light for a discreet light like a strobe then things change if the strobe light is
very fast so fast that it looks like the lights are just on then the situation looks the same to
you and you can run through the hallway however if the flashing of the light slows down so that
you can only see once a second or once every few seconds then you can no longer run through
the hallway at least not with as much confidence as before this is the effect that discretizing
has on our continuous PID controller if the sample time is relatively fast the PID controller can see
everything and react just the same way as before however if the sample time is relatively slow
that is the flashing of the light is slow then the PID controller will have to be slowed down as well
to keep it from metaphorically running into the walls now the structure of the PID algorithm also
looks different between the continuous s domain and the discreet Z domain representations they
both have a filtered derivative term and there are integrals on both sides but as you might
expect since they look different the KP ki and KD terms are not the same the two even for equivalent
systems however there are several different ways to convert from the S domain to the Z domain and
again I go through many of them in the series on discrete control so a typical approach to tuning
a discrete PID controller is to first tune it in the S domain and then convert it to the Z domain
while ensuring that the sample time is fast enough to keep the same behavior then you can implement
this discrete PID controller on your digital computer and be confident that it will behave the
way that you want now I want to end this video by quickly explaining why we learned and talk
about controllers in the continuous domain first why don't we build and tune our PID controller in
the discrete domain from the beginning the answer is the same answer for why we use linear models to
approximate our nonlinear systems it's because solving problems in the S domain is easier and
we have a lot more tools at our disposal for the continuous domain just like we have a lot more
tools for linear systems over nonlinear systems in addition often the plant being controlled is
itself continuous so modeling both the plant and the controller in the same continuous domain makes
the problem simpler and as we've just seen as long as certain conditions are met like a fast enough
sample time then these imperfect representations are still good enough to get the job done and it's
easier than the alternative so I hope this quick discussion gave you a little insight into cascade
control and discrete PID controllers 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