To create an MPC controller in MPT3, use the MPCController
constructor:
where sys
represents the prediction model, created by LTISystem
, PWASystem
or MLDSystem
constructors (see here).
As an example, let us consider an LTI prediction model, represented by the state-update equation {$x^+ = A x + B u$} with {$A = \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix}$} and {$ B = \begin{bmatrix} 1 \\ 0.5 \end{bmatrix} $}
Next we specify more properties of the model:
A number of other constraints and penalties can be added using the concept of filters.
Finally, we can synthesize an MPC controller with prediction horizon say {$ N=5 $}:
Now the mpc
object is ready to be used as an MPC controller. For instance, we can ask it for the optimal control input for a given value of the initial state:
You can also retrieve the full open-loop predictions:
Please consult this page to learn how to perform closed-loop simulations in MPT3.
Once you are satisfied with the controller's performance, you can convert it to an explicit form by calling the toExplicit()
method:
This will generate an instance of the EMPCController
class, which represents all explicit MPC controllers in MPT3. Explicit controllers can be used for evaluation/simulation in exactly the same way, i.e.,
Consider an oscillator model defined in 2D.
Linear discrete-time model with sample time 1
Set constraints on output
Set constraints on input
Include weights on states/inputs
Compute terminal set
Compute terminal weight
Add terminal set and terminal penalty
Formulate finite horizon MPC problem
The next example demonstrates how to achieve regulation to a nonzero steady state. Consider a model of an aircraft discretized with 0.2s sampling time
Given the dynamics of the model, one can compute the new steady state values for a particular value of the input, e.g.
The computed values will be used as references for the desired steady state which can be added using "reference" filter
To fomulate MPC optimization problem one shall provide constraints and penalties on the system signals. In this example, only the input constraints are considered
The penalties on outputs and inputs are provided as quadratic functions
which yields a quadratic optimization problem to be solved in MPC. The online MPC controller object is constructed with a horizon 6
and simulated for zero initial conditions over 30 samples
The simulation results can be plotted to inspect that the convergence to the new steady state has been achieved
Back to MPC synthesis overview.