 So last lecture we looked at linear quadratic optimal control and I also talked about realistic formulation before I move on to the last topic of this series of lectures that is model predictive control I want to go over this realistic LQOC formulation again little more systematically then what I did in my last lecture so that we understand the foundation why we modified the control law okay well it is feedback control in the last lecture I found it difficult to explain so I went back and re derived all these derivations which are given in particular in my notes for the innovation by support are not appearing in any book so but so they are I had to re derive some of those ideas they are there in different form but the specific formulation that is given here is not there so we had two problems one problem was we had to deal with disturbances right now at this stage let me not qualify whether they are measured or unmeasured you have to deal with disturbances okay we looked at a system when we started doing linear quadratic optimal control let me just remind you we just looked at this model right we just look at a model in which there was no disturbances there was no measurement error only problem that you wanted to look at was to bring the system from nonzero initial state to final state equal to 00 origin that was the only problem that you had to study and then why we have done this I mean once you have done the whole derivation and come to the realistic formulation you realize that you have done this because you wanted to come up with a formula for coming up with G infinity controller game okay once you get the controller game then you know you can modify to do other things for example disturbance rejection set point tracking all those things you can do further modification so now we derived the controller for this simplistic looking model okay now what I want to show that even when you have disturbances okay even when you have disturbances or if you want to take it to some obituary set point okay you can transform the model to a model which looks very very similar to this if I am done that then I have achieved what I wanted to do that is ejecting disturbances and moving to any obituary set point that is okay so I will move directly to and then well let me just throw this one slide again and then we wanted to move you wanted to design an LQ controller which moves to the origin the way we did this was we took a finite horizon formulation here and then we let n go to infinity with the derivation by taking a finite horizon formulation that n go to infinity and then we found the solution okay now let us let go to a more realistic formulation so let me start here problem of designing a linear quadratic optimal control okay for a system which is governed by this different equation okay I am adding two terms here one term is a constant disturbance in the state and a corresponding coupling matrix okay why I have used some different notation here will eventually become clear okay I could have used gamma d you have been using gamma d here in some cases you know the disturbance then you can use gamma beta equal to gamma d in some cases you do not know the disturbance then what you do so all those questions we will answer subsequent so right now I am keeping it leaving it fuzzy and I am not saying that this is a major disturbance or unmeasured disturbance or whatever I am leaving it open okay similarly I am assuming that there is some additive disturbance in the output there are two disturbances in the system one is the input disturbance and then there is an output disturbance right now I am assuming them to be constant not time vary step change like disturbance okay I want to control the system I want to control this system at an arbitrary set point R okay right now let us assume the constant set point okay let us assume a constant set point is this clear now I am taking a more realistic formulation is a disturbance in the state which is constant is a disturbance in the measurement which is constant and I want to take the system to set point R as K goes to infinity I want to reach a set point R R is an arbitrary set point we are looking at deviation variables like I said if you took take the quadruple time setup then 00 corresponds to the initial silly state where you are linearized and you might want to take it to some other set point which is not 00 so level equal to you know minus 4 centimeters and plus 3 centimeters whatever so that could be so I should be able to specify any set point I should be able to reject disturbances that is my ultimate goal of any controller design and then I seem to have done a design for a very simple system where there was no disturbances and I said I want to control at the origin now how do I tie these two together to achieve what really I want to do okay so let us assume that somehow at this stage okay we know this we know this signal beta s we know this gamma beta we also know this signal beta s and we know this gamma beta well I should have put C beta here slight error slight error in mind is a typo here this should be C beta so because this is C I have called this C subsequently and because this is gamma I have called this gamma is a slight typo I will correct that okay and here to you just correct this with C beta okay okay so now what happens is what is the steady state of this particular equation this is the steady state equation okay at the steady state okay at the steady state excess is equal to phi excess into gamma unit this gamma beta into beta s this is a steady state input disturbance okay this is a steady state output disturbance this is my steady state equation okay now I can from the steady state first equation okay from this first equation it follows that you know I just take this phi s on the left hand side I will get I – phi s I – phi s inverse into is this clear from the first equation it just follows this particular and then I can substitute for r I can substitute for r okay all these terms if I if I just substitute for excess here okay I eliminate and get the relationship between r us beta s and beta s okay now I have assume that beta s is known to me beta s is known to me this matrix is known to me this matrix is known to me all the matrices here are known to me okay r is given to me set point is given to me I want to use the set point r so operator has given me a set point okay who set specifies the set point operator as you as a control engineer we specify the set point I want to reach this particular point okay so you are given the set point so what is not known here is input us okay that should be maintained to achieve this set point in the face of these disturbances okay that can be computed now so I am just what I am doing here is this particular complex matrix C into I – phi gamma I – phi inverse into gamma I am going to call it as KU this is the notation simplified notation same thing is for this particular matrix I am going to call this as K beta okay and then this C beta remains here okay so when number of inputs equal to number of outputs that means number of controlled outputs is equal to number of measure number of manipulate variables this KU matrix okay this gain matrix KU gaugay still this is set gain matrix if you realize nothing but a set gain matrix this set gain matrix will be square and if the system is controllable this particular system will be this gain matrix will be invertible you should be able to go take the system to whatever final steady state that you want okay so this KU will be invertible matrix in which case you can write us to be this substitute back you will get excess okay so if you happen to somehow know the disturbances and if you happen to know if you happen to know the set point then you can find out and steady state that must be reached to achieve those set points and to reject the disturbances okay in spite of the disturbances if I maintain this us I should reach this excess maintaining this excess implies I have reached R that is where I wanted to be right I wanted to be at y is equal to R okay so if I maintain this if I maintain this us then I will reach excess if I reach excess I will reach R that is what I wanted I wanted to reach the set point R if I just do this I will reach the set point R everyone with me on this okay and of course if KU is not invertible if the number of inputs are more than the number of outputs then you can always replace this by pseudo inverse that is not a problem okay now what I am going to do is I am going to subtract this model I am going to subtract this model from the original model that I consider that is this model here well of course replace this by C here so this dynamic model and this steady state model I am going to subtract okay I am going to subtract these two models once I subtract these two models I get I get this model the disturbance constant disturbance terms disappear okay constant is it clear the tricks that I am doing now I subtracted the dynamic model and the steady state model from the dynamic model okay so what I got is this let us call this delta model okay let us call it delta model so this delta model is XK plus 1 minus excess now this model this model looks like the model for which we have developed a Q controller okay this model looks like so I can define this delta XK I can define delta UK I can define delta YK this is just translation of the model if you realize you are just translating the model okay you are changing the origin that is all okay now what is the meaning of controlling this model at the origin if you control this model at the origin then that means XK is equal to excess if XK is equal to excess and UK is equal to US okay that means you have achieved the set point at the desired set point in spite of the disturbances in the output and in the state okay so my controller design is done for this particular model and then you got this controller okay in terms of delta you got the controller which was the controller which is LQ controller okay you have chosen WX matrix and WU matrix all that you have done and then you got this controller and then so origin of this particular system corresponds to the desired set point okay so actually when I implement this control law I implement it like this okay when I implement the control law I implement it like this okay is this clear so basically what I am going to do next is I am going to change my controller like this now there is a transition from the previous light to this light see here I said this is excess and US they were not time varying okay they were not time varying because I had made two simplistic assumptions one simplistic assumption while disturbance levels are constant but disturbances can be drifting okay disturbances can be drifting second I had made an assumption that set point given is constant but you may have a set point trajectory see for example if you are controlling an aircraft and you want to take off okay then you want to go from height 0 to height whatever you know 2 km and you are given some set point trajectory the way you should go is like this okay so pilot will give a set point trajectory to the autopilot and autopilot will cruise the aircraft from the given level to the higher level okay when the situation comes when the set point is constant when the set point when the aircraft is cruising at a constant height okay the set point is constant then you only have to worry about a disturbances like wind gusts many of you have traveled in aircraft so you would know suddenly you will get some wind gusts and then aircraft will start shaking and you need a controller which will and this is typically done by the autopilot automatic controller on board autopilot will be on board computer doing LQ controller predictive controller whatever so the pilot does not now do this sitting there he would leave it to the controller to do that stabilisation so the disturbances could be time varying the set point could be time varying so I am trying to now modify this control law to accommodate both the possibilities so I am saying that is excess and you are so that translation that I do also need to be time varying the disturbances are time varying and if the set point is time varying then the translation of the linear system model that I need to do is also time varying that is the logic which is used here to you know deal with any kind of disturbances deal with set point tracking okay so I am now talking about RK RK is a set point trajectory it is changing at each time instant okay so here excess and us are the steady states that are estimated based on the current set point at time k and the current level of disturbances disturbances can change in future I will adapt to that okay so this is the basic idea so what is done in this innovation bias approach is that I have this observer which is developed from this observer which I have here I have taken prediction form the reason for taking prediction form of course I said the simplicity in derivation but also a prediction form of this kind can be arrived through time series modeling you have developed box Jenkins model so you have developed RMAX model developed equivalent state-press realisation we will get this directly we will get K and CD directly okay or you will get sorry L and CD directly that is what you get you go back and look at your notes you will see that I have made this connection that actually time series model is nothing but this Kalman filter okay so I have this observer this observer could be derived from first principles then you know Riccati equations and this it could be derived directly from data box Jenkins model or RMAX model state realisation you get this form okay does not matter now what I said is that I do not have a disturbance model right now let us assume that there are all unmeasured disturbances there are all unmeasured disturbances okay and if there are really unmeasured disturbances they are really white noise then this we know that EK will be a white noise okay but then I showed you that if EK is not going to be a white noise then the disturbances in the input side are step like or you know drifting disturbances they are not going to be EK is not going to be a white noise okay so or if there is a model plan mismatch EK is not going to be a white noise okay so what we do in such case is following I talked about this filtering of the disturbances so what I am going to do now what I am going to do now this okay let me go back here what I am going to do now I am going to take this EK EK to be same as beta which I use earlier you remember I use that beta and gamma beta okay I am going to take this L infinity and EK to be representative of disturbance in the state okay and L infinity to be the corresponding coupling matrix okay see here what I needed when I went here I needed this term gamma beta beta okay what I am going to do here is I am going to pretend that this L infinity is nothing but gamma beta and EK is EK is representative of the unmeasure disturbance which are drifting okay so of course this unmeasure disturbance has two components one a slow component other one is a fast component I want to knock off the fast component I want to look at the low drift low frequency drift which I am going to do using this filtering business using this filtering business I am going to filter this innovation errors and then filtered value I am going to take as a representative of the unknown disturbance and then what then I am going to just do this mapping I will just do this mapping okay I will say that my beta S is nothing but ESK okay beta gamma is nothing but L infinity okay then I will say that beta S is nothing but ESK and C neta is nothing but identity matrix okay who meant I do this mapping then I can use all that I have done earlier but I have to make one more assumption here okay what is that assumption I have to make the assumption that the disturbances do not change in future you have to think about this little deeper thing here that I am making an assumption that disturbance at whatever is the current filtered value of the innovation that is not going to change in the future that remains constant it is like a step it is like a step that is what I am going to assume right now okay this is a simplifying assumption to add or this another way of looking at it is that adding an integrator into the system but that you will probably realize later that I am actually making an assumption that is this beta is actually is remaining constant over the horizon or from 0 to infinity okay I am adding a simplifying assumption here same thing is true about the output disturbance I am saying that there is a constant output disturbance is a constant input disturbance and both of them can be approximated using this filtered value okay moment I make this simplifying assumption okay then my control law can be you know you just substitute here for gamma beta and Cneta and then beta and beta you substitute those values you will get the control law okay this particular control law can deal with drifting disturbances it can deal with it can deal with changing set point is that okay so that the trick to arrive at this was to shift the origin okay in fact shift the origin continuously on the fly okay you define what is the origin okay and then try to use the law that was derived to control that the origin to deal with the system which is actually changing which has changing disturbances or to track the set point okay so this is a trick all these things are possible of course because we are dealing with delier system you can do all kinds of manipulation okay linear algebra allows us to do all kinds of nice things and that is why we are able to you know design the controller only for a very simplified model then complicate the model and use the same controller all these things are possible because of linearity okay the real world of course is not non linear it is non linear but when approximations of linearity hold we can use this manipulation and implement this controller okay yeah which it is yeah so actually this I have taken another short cut here because I have assumed that while I am just trying to give you analogy and then there is one more deeper thing here because you are using observer and a plan together and then that the real derivation will be more complex but I am just trying to show it by analogy that you know it is as if assuming that there is a model which has beta k equal to l infinity and if you were to assume this you will arrive at the same controller that is what I am assuming so it is a to do it that to show truly it gives you offset free behavior I should consider the plant which is different state space model observer which is exact and then show that how offset is removed and all that but instead of doing that I am taking a kind of short cut by showing parallel okay so hope that you will understand it and then you know actual derivation you want to do for both together little more complex but it can be derived and that is not a problem you can have any problem I am just using better form as one easier to do I do not write two equations every time for observer so I am I can just do with only one single okay so let us now move to predictive control which is the thing that I have been waiting to teach right since the day one okay so as I said in my last lecture model predictive control is it is a multivariable controller online multivariable controller that uses a dynamic model explicitly okay it is one of the most widely used controllers in the industry today started with the chemical industry now it has spread to everywhere it is used in all kinds of applications well these two are the first to implement it industrially one was done in shell in 1976 or 74 they first implemented on the real problems but there was a paper in Automatica by this group from France and I think it was a closely held technology because it could do online control of a complex plan it was a computer control and probably one of the first last scale computer control system applications why it was done in the chemical industry first that is because the chemical processes are very slow okay and you have time to compute okay so my furnace if I am controlling or a distillation column I am controlling the time constant of a distillation could be column could be 45 minutes 1 hour and the settling time can be you know 5 hours 4 hours 10 hours so the sampling time for control can be as large as 10 minutes 5 minutes 10 minutes and then in the computers of those times you could only solve problems which are you know where you are time to compute so all the computations could be probably done in 30 seconds online computation so 30 seconds is pretty large compared to if I want to compute if I want to control the robot using these methods okay then I need very fast computations and that is now possible so that is why the technology which started with chemical industry has now moved to systems which are very fast okay aircraft control and all kinds but it started all the chemical industry because chemical processes are very slow a lot of time to compute why do you need time to compute online there is a departure here from the philosophy of control that we have been used to we had one fixed controller PID controller for example it has three parameters PID okay one differential equation or one difference equation being solved online okay which is very very simple you can you do not require any you know big computing time for this you could do it very very quickly okay LQ controller once you define a G infinity matrix once you find it G infinity matrix what all things that you need for online implementation matrix multiplication you need to write an observer and then you need matrix multiplication subroutine you know multiply matrix by vector matrix whatever if you have those things you can you have some few few calculations to be done at each control time okay you have to compute the predicted state estimate x hat k given k-1 that involves L infinity you compute L infinity G infinity you have to gain matrices you just need you know three equations one is the observer equation first you find out the information then find the observer calculation and then implement a control law okay so it is that that easy it is just two three equations to be solved online it is very easy here we are going to depart from that okay we are going to have a controller in which calculations will be done at each time instant separately okay and then it has been used in very large dimensional problems I will come to that little later so what is the what is this controller about this controller is same as optimal controller except some modification okay it is not going to be different from the quadratic optimal control it is just you know a cousin of quadratic optimal control but it is more practical suited for real real problems than quadratic optimal control well what is the difference between quadratic optimal control and this the first point is not a difference multiple interactions multiple input multiple output system quadratic linear quadratic optimal control can deal with it not a problem we are using a multiple input multiple output model the controller which you design using LQ approach will be handling multiple input multiple output interaction okay so that is not an issue second thing is a problem what about constraints what are constraints let us take a simple example of the devising a controller okay to navigate a vehicle within IIT okay what are the constraints just translate a real problem into control constraints what are the constraints speed limit good second it has to be on the left side of the road left half of the road you know the trajectory cannot be arbitrary okay there is only certain path which it has to follow it you may have an ideal path which is set point but it may not follow the set point you know so it has a boundary within which it has to be there what is manipulation what about manipulation can you have infinite manipulation can you increase can you increase the speed at any rate at which you want no you cannot there will be there will be some limit on the fuel injection okay there will be a maximum limit on the fuel injection there will be 0 limit you cannot go below 0 you cannot have negative fuel injection so that is not possible you cannot have fuel injection higher than certain value there will be a maximum fuel injection at rate of fuel injection okay so then rate at which you can ramp the fuel injection will it be limited it will be limited you know you drive motorcycles or cars you know that you it is not that just because you press the accelerators at whatever speed you want the real injection is going to be at that you know it is going to be whatever maximum rate it can deliver that is only rate it can deliver okay so there are real constraints on the system there are other kinds of constraints for example when I am driving the car there is a constraint that I should run the motor or I should run the engine in such a way that carbon monoxide emissions should be as small as possible or should be 0 okay efficiently running the engine so fuel to air ratio has to be very carefully maintained otherwise you know you will have unburnt hydrocarbons living into the atmosphere so there are atmospheric or environmental regulation which will tell you how should run the engine same thing is true about some other systems like chemical plants chemical plants you know what you release into the atmosphere there is a regulation you cannot release any amount of you know atmosphere or to the water okay so there is a regulation on coming from environmental consideration there are real problem you are running a furnace okay there is a maximum rate at which you can inject the fuel you cannot inject the fuel at instant rate but when you write a LQ controller it just says that controller output is gained times you know the state there is no way of saying in that LQ controller and actually UK is bounded UK is not any other any value it can take so what you do if you want to implement a LQ controller with bounds then what you do is you in a software you put an artificial limits you say that if controller calculates input which is higher than this value then do not send that value to the actuator you know send a value which is equal to what is this limit so there are ad hoc things that you have to do to maintain the system within the bounds this is possible when there are input bounds what about output bounds what about the fact that I am driving my LQ controller I make a move and my vehicle goes outside the boundary after some time not now after 15 minutes if I make a wrong move now my vehicle is going to go outside the road okay so what about this my LQ controller cannot really predict that after some time there will be a violation of constraint on the output not just the input and this is going to happen after some time not now okay so all these other examples I want to ramp up the temperature in the furnace okay and there is a you know that there are overshoots many times temperature will overshoot okay you want to go from 800 to 850 okay you start injecting bore fuel the temperature overshoot to 900 okay you do not want to go to 900 it might be touching the limit of you know some safety limit you do not want it to go to you know beyond say 870 but when you start doing this you have no clue when it is going to go to 870 it will happen in future okay the basic idea in model to control is that if you have a model online you use to do it forecasting okay you can use and foresee what is going to happen in future and then manipulate your control action now such that the future violations of the constraints are eliminated okay I am going to do this online all the time every sample in instance I am going to use this model do predictions over the future okay so how much in future how do you drive a car when I am driving the car okay starting from my hostel or starting from my home to let us say my office I do not have a plan for the entire trajectory I have a plan for next 10 meters okay I implement that and then I have another plan for next 10 meters okay I implement that and then I have another plan for next 10 meters maybe there is somebody crossing in between suddenly I see and I have to change my plan so I cannot have one plan I cannot have one optimal plan for the entire trajectory I need to have a plan which is changing as a function of time looking at the disturbances looking at a trajectory you know maybe in between there is some work going on and the road is bad I need to change my policy for you know accelerating or breaking okay I need to do that depending upon the situation current situation so what is the basic idea here the basic idea is very very simple actually what it will do controls is much more easy to understand that LQ when all those because this is something that we keep doing all the time okay when we keep working we have a dynamic model for the plant whether you do it doing the or unknowing the different story maybe after listening to this lecture you will realize that this is what you have been doing all the time in different context whether it is driving a car whether we are dealing with a course or whether you are dealing with your friends this is what we keep doing so given a dynamic model for the plant what we do is we actually we actually try to foresee what are the possible consequences of actions that I take now okay actions that I take now and then and then based on the forecast I decide what is the next move that I should make okay so what is happening here in model predictive control in model predictive control there is always a dynamic model which is running in parallel to the plant this model is used for forecasting okay and actually you solve or you formulate an online optimization problem at each sampling instance you formulate an optimization problem okay over a finite window let me just pictorize this and then tell you so what I am going to do is I have I am standing here at instant k okay k plus 1 k plus 2 is all future okay k minus 1 k minus 2 k minus 3 all past I am standing right now at instant k okay now this is this is inside my computer well I am sitting inside the computer I have this different equation model okay I can play with this different equation model I can do forecasting what if I give this sequence what will happen after some time okay so I can for every every forecasted input in the future see I am putting here a terminology you k plus l given k what does it mean it means that input that I am contemplating I have not implemented it okay I am going to implement this contemplated input only on my model inside the computer okay if I use this contemplated input on the model okay model will tell me what will happen in the future okay model will tell me what is happening and then that forecast is used to make the decisions now okay so if I can forecast I can see that you know for a certain input actually the predicted behavior will cross the target suppose this is my constraint suppose this is a temperature limit okay then I want to move from this point current point to this set point in such a way that I never cross this boundary okay if I have a fixed gain control law it is difficult to see what is going to happen in future here I can explicitly see what will happen in future because I am going to do simulations in future okay see when you when you when you are driving the car you have a constraint that you should not hit an object right so just imagine what you do when you drive the car and apply break and you actually have a dynamic model for the car behavior in your mind you dynamically construct a model for the object which is moving somebody comes on the way see there are times when when somebody is crossing the road okay you do not break there are times when somebody is crossing the road you break why because you have a model for the car you know when you will reach certain point okay and then you develop a model mentally as well we are far superior computers than all these so we can you know we can predict when somebody is going to cross the road and whether our car will be there at that point before or after and accordingly we can plan our action and this is a decision only for that particular window of time you do not you know once the object is gone you change your policy again you start actually again okay so you have a plan which is dynamic okay so the idea is that standing at this point I only forecast over a finite window in future okay I do forecast over let us say next 20 minutes or next 15 minutes okay using this forecast I am going to find out somehow this future optimal state of future input such that I read the desired set point without violating the bounds without violating the bounds on the input okay I am going to do this without violating the bounds on the input I am going to do it without violating the bounds on the state okay what I am going to do then is I am going to implement only one move I am going to implement only one move into the plan inject one move into the plan okay I move to this new point K plus 1 okay I reformulate my problem of deciding controller moves from K plus 1 to K plus T plus 1 so I have a moving window in time okay I formulate my control problem over a moving window in time and each time I solve it each time I solve it I just make I do not trust my see if you make this decision that you know you have some object coming and then you are going to slow down for next let us say you take a decision every 10 seconds and you keep it for 10 seconds okay you have a policy for you know 10 seconds for next two minutes you are going to slow down okay and then you will actually read this is your optimal policy right now looking at the object okay but then after 10 seconds or 20 seconds what happens is that the fellow who is crossing sees that a car is coming okay it decides to run and cross the road okay then you suddenly have you revise the policy you do not say that well I decided to go slow for next two minutes I am going to go slow you do not do that right you after 10 seconds or after 20 seconds you revise the policy you say okay now the things are changed okay let me now accelerate again let me change my policy so you do not trust your moves future moves for a long time you just touch them for a short period and then you change them right look at look at the way we deal with you know let us say exams okay so you know k plus 1 k is today k plus 1 is tomorrow k plus 2 is thereafter tomorrow and what are the disturbances quizzes and you know the real life problem and then you know depending upon what happens in the particular quiz today you decide your plan of what is the method input the preparation that you do for an exam to achieve certain goal what is the set point of course 10 out of 10 so and then what you do is you change your policy of preparing for a particular course depending upon there are multiple inputs one is what is being taught in the class okay second is what is quizzes and we are performing so there are so many inputs that keep coming to the system and then you do not say that I have decided to work only one hour for a day for next 15 minutes you do not do that right you probably implement your plan only for today tomorrow something else happens your particular quiz paper gets graded then you decide no no I am going to change my plan I am going to do it for 2 hours a day or 3 hours a day whatever okay so we have a moving plan and at any time with your semester we will have a plan for next 7 days okay and then that keeps changing depending upon the situation depending upon what is happening in the classes what is happening in the exams what is the result and so you keep adopting and you do not have a plan over a longer horizon you have a plan over shorter horizon so this is called prediction horizon in predictive control okay you have a prediction horizon you keep predicting your moves or predicting behavior over the next 7 days and then you keep adopting you only implement one move at a time you do not trust your optimal moves for a long time okay so my idea is going to be this my optimal optimization problem is formulated over a finite window of time and this window is going to move okay as I move in time okay so another analogy for this would be you know you are walking in a dark okay and when you have a torch with you with the torch you can see only 50 meters okay you take one more step you see next 50 meters okay so you are just every time going ahead into future and you move one step ahead and you see 50 meters next yeah K plus P here what I am saying here K plus P so at each optimization at each point I am going to form an optimization problem and solve it online okay I am going to solve this problem online optimal solution of this particular problem is not going to be a close form control law it is solution of an iterative optimization scheme okay so what becomes very very important here is to have very efficient online optimization procedure what may be there available you can solve very large optimization problems in thousands of variables in fractions of a setting now with the available computers with so much advances in the optimization you can do that and that is why all these things are feasible now and then you move on in time as a moving window okay so what is important here is that you are doing proactive constraint management every time you make sure that the inputs are within the constraint the projected outputs the forecasted outputs are within the constraint okay so that you keep ensuring every time and this is where it actually replaces a programmable logic controller where you know you handle constraints to ad hoc means here the model the control problem knows that there are constraints and it tries to handle it in a very systematic manner okay so what are the basic components of a manipulative control of course one is the state estimator okay or the internal model well I am going to present everything in state space format I am going to present everything using observer and all that that is not how historically it developed okay historically it developed through different ways people first started using what are called as final impulse response model and finite step response model and then later on the connections to the state space models was very shown and then now there are packages available in the industry which are based on the state space model so all this merging of all different ideas which I have done in the course has not happened exactly at the time the whole thing got developed it was developed in a different way and then you know people merge different ideas and you have a model form now so earlier people when those who actually developed these controllers in the shell did not try to use rmax well it is not that they did not know about rmax but they did not try to use rmax there are certain difficulties when you go to noise modeling so they use some simplistic noise models and they did not use observer the way we are using now so this was in early 70s not that those theory was not there but it is that the confidence to use it was not there for last scale plans and then state estimator the next thing is that how do you handle predictions how do you predict over the future okay and the third thing is online optimizations how do you solve the problem online in fraction of a second using optimization scheme okay so the three components so observer modeling this I have covered painfully through many lectures okay and in my opinion in any model predictive control scheme the key thing is the model okay you start from a scratch and develop a model which gives you good predictions okay you can appreciate when you are driving a car the key thing is the mental model you have for the dynamics of the car and dynamics of the objects which is moving in front of you it could be another car it could be a person who is crossing whatever okay that model that we are able to develop it is so critical in diving the car that if that model is not good there is actually okay so the modeling is the key to predictive control then you know you are going to use quadratic programming which is the efficient way of solving the problem or linear programming LP so all those codes can be used those can solve a last scale problem so we are going to pose this control problem finally as a linear quadratic optimal control or LQ quadratic programming problem or linear programming problem LP okay and so so I just want to emphasize now the controller will consist of a state estimator which is running in parallel and an optimizer online optimizer online optimizer will solve the control problem at every sampling instant presumably in the fraction of a second okay that is what is I show the time required for solving the control problem even though it is optimization problem is significantly small compared to the sampling interval if it is one minute I should be able to solve this control problem in one second if sampling interval is one second I should be able to solve this problem in point zero zero one second it possible now one millisecond is not a big deal you can have microprocessors which can solve an optimization problem iteratively online fraction of a second entire window will only use one and then we will move to the next optimization problem so we will be solving optimization problem one after another there is no one optimization problem see what was the problem with LQ formulation we made one giant problem we said from time zero to time n and n goes to infinity so which means in LQ formulation we tried to solve the problem as one mega problem from time 0 to time it's like saying you know design one controller that will move you from that will move your car from your hostel to here okay in solving one optimization problem offline there we did not solve it online we use lots of tricks we came up with the Riccati equation and then we came up with a solution with your optimal solution unconstrained optimal solution it was nice there but now you know I am going to say that well I cannot have one controller which is you know which is like panacea to move in system from initial point to some final point that's not possible okay so so now let's start doing the prediction we are at the point k is everyone with me with this equation we have this equation well I intend to change this to L infinity to be consistent with the notation I made some small errors those are correct I will upload a corrected version and sorry if you have to take print out of some things again but notations have to be very very consistent I make one mistake in rotation but LP is nothing but L infinity the same as L infinity okay the observer gets so this kind of a model could be obtained as a Kalman predictor it could be a Luenberger I am not qualifying this observer to be of any particular type can be whatever is your choice you can do it in a Luenberger observer you can it can be a realization of our max model it can be Kalman predictor whatever I don't care I have this model I have the state observer okay I am going to use this that observer to do prediction okay now so current at time k my estimate of x is given by this this equation yeah okay this okay-1 will be yk-1 corresponding me this will be when you are using okay-1 here it will be yk-1 and except k-1 okay okay now now we are at the time point xk we have the state estimate of the state at the current time point okay I want to move into future okay so what I am going to do now I am going to call this there are again two ways of doing it one way is this innovation bias approach the other way is state augmentation I am not going to describe the state augmentation and to describe innovation bias okay for the same things which I did earlier I am going to filter this innovations and take a filtered signal so this is what we have done earlier for the LQ controller and now okay now look at this problem of simulation into the future or forecasting into the future okay if you give me a guess of future inputs I am going to call them as uk-z given k these this notation means this is a contemplated future input not actually implemented on the real system it will be implemented only on the model okay the model inside my computer okay it is only for internal forecasting okay so this is my let us say you give me one set of such input what should be important as this inputs are within the bounds okay then how can I use the model to do forecast if I know the input okay if I if you give me a future input can I use my model to do forecast okay what I am going to do is this forecasted trajectory I have given here a different notation just to differentiate the fact that this is forecasted this is not really going to happen may or may not happen I am just forecasting okay so I am using my old different equation you just go back here I am just using this I am going to use this different equation okay in slightly different way in slightly different way I am going to use this equation the same equation so what is known to me here five okay gamma okay LP is known to me the gain is known to me and instead of E I am going to use a filtered value of E I want to knock off high frequency from this I want to use a filtered value of E so my prediction is going to look something like this Zk plus 1 okay when I implement this forecasted input it has not been really implemented it is only in the model okay the forecast will look like this okay the forecast will look like this this is LP that notation of L I will make it consistent okay yeah linearized model can also yes correct but then that signal will get captured in E E will become biased okay and then that information will come up as if it is a disturbance into the signal E okay so this E signal is actually trying to compensate for plan model mismatch for unknown disturbances so it also compensates for phi and gamma not being same as the plan okay so that is a very good question so these two compensations these two compensations are essentially added to compensate for model plan mismatch okay that the true plan will not have five it could be five five prime or something it could be gamma prime it could be C prime okay so do that is implicitly compensated through this signal okay implicitly compensates for this signal and it helps it is not that it does not work it works with this strict works okay see what I am doing here is I am tying up this prediction with the with the observer what an observer do you want me XK-1 if you remember here I got XK-XK given K-1 I got from the observer I am tying this up with my prediction as the initial point initial state so what I am saying is that the initial state of my prediction is same as the initial state of the observer brings the information from the path to current current to future is through this prediction okay and this is the this is the meeting point okay now if I implement the first move then the predicted output will be this what will be at K-2 one one more instant in future I am going to use this ZK-1 here you see here okay and then I am going to implement one more input you K-1 given K okay and I am going to assume that this disturbance remains constant over the horizon this does not change I made this assumption when I talked about LQ controller same assumption I am making here disturbance does not change over the future okay estimate of the disturbance what is this LS bringing in it is estimate of unmeasured disturbance is estimate of learn model mismatch everything club together is contained in the signal EF LS times EF and EF here most of them are bringing this information about unmeasured disturbances learn model mismatch everything is contained in this okay so my ZK-2 is going to look like 5 square ZK-1 Z and so here this is 5 gamma UK UK-1 given K is this here is this equation algebra clear yes algebra is pretty simple here okay what about K-3 I just go on writing out different equations see I have a dynamic model I can explicitly forecast so these Z here and why here are forecast this is how the system will behave in future provided I happen to implement I happen to implement UK given K UK plus one game given K UK plus two given K I can just go on doing this till you K plus P I can do P step I had predictions using my different equation model this predictions are not open-loop predictions they are closed-loop predictions in what sense I am feeding back information about unknown disturbances learn model mismatch through EF okay and through ES appearing in the output so I am correcting the output I am correcting the state dynamics to compensate for the fact that the model may not be exact there could be unmeasured disturbances in the state and in the output and what is the imposter what is what is used as a representative of these unknown inputs EF LF times ES and we are used as representatives of the unknown input okay so this is my forecast this is my forecast okay this is how the system will behave if I happen to implement one particular future input sequence right so it is like you could plot this if you have if you have if you are doing it very very fast okay you can actually for every input you think you can plot what will happen in future right this is the future trajectory so I actually created one future trajectory okay let us interpret this very carefully see what is the VK here VK connects with current state okay these are very very very nice interpretation I want you to understand this very careful this prediction p-step ahead prediction okay p-step ahead predictions of what is going to happen okay consist of two components one component is effect of the past on the future this is the effect of the past on the future and this is effect of the future on the future a dynamic system has a memory okay let us go back to this painful example of your study so XK given K-1 is the current state okay will it not have effect on what is going to happen on the nth nth it will have your overall grades it will have an effect okay but is everything lost no you still have project to do you still have you know for the nth nth to write so these are all future input and then you can study okay so these are all future input that will go into the system so what will happen after some time is a cumulative effect of two things one is past having effect on the future and future having effect on the future okay so in any dynamical system the dynamical system okay there are two components that influence the future one is past history influences the future okay and the you have degrees of freedom you can change the future okay you can change the future by injecting input move you make them carefully you can change the future okay you can change the future so this is this is what is the message here that there are three things here that three components there is one more component here which is effect of one model mismatch and unmajored disturbances on the future so that is captured through this EF okay so prediction of p-step ahead prediction using this observer has three components one is effect of the past behavior on to future effect of future inputs on the future and effect of past knowledge about model plan mismatch and disturbances on to the future okay so these three things which so in some sense this model also reflects what in here we keep saying what's going to happen in future is your Purane Karmonka so all this old karma comes to you know except K given K- but everything is not lost you have a degree of freedom to change the future so that is given so these two things here this and this will bring in the effect of the past and this is the future which you can manipulate so p here is called as prediction of right okay now how do I want to move from the current point to the final point see I am not at the set point currently I am not at the set point okay let us say you are driving or you are piloting a plane and you want to go from the height 10,000 meters to 15,000 okay what should be your set point trajectory should it be you know within one instant 15,000 15,000 15,000 or it should go gradually depends if you are you know civilian pilot or whether you are a you know fighter pilot if you are fighter pilot you want to go from 10,000 to 15,000 in the next second that's because maybe some missile is behind you and then you want to move as fast as possible to the new set point and you do not mind if it overshoots and you know but of course if you are a civilian pilot you want to go graduate the new set point okay how do you achieve this okay let me before I do the math let me show this visually here I think my figure has got moved so the question is when I am moving from here to here and I am moving from here to here this is my final set point this is my 15,000 feet I am currently at 10,000 feet okay you have been cruising near the 10,000 feet and suddenly you want to go to 15,000 feet I am just given here in terms of percentage okay you want to go to the this particular so should my trajectory be like a step future trajectory or should it be gradual okay should I move very very slowly here should I move by this trajectory should I move by this trajectory you know I have an option I can create a future trajectory to move from current point to the final point okay and then what I can say is that the prediction should be as close as possible to this trajectory is that okay see I am predicting okay how do you choose the moves you choose the moves such that you know the predicted behavior is very close to this desired behavior okay so I am giving a desired behavior from the current operating point to the final operating point okay so this is done through this trajectory generation this figure should have been figure has moved to a wrong point okay so what I am going to do now is I am going to do okay this this one slide is just to show that this particular model is equivalent to something that come here so how do I choose the inputs when I when you give me these inputs you should not give me an arbitrary input you should not say that you know input can go from 0 to some infinity you cannot do that you can change the input only at certain rates you can change the input only within certain bounds when I am selecting these inputs it should be chosen properly by the optimizer optimizer should know the limits on the input for optimizer that can be done by specifying the constraints okay so I can actually give the constraints I can also say that well after all I am not going to implement all the future input okay I am not going to implement all the future input I am going to implement only one of them I am going to discard the future input okay and then you know I am going to redo the optimization problem again okay then why compute next suppose I am predicting over next two hours why compute a future trajectory over next two hours if I am going to use only first one minute part of it okay so what we do is what is called as input blocking so instead of using I will just show you the equations look complex I show you picture where we show okay instead of saying that I am going to manipulate over the entire future horizon I am going to say that I am going to manipulate over one input in the next then say I am going to keep the input constant over next three instance I am going to keep input constant over next five reinstants I am going to keep the input constant over the next for the prediction okay instead of changing every input in the future I am going to constrain the movement in the future that is because even if I compute all these inputs optimally I am not going to use them again okay I am just going to throw it use only one move and move ahead okay so what I typically do is I do not give I do not use entire degrees of freedom into the future I constrain it second thing is I should choose this future input move in such a way that in such a way that they are within the bounds right this due low is the lower bound okay u high is the higher bound upper bound I should choose them in such a way that difference between two successive moves is also constrained I cannot excessively increase between two sampling instance I cannot excessively decrease between two sampling instance these are the real problems if you have a control ball you cannot take it from 50% to 0% in one second okay you can probably take it from 50% to 49% otherwise the mechanism will break so it is a limit on which you know you can actually move a system so those limits will get told to the optimizer so the limits on the move at a time okay we are called as these are called as rate of change of moves okay and then there is a constraint on look here I have drawn this constraint boundaries is the upper limit is the lower limit you cannot choose input beyond this point there is a limit on how much I can move at a time okay so I should actually obey all these constraints when I forecast okay so that is implicit in optimization problem and of course I talked about this future set point trajectory future set point trajectory generated by filtering technique okay you actually filter the current set point minus the current output through a difference equation a linear difference equation will actually create a filtered signal okay again just go back and think about what we have been doing till now this look equation looks little complex yeah input blockings see I can formulate the problem over the future by taking degrees of field can I go back can I go ahead and come back and input blockings I will do that this will become more clear why I am saying okay so there is mathematical way of generating future set point trajectory and that is given here let us assume that there is a way of generating the future set point trajectory and then how fast or how slowly you take it from the current point to the next point and we decided by tuning parameter gamma so that parameter gamma have given here this is nothing but linear difference equation again this is again a linear difference equation I am moving this I am generating set point trajectories from one point to the other point this is a tuning parameter I choose it once okay so every time I am at a current point I generate a smooth trajectory from here to okay okay now what I am going to do is let us keep this target okay so what I am going to do now is I am going to form an MPC problem as a constraint optimization problem constraint optimization problem which is such that such that this is the future set point trajectory minus the future prediction the difference between the future set point trajectory and the future prediction that is given by this okay what is this ES ES is the final value where you want to reach okay ES is the final value where you want to be okay so for the time being for the time being forget about this ES you understand what is this why are this is the future set point trajectory which I have generated I generate this set point trajectory here right I am currently at this point I am currently at this point I want to move here okay and these are my let us say this is my future set point trajectory this green value is what I want to use this is my future set point trajectory I want to move along this trajectory okay now what I am doing here I am defining the error between the desired trajectory and the forecast on the forecast okay what are what is it that I can change in the future input moves okay so these are my future input moves okay this part why had k plus j given k what does it depend upon future input moves it depends upon the future input moves okay so the difference between the future set point and the future behavior will be governed by future input moves okay I have defined here E transpose WE I am defining some kind of a distance measure what is this square of the distance this E transpose W this is error vector error between set point and the prediction okay that transpose WE will give you square of the distance okay then I am penalizing the input move I am penalizing the input move okay I am putting some weight on the future inputs okay and what is my MPC formulation my formulation is minimize this objective function with respect to minimize this objective function with respect to the future inputs okay minimize this objective function what is this objective function some of the square of errors from what is this what is this error between future behavior and the desired future set point I have a desired predicted behavior I have predicted behavior in the future the difference between that should be as small as possible ideally what should happen it should actually follow that future set point trajectory okay but I want to do this I want to minimize this difference such that you know you do not take excessive input moves I do not change the input suddenly okay I am putting a weighting here factor on input move okay I am putting a weighting factor here input move and just one minute let me complete this so this optimization problem this optimization problem is subject to constraints what are the constraints one constraint is the prediction constraint this model is being used to predict why had the okay prediction constraint subject to bounce on the input okay and subject to bounce on the move subject to bounce on the predicted outputs the better output should not go you know better output should not go much much beyond this the some constraints okay so this optimization problem input blocking constraint so all these constraints are solved so this problem in which you minimize this objective function subject to model equations prediction equations subject to constraints on the input on input moves on predicted future outputs okay this problem is solved online okay this problem is solved online okay so is this idea clear so what I am going to do is I am going to solve this online optimization problem okay and what I am okay after I get the optimal input moves I am going to just use this I am just going to set the optimal move only first move in that optimal input profile I am going to implement okay only the first move in that optimal input profile I am going to implement I am going to reject the entire optimal reformulate the optimization problem at the next point okay and resolve it okay why do I need to do this because because the disturbances keep changing all the time okay where is the information about disturbances coming in through this so this L times L times epsilon okay so through this L times here here here this EF will bring in the information about the disturbances planned model mismatch that can change every instance so I cannot trust my optimal solution too much I just implement one move okay I just implement one move and then resolve the problem for K plus 1 to K plus P plus 1 okay so I keep solving sequence of optimization problem there is no one closed form solution okay well this blocking is little difficult to understand in the beginning what I will do is I will slightly modify my loads and upload them I want you to implement this controller on your system okay so that is the real test of whether you understood what I am trying to teach in this course or not okay so if you can make it work nothing like okay so now why I am blocking I am blocking okay because you know anyway even if I were to consider all future input move and not block them see if I were not to block the if I were to optimize entire future input move I am just going to use one of them right I am going to discard rest so to reduce the dimension of the optimization problem okay I put this constant so when I put this constant the dimension of the optimization problem is reduced and then you work in a lower dimensional space than the higher dimension oh yeah yeah yeah so this input constraints if you put this input you will get a kind of suboptimal solution compared to if you do not do this that is there but then you know I am I am not trusting my suboptimal solution too much right I am just taking one move and then I am discarding the rest so we try to do this because you want to reduce the dimension of optimization so we will come back to this to do after all that