Can you design a controller that is
able to handle unexpected and uncertain changes to the system
that you're trying to control?
In an extreme case, imagine a plane flying along happily
on autopilot and then suddenly part of the wing falls off.
Now, if you want autopilot to handle that,
is that something you should have expected and built
in some kind of wing broken mode in the controller
or can you just design a controller
that's able to adjust itself to this new unexpected situation
on its own?
Well, that is what adaptive controllers can do.
And in this video, we're going to talk
about one adaptive method called model reference adaptive
control.
And so you know what you're getting yourself into,
this is just an introduction to the topic.
We're not going to go too much into the mathematics
of this control law.
But I do think it will be interesting and beneficial
to talk generally about what it is, how it works,
and why you might want to consider it
for some of your projects.
I hope you stick around for it.
I'm Brian, and welcome to a MATLAB Tech Talk.
As the name suggests, an adaptive controller
adapts to variations in the process dynamics.
And these variations could come from a number of places.
For instance, the disturbances that come from the environment
might change.
Or in some cases, variation just comes from the fact
that you have uncertainty in your system
or unaccounted for dynamics in your model.
And finally, like in the case of the wing falling off,
the system dynamics themselves might actually change.
And a controller should be set up
in a way that can handle these variations.
One way to do this is with a robust controller.
This means that the controller is designed
with enough stability and performance margin
that it works sufficiently well across the entire range
of expected variations.
And if a single static controller can do this,
then that's perfectly reasonable.
However, finding a single robust controller
that can meet requirements becomes more difficult
as the range of uncertainty grows.
So for the cases with large variation,
you may consider some other method
like gain scheduling that will change
the gains of the controller as the system moves from one state
to another.
For example, you may have a set of gains optimized
for an aircraft with full fuel tanks
and then a second set of gains optimized for near empty tanks.
And then through gain scheduling,
the controller smoothly transitions between the gains
as fuel is consumed.
And this works well for variations, even
large variations, but that you are expecting.
It doesn't work too well for uncertain or unexpected
variations because you won't have already generated
an ideal set of gains for them.
So in the cases where variations are large and uncertain,
it makes sense to do something else.
With adaptive control, the gains or parameters of the controller
are not completely determined ahead of time.
Instead, a learning mechanism is built
into the controller that is constantly tweaking
and optimizing the parameters.
Therefore, even if the controller
encounters a situation that it isn't designed specifically
for, it can still adapt to that situation
by changing the parameters of the controller in real time.
So with that being said, I want to go
into more detail about one particular type
of adaptive controller called model reference adaptive
control, or MRAC.
With MRAC we specify a reference model
that we want the closed loop system to match.
Let me try to explain it this way.
Let's assume we have this real plant that we've modeled
with this state equation.
We can manipulate this system through the control input U
and then the system state X changes.
And let's say we design a full state feedback controller that
can track a reference signal R. We have the feedback gains KX,
and we have the feed forward gains KR.
So the idea is that we want to tune these gains to generate
the performance we're looking for in this closed loop system.
Now, what performance are we looking for?
Well, we could define performance in terms of things
like rise time, overshoot and settling time to a step input.
However, alternatively we can say
that we want this closed loop system
to behave like this other open loop system.
This other system we get to choose.
And it's our reference model.
It represents the ideal behavior of the closed loop system.
So how can we ensure that these two systems match?
Well let's just take the simple approach where
we solve for the state equations for both the reference
model and the closed loop system and then set
them equal to each other.
The reference model is just the state equation,
and to get the closed loop system model
we feedback the control input U which
is KR times R minus KX times X. And now
by setting the state and input matrices equal,
we get the model matching conditions.
Therefore, all we need to do is solve for KX and KR that
make these two equations true.
This is essentially pole placement,
where we're choosing to place the poles of the closed loop
system at the poles of the reference model,
but we don't necessarily care about the location
of the poles themselves.
What we want is to have the state of the closed loop system
match the state of the reference model.
That is, given the same reference signal,
we want the outputs to match.
So let's try this.
We can subtract the two outputs from each other to produce
an error signal E. And the goal is that we ultimately
want this error to go to 0, since that would ensure
that the two systems have similar behavior for a given
reference signal.
So we have E equals X minus XM, and if we
take the derivative of that we get E dot equals
X dot minus XM dot.
And after we substitute in the two state equations,
we get this.
If we now pick KX and KR that make the model matching
condition is true, then these two terms will cancel out
and this bit becomes AM.
And what we're left with is E dot equals AM times X minus XM.
Or E dot equals AM times the error.
Now, if you choose a reference model that is stable,
that is the real parts of the eigenvalues of AM
are all less than zero, then this
is a stable linear equation and the error
will tend towards 0 over time.
So that means that even if we initialize these two
systems with different starting conditions,
as long as the model matching condition is met,
the error will eventually go to 0
and the outputs will be the same.
And that's pretty cool.
But you can probably see a problem with this
and that it assumes that we have perfect knowledge of the system
we're trying to control.
That is, not only do we know the parameters A and B,
but we also know that the model itself perfectly
captures the dynamics of the real system, which if we
knew that we wouldn't need adaptive control
in the first place.
But we know that isn't the case because we already
talked about all of the uncertainty regarding
the variations in the system.
So there's going to be some amount of uncertainty f of x,
that makes picking KR and KX that's going to perfectly match
the closed loop system to the reference model impossible.
We are out of luck.
Except maybe we aren't because we
can try to do something about it.
If we can cancel out that uncertainty,
then we'll be left once again with our nominal model
and our model matching conditions will still hold.
So to cancel f of x we can feed back another term W
transpose times phi, where w is a vector of adaptive control
weights and phi is a set of uncertainty model features.
And I'm going to explain what that means in just a bit.
But for now, if W transpose times phi perfectly
matches f of x then these two terms will cancel out
and we'll just be left with the nominal model of the system.
All right, so that's our new goal.
We want to match W transpose phi to the unknown f of x.
So what is W transpose times phi?
Well, it can sort of be anything you want.
Phi is a set of basis functions or features
that you can choose which can then
be combined using the weighting vector W. For example,
let's assume a system has two states, p and theta
and that the unknown variations to the system
are f of x equals 1 plus 3 times theta plus 2p
plus the absolute value of theta plus 4 times the absolute value
of p times p plus theta cubed.
In this case, an absolute ideal phi would consist of a bias 1
plus the other features theta, p, the absolute value of theta,
the absolute value of p times p and theta cubed.
And then the absolute ideal weights
would be 1, 3, 2, 1, 4 and 1.
And the combination of these two would perfectly
represent the unknown variations,
and if you knew all of this, then you
could set up W and phi accordingly.
However, more often than not, we don't know what
the model of f of x looks like.
So we don't know what the ideal features are and therefore we
have to make a choice as to which features we want to use.
We could simply choose to model phi
as the states of the system plus a bias.
And then in this case, we'd essentially
be making a linear approximation of this nonlinear function.
And that's still better than nothing,
but it won't be perfect.
However, if we had some understanding
of the structure of the variations, like for example
we know that there's a term that is
proportional to the absolute value of theta,
then we could add that additional term to phi.
And now our approximation would include at least one nonlinear
term and the fit will be better.
However, if you don't know much about the individual features
of f of x at all, it's common to use a set of general features
like radial basis functions, that
are universal approximators.
This just means that you can represent any arbitrary
function f of x as long as you have enough of them
and set them up correctly.
Let's look at radial basis functions a little bit
more so that how they work.
There are several different shaped radial basis functions.
But for this example, we're going
to focus on a Gaussian shape.
Therefore, a radial basis function
is essentially a Gaussian that has a given width and center.
And if we have multiple Gaussian functions,
we can build up a function approximation
by scaling each one by a different weight
and then summing them together.
For example, here I have a Gaussian
that I can scale with a weighting factor.
I can adjust the width of the Gaussian
and I can move the center.
Now, I can add two more Gaussians
centered at minus 3 and 3, each with the same width.
And they all currently have the same height as well
or a weighting factor of 1.
Now, the product of W transpose and phi
is the function of approximation.
And by adjusting the weights or the height of the Gaussian,
we can affect the shape of that function.
And the idea would be to find a set of weights
that produce a close estimate of the uncertainty f of x.
However, there's not much flexibility
if we just use three radial basis functions.
So we may want to increase the number.
For example, let's say that this black line is
the real uncertainty function f of x.
Now we define 20 radial basis functions that
span across the input space.
And I've initialized W to be 0.3 for each Gaussian.
And the purple line is the result
of W transpose times phi.
And at this point, we can start adjusting the weight vector,
which changes the amplitudes of each of the Gaussians,
which then changes the estimated function
until we get to some optimal set of weights.
And finding this optimal weight vector
is where adaptive methods come into play.
If you have a nominal model and a reference model
and a set of basis functions defined,
then you can use them along with the error term
and the reference signal to learn W over time.
In this way, we're converging on the unknown dynamics
so that we can cancel them out.
But we can actually do more than just
learn the unmodeled dynamics, because if you don't
have a nominal model at all, and therefore
no way to come up with a nominal KR and KX,
we can also set up the adjustment
mechanism to learn KR and KX.
So at the exact same time, we can learn the unmodeled dynamic
so we can cancel them out and learn
the control parameters to reach that model matching condition.
And at this point the obvious question
is, how do these algorithms do that.
And unfortunately, the math would take a video on its own
to describe.
But fortunately, other people have already
created those videos.
So if you want to learn about the MIT rule or the Lyapunov
rule for learning these parameters,
I suggest you check out the great resources
that I've listed in the description of this video.
And hopefully, with this brief overview
of the control law and the block diagram,
you'll have a better appreciation
for what MRAC is trying to do, and that'll
make going through the math a little bit easier.
Now before I end this video, I want
to show you a version of model reference adaptive
control in action.
This example shows how to use MRAC
to control the roll of a delta wing aircraft
by canceling out the undesired role oscillations that
can occur.
And it uses the model reference adaptive control
block in the Simulink control design software.
The general problem is that with delta wing aircraft that
are flying at high angles of attack,
the stalling of one wing before the other
can induce a roll and a slight turn that
will stop the stall on that side but then
cause the other wing to stall.
And then the opposite happens causing
a back and forth oscillation.
And high angles of attack are seen
when the airplane is landing, which is not an ideal time
to kick up these disturbances.
So let's see how this example uses
MRAC to learn these disturbances and cancel them out
by moving the ailerons
Here is the real system dynamics.
And it's saying that the roll rate is the derivative of roll
angle and the angular acceleration
is affected by the angle of the ailerons plus the unknown roll
dynamics delta x caused by the stalling wings.
This is the f of x that we won't have modeled
but are hoping that the MRAC controller can
estimate and cancel out.
And down here we define the nominal model
of the aircraft and the reference model
that we want the closed loop system to behave like.
And since we have a nominal model,
we can use the model matching conditions
to specify a KX and KR.
Now we need to specify phi.
Again, if we knew the structure was in this form up here,
then we could just use those features directly in phi.
However, since we don't, this example
opts to use system state as the feature set at first and then
20 radial basis functions afterwards
so that you can compare the performance of both.
Now we can simulate the performance
of the controller in Simulink.
Here we have the true airplane model
and the true external disturbances
and then this block is the model reference adaptive controller
that's taking in the reference command in the current state
of the system and then using an adaptive mechanism it's
learning the parameters of W in order
to cancel out the disturbance.
And then this block outputs the control
signal U and the estimated disturbance.
And if we scroll down, you can see
the roll tracking capabilities of this controller
when we use phi defined as system state.
And we can see the comparison between the estimated and true
disturbance.
So the disturbance was matched pretty well
but there are periods where there's
a rather poor estimation of the true disturbance.
And that's due to the linear approximation.
And if we scroll down some more, we
can see the result of the radial bias function feature set,
which produces a better overall tracking because of the better
nonlinear estimate of the true disturbance.
And that's pretty cool, right?
Well, there is a bunch more that is
involved with setting up and running an MRAC controller.
But I hope between this video, this example
and the other references that I link to below,
you'll be in a good position to try this out yourself
and start getting more familiar with this powerful control
method.
So that's where I'm going to leave this video for now.
If you don't want to miss any future Tech Talk videos,
don't forget to subscribe to this channel
and also check out my channel, Control System Lectures,
for other control theory topics as well.
Thanks for watching and I'll see you next time.