
This content was created by Guy Kawasaki. This content was uploaded by Guy Kawasaki. This is a YouTube video titled "Model Predictive Control" created on December 20, 2022, featuring a presentation by Subha Thomas from Wolfram Research. The talk covers the implementation and functionality of model predictive control (MPC) in the Wolfram language, discussing its features, constraints, and optimization problems.
Chapters
Hi, I'm Subha Thomas with Wolfram Research. I will be presenting the model predictive control and related functionality in the Wolfram language. Hello and welcome to this talk on model predictive control. As Jan mentioned, this is among the newest features that we have recently added. So we have been like steadily adding new features. We have been enhancing and polishing the functionality and control systems and its interaction with system modeler. I do not know how much at this point I'll be able to cover. So I'll try to skip something and just give you what's important and then hand it off to Sergio. So one thing I would like to emphasize is that the workflow hasn't changed. So whether you're designing an MPC controller or a pole placement or a pid, it's still the same. So in a sense it looks the same, but in another sense it's a completely new and widely used controller technique. So as before, the control problem is still the same. The general control problem is the same. We have a plant and we would like to improve its performance or change its characteristics in some way with the controller and in mpc, for this particular the way we design it, we rely on a linear model, okay? So we can also give nonlinear models or also models from system modeler. But those models are converted into a standard linear state space model. And that's where a discrete time model, and that's what is the basis for the design. So the MPC works by minimizing a cost. There are many ways you can formulate the cost. This is just one such example. Here X are the states and you are the inputs. So I'm minimizing this, which means I'm driving all the states and the input variables to zero. It's basically a regulator problem. And if this is achieved the system. That's the way we specify the objective for a regulator problem. Later, if I have time, I'll show how we can specify different cost to achieve tracking. We can specify different norms. The ETA here is the horizon. Here we have finite. We can also in some cases increase the horizon to an infinite horizon. And one of the distinguishing characteristics of MPC is the ability to specify constraints upfront. When you're doing PID or lqr, we do not specify the constraints. We use weights or the pole locations and then hope that, okay, and then we see how much control effort we take. And then we adjust the poles or the weights so that the controls are within the and the states are within the constraints. Here we can specify this upfront in a nutshell what happens in MPC is there is a model that we base the design on, there's a cost and constraints, and we have to solve an optimization problem at each instant. As Jan mentioned, this is not a trivial thing to do. I cannot just take any microcontroller lying on my desk and deploy an optimization problem to it. Even if I have a platform where I can do an optimization problem, it has to solve it fast enough depending on the process. Typically in chemical processes they are much slower than say, mechanical or aerospace processes. And so you have the time to solve an optimization problem. So the problem here in the main problem is that we do not have the controller in a closed form solution. But it turns out that if we base it on a linear model with linear constraints, we can reformulate this problem as a parametric optimization problem and then we can solve it offline, and then the controller becomes much simpler. And then we can even deploy this controller to microcontrollers like the Arduino. Okay, so let's see what a parametric optimization problem is. Here I'm trying to minimize an expression. Okay? Yeah, so here P is the parameter and there are two variables and of course I would expect the result to depend on the parameter P. What is interesting here is that in general the solution is a piecewise function and the minimum, the arguments at which the function is minimized is an affine function of P. So you'll see later what this means is that the control law we get is going to be in this structure. And so up front we can design the controller which is a piecewise affine function. It's basically a bunch of if else statements which we can deploy even to the simplest of microcontrollers. So if I'm here, I'm just plotting that you can see the different regions. This is the minimum arguments and this is the cost. This cost is like of secondary importance. We are more interested in the control, but this was the cost that was minimized in the different regions. So, okay, so how do we reformulate the mpcs, the MPC control problem as a parametric optimization problem. So here I have a simple model, it's an integrator, so that's the model and I specify a cost I want to. And I've chosen the horizon as three. So because I choose the terminal cases, terminal status, I'm not considering the terminal state, just for example. And I described define a bunch of constraints. Now I'm going to reformulate this. So every X that is greater than, that's positive, greater than zero I replace with the dynamics of the system. So I set up a rule for that, and then I get a new cost and a new set of constraints in terms of x0. That is, I've replaced every value, every state that is positive by its preview, but based on the dynamics of the system. And now if I look at the variables in the system, I have the input variables and then I have the state at time zero, so that I can treat as my parameter. So now I'm going to minimize this new cost and the new constraints for these variables with the initial state as the parameter. And you see how the control law turns out as a piecewise function of the states. So if we solve this parametric optimization problem, then we have solved our control problem for, for the system. Here I'm just going to quickly go through this. I just simulate the system. I take the simulation, I apply the control law, and I'm choosing some random initial state. And you can see it's driving to zero. The control is applied periodically. After this, it again starts over here and recycles. And you see that it eventually reaches zero. What are the MPC problems we can solve? We can solve regulator problems. Regulator problems. We are minimizing the states and the inputs. It basically drives the systems to zero. And there are different ways we can formulate it. These Q and U are the weights that we give to the weights to the states and inputs. We can minimize a squared norm, this is a squared two norm. Or we can minimize the one norm or an infinite or an infinite norm. We can also solve tracking problems. So instead of minimizing the states and the inputs, we can minimize, say the, we can minimize the error and the input increments. So this will cause the error is defined as the difference between the actual measurement and the reference. And if you solve this minimization problem, we get the system to actually track the defied reference. And I'm skipping over these diagrams because of lack of time. In some cases, we can solve the infinite horizon problem. And that is the, that's the best solution we get. We just divide the whole region into a bunch of regions. And for each region we have a control action. And this we can solve only for the two known problem. So this slide, I basically explain the usage, the usage of the function itself. The function is model predictive control. So if you take a plant, right, it can have two kinds of inputs. Some of them you can use for feedback. Some of the inputs coming to the system are disturbances of which we have no control. So we have to tell this Function what are the feedback inputs. The others are taken as disturbance. If you are tracking, we can say what functions we want to track. And then depending on whether it's a regulator or tracker problem, we. These are the, these are the keys in the association we use to specify these parameters. This will become clearer as when I show the examples and then there are constraints. We can specify constraints in various ways. This is just constraints on the states. These are constraints on combination of states. These are constraints on the state at a specific time instant. This is the constraint on how much the state can change. So you can. Basically I'm trying to say that you can do different kinds of combinations of constraints. And this works not only for the states, you can also give it in terms of the inputs or outputs. Okay, so I'm glad we got to an example. So, okay, here I'm trying to solve an MPC problem. I've chosen this dynamics for the plant. So I specify that and then I'm minimizing this cost. So I specify the weight, the weight to the states, the weight to the inputs and the horizon. And so that's going to be my cost and I specify a bunch of constraints. And then from here onwards it's just like any other control system function. We give those values to the model predictive controller and it returns this data. So with our updated workflow you don't have to worry about connecting the controller back to the system and just ask for the closed loop system and it will automatically do the connections for you and you can simulate the system. Okay, let me quickly run through the trial. So this, this problem I'm. It's almost same system. I'm solving a tracking problem. So I here I'm specifying the cost in terms of the error and the input increment and specifying the cost, specifying the cost and then the constraints giving it to model predictive controller. It's going to compute the data. I can get the closed loop system here. The closed loop system is assembled in a different way. Again, it's automatically done for you. And then we can simulate it for any set reference I can change it to. And this I just show it for another signal. Okay, so this one is for the infinite horizon problem where I said that, you know, it's, it's the hardest problem to solve because you're, you're trying to solve it all the way to horizon, the infinite horizon. So the way it works is after there's a region close to the origin where the constraints really don't come into play. And that Region is an invariant region where the. Where it's basically the LQR controller. And then the MPC controller comes in and tries to drive the system into this region. So we can see this here. So I've just summarized everything here. I have the model, the cost and the constraints. If I look at the feedback gains model, in this case, it's just a bunch of if else statements. If it's in this region, do that. So I can actually, I can visualize that and I can get the closed loop system and simulate it. You see, this is the invariant region. Anywhere from here, the system will not go out. The controller will just drive it back to the origin. If I start from somewhere else, it will drive it to the origin. Okay, so. Okay, so this I wanted to show. I just want to show the different models we can handle. We can handle the other nonlinear models in the Wolfram language. Here I've taken a system model. I specify its specifications, its cost, just the same as before. And now I compute the model predictive controller for that. Okay, and now you get the closed loop system. Right. It has to put it together in a different way. This is a system model, but again it's done automatically for you. So this one I can open in system model, hopefully. And you can see it's already laid out. And then you can simulate here. Yes, there are some things we automatically choose, like the state response. Everything here is zero. I have to actually perturb it a little bit. And you can see it being driven to zero. Okay, okay, I have both. Okay, let me see. So before I would like to quickly mention this. So this is a data object from before the closed loop system came. We got it automatically. But if you peek into that, you see this object. Discrete input output model. This is a new model we had to design in the system to handle these MPC controllers for the finite horizon. So that is the core controller model. On one hand, it's like a time series for at each instant. Because when you're doing the finite horizon, it's unlike the infinite horizon. We have to know at each instant what the control law is. So it's a bunch of piecewise functions. And it turns out that it's a very generic input output model that is applicable to more than just MPC controllers. So any linear time invariant system can be described using this. And here I show that a transfer function model can be. The discrete input output model is a special case of the transfer function model. You can see that it simulates both. And from this you can get a whole bunch of properties. So if I have a discrete input model, I'm really out of time. So I'm just going to rush through this and ask for a whole bunch of properties of this model. Okay, so just to quickly summarize, so the way we compute MPC controllers, it's based on a linear model, cost and linear constraints, and we solve this as a parametric optimization problem. So we can get the controller in a closed form solution that is readily available for deployment, and we have a streamlined workflow where you can get all the properties upfront. I will end with that. I'm really out of time. I apologize for the initial hiccup, but I'll be downstairs. So if you have any questions, please feel free to stop by. Okay. And I'm going to pass it on to Sergio. Right. Thank you.
More from Guy

Cheryl Strauss Einhorn | The Human Edge: Smarter Decisions in the Age of AI | Talks at Google

Rachel Glennerster | Innovation and the Center for Global Development | Talks at Google

Rebecca Winthrop | Rethinking the Purpose of Education in the Age of AI | Talks at Google

Dr. Robert Wachter | A Giant Leap: How AI Is Transforming Healthcare... | Talks at Google






