Transcript for:
Understanding Control Theory Principles

Hi everyone, welcome back. Okay, so we've spent the last few lectures looking exclusively at x dot equals ax. Okay, so this linear system of equations, figuring out how to solve it, what the dynamics look like, and really boiling down to the fact that the future state of your system depends almost entirely on the eigenvalues of this A matrix. So if they're unstable, your system's unstable. If they're stable, your system is stable. Okay? And so what we're finally ready to do now is add control to manipulate the system, to bend the system to behave the way we want it to. So we're going to add a plus bu, and u could be a vector, so I want to make it very clear that... U could be in R, let's say, Q. Okay, so there could be Q inputs U. A lot of the times I'm going to act like it's a single scalar input of time, but it could be a vector and B could be a matrix. Okay, so let's think about what the sizes of these things are. A is R n by n. B is R, has to be n tall. And Q inputs Y so that this can multiply. an add up to be an x-tall vector. Okay, so this is the system we're going to be talking about from now on. We know what we want, we want to shape the eigenvalues of A, and so sometimes with control we're going to be able to shape the eigenvalues of A, and that's what we're going to talk about now and in the future. So basically, when can we use feedback control to manipulate the system to do what we want, and if it is controllable, if I can manipulate it, how do I... design this control law u, how do I design that input so that it actually drives my system to the behavior I want. And so again I want us to remember that so now we could say our system is x dot equals ax plus b u, okay, so u is the input, it feeds the system. And later on, we're not going to do this now, but later on, I'm just maybe going to put this in a different color. So later we're going to talk about measurements y that equals c times x, where y is going to be in our p. I could have p measurements of my system. But for now, what we're going to do is we're going to act like our system measurements are y equals just x. We're going to act like c is the identity, and we can measure all of our state x. So we're going to act like we can measure everything. And then... Sorry for the squeaking. I hope that's not as annoying for you as it is for me. What we're going to do is design a control law, u as a function of x, so that this system is manipulated to behave well. Okay, so I'm going to say, and I'm just going to tell you the answer. It's going to be minus a matrix K times x. This is, in some sense, optimal for linear systems. Okay, so it's optimal for linear systems in some sense. I'll tell you what that means. Again, this is just kind of a high-level boot camp, so I want you to get the gut feeling first, and then you can figure out when things could break down. Okay, but I have some system, x dot equals ax. I'm going to add a plus BU. I'm going to force it. I've got some control knob U I get to manipulate my system with. And what I'm going to do is I'm going to actually measure the state. So if I want this thing to be stable, I'm going to measure the state and if that state is moving away from where I want it to, I'm going to proportionally increase or decrease my control to try to regulate that into stability. And so it turns out that u equals minus kx, let's write that out, u equals minus kx, if the system is controllable, which I'll tell you what that means in a minute, then for a certain special matrix k this is kind of the best controller to stabilize the system or to change the eigenvalues to where you want them to be. So out of all of the possible functions of x that you could be, just a proportional linear control k times x turns out to work great. And so that's awesome for us. If we have a linear system, we don't need some exotic nonlinear control u equals sine of x squared. Linear control does great. That's what I want you to take away just to start. Now, okay, and if you plug this in, let's just go down a couple more steps along this. So if I plug in... And we've done this before, x dot equals ax minus bkx. So I'm plugging in minus kx for u. That equals, excuse me, a minus bk. So this is my new A matrix with feedback. With sensor-based feedback control, I can actually change the dynamics. This is my new dynamical matrix, and hopefully I can place these eigenvalues anywhere I want. That would be kind of amazing. By choosing k, I can drive the eigenvalues of my system with feedback to be anything I want. As stable as I want, or maybe I want it to be barely stable, depends on the application. And what's remarkable, is that I can actually change the dynamics of my system. is that for many, many systems you can do exactly that. The system is completely controllable, and with the right choice of k you can completely change these dynamics. Okay, so what I'm going to talk about today is called controllability. Okay, so that's the name of the game. controllability that's what we want we want to control the system now I am going to start off defining things loosely in kind of intuition and words and then what we're going to do is build up to more mathematical tests and ideas for why and when this works okay roughly speaking though my system is controllable if I can choose u equals k and place the eigenvalues of this system anywhere I want. So if the system is controllable, then I can put the eigenvalues anywhere I want with a good choice of k. If the system is controllable, it also means that by the right manipulation of u, I can actually steer my state x to anywhere I want, anywhere in the state space that my linear approximation is valid. Then with the right if-and-whisper, my system's controllable. If I can drive the eigenvalues to any place I want, then I can also pick some really good control U that will steer my system anywhere I want it to go. Anywhere. Anywhere in Rn, in all of these n directions. Now, that might sound like a lot to ask, but your car is more or less controllable, right? You can parallel park, you can get it places. So this idea of being able to steer the system with your inputs... To go to a state that you want is not so crazy. Okay? And what we're going to talk about now is when the system is controllable and how to test for controllability. Okay? And the great thing is it's a super duper simple test in MATLAB or in a computer package or linear algebra to test these things. So, what impacts whether or not my system is controllable. So this is my system. What do I have access to that makes it more or less controllable? Okay, now I tell my students that as a control engineer, oftentimes I'm given. a system that's been already designed. They already have x dot equals ax. It's an airplane. And they're not going to rebuild that airplane to give me a different a just because I want it to be different. They give me an airplane, doesn't work the way they want, and so they want a feedback control to manipulate that pre-built system and change its dynamics with control. Now if you're lucky, you might get to choose b, but chances are you don't. So again, in an aircraft example, b is is, for example, where the ailerons or the rudder or the elevators. All the control surfaces tell you how your control affects the forces and therefore the dynamics and the state of your aircraft. So generally speaking, this is a long way of saying that in most control systems, you are handed an A matrix and a B matrix. You do not get to choose them. They're given to you. Okay, so someone hands you a system. It has an A matrix, some dynamics, and it has a B matrix. That's the set of actuators they've built into the system. And all you get to do is measure, hopefully, a lot of X, but maybe only part of the state, and feed that back into a control law U. Okay, so long way to say A and B are fixed. You get to control U in a control system. Okay. And so the only things that really impact whether the system is or is not controllable are those A and B matrices. Depending on the choice of A and B, the system may be easy to control or it may be impossible to control. And it's nice to be able to tell someone, if they hand you a system, they say, gee, I sure would like you to control this. Instead of you just telling them, oh, I tried really hard, it didn't work. You should be able to tell them, no, mathematically your system is not controllable because you built B wrong. If you built B A different way I could control it. And so that's what I'm going to give you the power to do today, is a simple test using only A and B. And I'm actually going to write this out. So there's a test in MATLAB called CTRB of A, B. Okay, so you type this into MATLAB for an A matrix and a B matrix, and it'll spit something out that'll let you tell if the system is controllable. And we'll get to that in a minute, okay? Okay, so mathematically if I wanted to prove to you which systems are and are not controllable, it would take a decent amount of work. So what I'm going to do is I'm going to start with some examples of systems that are obviously controllable, and then I'm going to take some systems that are obviously uncontrollable, and we're going to try to find some rules for when systems are probably controllable and probably uncontrollable. Then we're going to show in MATLAB how to test any system. and then after that I'm going to go through a little bit of mathematical justification so that you get some intuition for kind of more mathematically why these things are doing what they're doing. Okay, as a really simple example, and we can do this in continuous time or discrete time, it really doesn't matter, let's take a system of equations, x dot, and remember this is a vector x, equals and I'm going to pick some dynamics. So I'm going to pick first of all some diagonal dynamics. So two eigenvalues 1 and 2, unstable system, whatever, doesn't matter, times x1 and x2. Maybe I should just write x1.x2. just to make it a little easier to follow. So x1.x2. equals this. Now this is my A matrix. And I'm going to give you an example of a bad B and a good B. Okay, so this should be pretty obvious if it's good or bad. So let's say I have that control system. Okay, so x dot equals ax plus bu. So this is my A matrix, my B matrix, and the control knob I get to fiddle with. And again, we are assuming in this case full state feedback, that is what this is called. If I measure my full state and I feed it back, that is full state feedback. Is this system controllable? Just think for a minute. Do you think you can control this system or not? Okay, when I ask students in class, usually they say, well, I can definitely control x2 because u feeds directly into this x2 equation, but x1 is completely uncoupled. I might as well say x1 dot equals x1. and then an x2 equation. The x1 equation has nothing to do with u, nothing to do with x2. So this x1 direction is completely uncontrollable. This a, b pair is uncontrollable. You can control x2 but I can't steer the system anywhere in x1 that I want and I can't stabilize this unstable dynamics. So this is uncontrollable. I'm going to say unctrb x. Okay, not good. This is uncontrollable. Now how would you modify this system to make it controllable? Okay, that's maybe the easiest question is how would I modify b to make it controllable, from uncontrollable to controllable? Okay, remember b can have multiple columns and multiple inputs. I can have more than one u. I can have u1 and u2. So if I instead wrote this as, let's say in an alternate universe, I have plus 1, 0, 0, 1, u1, u2. This is... controllable. Check. Okay, because now I have two different control knobs, U1 and U2, and U2 feeds directly into X2, and U1 feeds directly into X1. So I can independently use feedback to stabilize both of these directions. So this means I have more control authority. I have more actuators. I have more knobs to turn. And I have more authority over my states X1 and X2. So one way I can make my system controllable is just to add more actuators and make it more control have more control authority. So I say every column of B and every input signal every input channel is an extra actuator. It's another control knob I get to turn and that makes the system controllable. So kind of intuitively we know that this system is uncontrollable because you you and X2 don't touch X1. So X1 is just alone and unstable. But here my control can feed into both of those and so this is controllable. So these are kind of the two most obvious cases. cases of uncontrollable and controllable. But let's go a little deeper. So there are shades of gray. There's things that are not obviously controllable or uncontrollable. So another example is if I had 1, 0, 2, you know, x1, x2. Let's keep the same u. 0, 1 the same b, but now if I add a coupling term, so if it's not a 0 up here Now the system magically becomes controllable. Now, I haven't proven that it has become controllable, but take my word the system is actually controllable. So the reason is, so remember I can choose U to stabilize the x2 direction now, right, because it feeds directly in, but now the x1 equation depends on x1 and x2. x2. So I can simultaneously stabilize x2 and by the schedule of how I manipulate x2 I can also stabilize x1. Now again I haven't shown you why this is true but there can be these cases where it's not as obvious but this is actually a controllable system. Okay, so in the decoupled case it's uncontrollable, but if these variables are coupled, sometimes it becomes controllable, which is really cool, and it's useful for control because it means with one actuator, if these states are coupled, then I might be able to control it anyway. So this is super cool, even if I have a super high dimensional state, like there is, you know, a thousand things I care about, In my system, if the A matrix and the B matrix have the right properties, so this A matrix is kind of tightly coupled with itself, then I might get away with having one control input, one column B, and one knob, and I might be able to simultaneously stabilize or manipulate all of those states, which is really remarkable. And that's one of the successes of control theory, is that oftentimes, even for very complicated systems, you can get away with relatively few actuators and relatively few sensors, and you can still control and observe the system. Okay, we're going to get to that a little bit more as we go along. But what I want to... I guess what I want to show you to start with is an idea of the simple test. Okay, so I want you eventually to understand why this is uncontrollable and this is controllable. But for now, I want you to first of all know what is the MATLAB command and how do I use it. And then we're going to start building up kind of more theoretical basis for why these two systems have different mathematical properties. Okay, so let's... do this as follows. So if I have an A matrix and a B matrix, there is a special matrix called the controllability matrix and it's not this C here, I draw it as curly C. Hopefully you can tell the difference, but it's a matrix. And that matrix is given by B. So B is a matrix or a column vector or a set of column vectors. Next to it I'm going to append more columns given by a times b, and I want you to convince yourself that a times b is the same size and shape of b at least. Followed by a squared of b, dot dot dot, all the way up to a to the n minus 1, times b. Okay? So this came out of left field, pretty much unmotivated. I'm going to tell you why this is what we want to be looking at and how to interpret the answers, but it's going to take a little time to build up, so just bear with me for a minute. So if I have a system A, x plus b, u, and I want to know can I control that system? Can I manipulate x1 and x2 to do whatever I want? Can I change the eigenvalues of this matrix arbitrarily? The first thing I do is I build this matrix. And this could be a big matrix, but for small systems like the pendulum or like these, I can do it by hand. So I build this matrix, and then I look and I see if it has full column rank. Okay? So for example, in an n-dimensional system, if this has n linearly independent columns, then the system is controllable. Okay, so if I take B and I pass it through the dynamics a bunch of iterations, so that's, again, why I like to think about discrete time, because this is kind of like time 1, time 2, time 3, if it was a discrete time system, but we'll get to there. So if I take this matrix and it has column rank of n, then the system's controllable. If it is rank deficient, if it does not have a full column rank of n, then the system, there's some directions, there's some directions in Rn that are uncontrollable, that I simply can't... touch with B. And so what this does is this essentially probes the system. This is kind of an impulse response and I'll talk about that in a minute. But I kick the system in the B direction and I let it ring through the system and if all of the directions in Rn were reached to some extent, then the system is controllable. But if there are some directions in Rn that are not in this subspace, then those can't possibly be controlled with plus Bu. Okay, and again I'm going to build up more math in future lectures, but I just want to kind of foreshadow what we're doing. So if rank of this controllability matrix equals n, so if and only if actually, so if and only if the rank of this is equal to n, then system is controllable. Okay, so that's the mathematical statement. I build this matrix for A and B, and if the rank is N, then the system is controllable. Which is great. It's a relatively simple criterion to test if my system is controllable or not. Okay? What I don't like about it is that it's a purely binary decision. It's like it's either yes, it's controllable or no, it's not controllable. It doesn't tell you how controllable, and that's really really important is how controllable the system is. But we'll talk about that in a minute. about that in a minute. Okay, so let's try, let's call this system star and let's call the system double star and let's actually compute this guy for my uncontrollable system and for my controllable system. Okay, so let's try this out. So star, let's do it right here. So first things first, I'm taking this system and I'm literally taking the A matrix and the B matrix and I'm building this matrix. Okay, so what is curly C? Well, first column is B, which is 0, 1. Okay, great. Now we take B and we multiply it by A and that's the next column. So what's B times A? Well, it's 0, 2. Okay, and because the system is two-dimensional, I can stop there. I can stop at a to the 1 times b and see if this is full rank. But let's just multiply one more time and see what's this ab times a. So what's a squared b? Well, it's 0, so I'm taking 0, 2 times 0, 2. Now I get a 4. So if I kept going, I'd get a 0, 4, 0, 8, 0, 16. Notice... I would always have a row of zeros. So these are always pointing in the same direction. This is pointing in the, purely in the x2 direction. This is also pointing in the x2 direction. They can't touch the x1 direction in the top. So this does not have full column rank. This only has rank in the 0, 1 direction. It does not have any rank in the 1, 0 direction. So this has rank equals 1 and it's uncontrollable. Okay, so that's how you would check. So intuitively we knew this was uncontrollable, but by running it through our test, we literally stack up b, then ab, we look at the column rank and the rank is equal to 1. This is linearly dependent on this. The second column depends on the first column. It's just 2 times the first column. So this thing has determinant equal to 0. It's ranked efficient. It's uncontrollable. Great. Okay, let's try double star. So double star. So curly C, my controllability matrix. Now I have exactly the same B, so the first column is the same. 0, 1, that's great. But now what I get to do is I multiply this new B times this A. Okay, and so just moving so that you can see this, I get 1, 2. So by having this coupling term here, I now get a 1, 2 out. And if you look at this matrix, it has rank of 2. It has a determinant that's non-zero. So this has rank 2, and it is controllable. Okay? So this is a super simple criteria to tell if your system is or isn't controllable, and the downstream implications are incredibly profound. If your system's controllable, then you can arbitrarily place the poles of it anywhere you want choosing a feedback and you can drive the state anywhere you want with an appropriate you. Really amazing if the system is controllable. Okay so let's just review a couple of things. I have not told you why the rank of this being full rank mathematically means that I can control to any state or change the eigenvalues. That's actually somewhat complicated. I will show you why it's true in discrete time, but to carry it through to continuous time requires a lot of math. So I would recommend you look that up on Google or Wikipedia or somewhere. But more practically, this is something actually test on a computer. So in MATLAB, CTRB of A, B gives you this matrix. And so if you look at the rank of this matrix that comes out, it'll tell you if it's rank N or not. Okay, so it's really easy to check in MATLAB if your system is controllable. And I'll fire up MATLAB in a minute and actually walk through it. Okay. Anything else I want to say? Yeah, so a couple of other things. You can have a system like the pendulum, for example, that was nonlinear, and when you linearize it, it may be uncontrollable. But by taking advantage of the nonlinear terms that you neglected to write down this linearization, it might be nonlinearly controllable. So just because your linearization is uncontrollable, if you have an honest-to-goodness nonlinear system, it might be, or it might not be, not be controllable. That's a hard, hard problem and that's getting towards actual cutting-edge frontiers of real control theory is when is a nonlinear system controllable, you know, if it's linearly uncontrollable. But let's not get into that. If a system is linear, linearized, let's just look at if it's linearly controllable, and here's a criterion. Okay, the other point, super important point, and we're going to talk about this down the road, is, again, this is purely an up or down, yes or no decision. Is it controllable or is it not controllable? It's a binary rank decision. But I can have a different B that makes the system more or less controllable. So it might be mathematically controllable, but there might be a better choice of B that makes the system more or less controllable. or less controllable. And so the way that we look at that, and I'm going to tell you a lot more about this in the future, is if I look at the singular value decomposition, the SVD of this controllability matrix, so remember, this thing has dimension a height of n. Okay, this thing is n tall, so it has the same height, the columns that come out of this are the same height as states. And so if I look at the singular value decomposition of this, if I look at the left singular vector, they will be ordered from most controllable states to least controllable states. They will literally be directions in Rn that are most controllable all the way down to least controllable. So if you don't know what the SVD is, don't worry about it, but if you do know what the SVD is, then you should be starting to think that the SVD of this controllability matrix gives you a lot of rich information, not just about if the system is or isn't controllable, but which directions, which states are easy to control. control in those directions or not. And I always think about this in terms of analogies. Like, let's say I'm driving around and I've got some, you know, I've got a gallon of gas. Are there some directions that are easier for me to go to on that gallon of gas than other directions? And this... Singular value decomposition of the controllability matrix will allow you to get to that idea of which directions are the, can I go the farthest on a gallon of gas, and which directions are the hardest to go far on a gallon of gas. I covered a lot. We are going to have a whole lecture on looking at the singular value decomposition of this controllability matrix and looking at degrees of controllability. So, don't let that distract you. The main point is that if I have a system AX plus BU, maybe my boss hands me a system and this is coded and he says, can you control this? There is an easy test. I take A and B and I plug it into this command in MATLAB. I look at the rank of it and if it is full rank then the system is controllable. So that is really, really nice that there is a simple criterion. In the next lectures we are going to demonstrate why this is the right matrix to look at. We are going to take the singular value decomposition and look at... degrees of controllability. And more importantly, if the system's controllable, we're going to design the controller that makes it do what we want. So that's the ultimate end game, is if your system's controllable, let's design a controller u equals minus kx to control the system. This is a means to an end. I actually want to control a system. OK, make sense? Great. So for the last thing, let's just fire this up in MATLAB and verify that we can actually do this controllability step on the computer. Because it's pretty simple to actually code this up. And I want to convince you that this looks exactly like I said it should look. Okay. So I'm going to keep these down here just so that we can compare our MATLAB output because I hope I didn't make a mistake. And then we're going to look at the rank of this controllability matrix. So let's fire up MATLAB and let's clear everything. Awesome. Okay, and I'm going to get rid of my measurement equation. I don't want to have that there. Okay, so simple, simple, simple. Let's take our first system, star, and let's plug in a and b and look at this command. Okay, so a is actually not going to change, so it's... Oh, it is going to change, yep. 1, 0, 0, 2. Okay. And b equals 0, 1, column vector 0, 1. And let me make this a little shorter so that I don't overwrite my cool controllability matrices down here. Okay, good. So now in MATLAB, super simple. I have A, I have B. Just type in controllability of CTRB. Boom! Alright, exactly what I told you it would spit out. It spits out a matrix of this controllability matrix. Now, if this was a big system, you might not be able to tell what the rank is by hand. Let's just type in rank of ctrb. Okay, it has rank 1. We need it to have rank 2 because it's a two-dimensional system. It's ranked efficient, not controllable. Done. Okay, you can tell your boss this system is not controllable. Let's try this one. Okay, A equals here. It's going to equal 1, 1, 0, 2. B equals the same 0, 1. Now I'm going to look at CTRB of A, B. And now, lo and behold, I get this controllability matrix here that has an x1 component. So these are linearly independent vectors, but again, if I had a higher dimensional system, it would be hard to tell. So we look at the rank of the controllability, and it is full rank, so the system's controllable. This system's controllable, this system's uncontrollable. Super simple. And I'm going to show you a lot more MATLAB commands down the road that are based on these A and B matrices. So we can cook up... representation, a state-space representation. We can do impulse responses, frequency responses, we can simulate for different use, we can feedback the system, we can design good controllers to place the poles anywhere we want, and we'll do all of that down the road. Okay, thank you very much.