Any of the filters is activated using with
method and deactivated by without
method. The activation/deactivation must be done on a system signal such as inputs u
, states x
, and outputs y
. For instance, consider activation of the terminal set constraint on the state variable. This is achieved by
The deactivation of the filter proceeds by
In the next list you can find various filters for adjustment of MPC setups:
binary
block
initialSet
setConstraint
terminalSet
max
min
deltaMax
deltaMin
softMax
softMin
Adding binary constraints is achieved using the binary
filter. To impose binary on all elements of a given variable
use
To add binary only to elements indexed by idx
, call
Consider the following example with one state and one binary input. The model is constructed and the binary
filter is activated on the u
signal
In the rest of the MPC setup, the constraints are provided for the states
and penalties are specified
The online MPCController
object is constructed with the horizon 5
To verify that the binary constraints on input are respected, a closed loop simulation is performed from the initial condition x0 = -5
over 10 sampling instances:
The simulation results are plotted and one can observe that the input provides only binary values
The move blocking constraint is activated using block
filter. The move blocking constraint is useful for constraining the predicted control moves over the horizon to reduce the number of decision variables in the optimization problem. Consider a regulation problem of the following PWA model with a varying gain
The model operates under state and input constraints
For the MPC setup the following penalties are provided
and the online MPCController
object is constructed with horizon N=10
To reduce the number of decision variables, the inputs from the third prediction step are constrained to be equal. This is achieved via the blocking constraint as follows
To compare both controllers, the open-loop prediction is evaluated for the value of the state x0 = [-7, 8]
:
and plotted
The initialSet
filter activates polyhedral constraints on the initlal states {$x_0 \in P$} in the prediction. The constraints are useful when solving parametric optimization problem because it limits the exploration space for unbounded problems. This filter corresponds to MPT2 field sysStruct.Pbnd
. As an example, consider the model of the form
which operates under input constraints
and the following penalties
The initial conditions will be restricted to the polyhedral set
Formulating a finite horizon MPC optimization problem over horizon 4 and solving it explicitly
one can plot the resulting partition and the polyhedron set in wired frame to see that the solution is contained inside the initial constraint set.
The setConstraintSet
filter activates polyhedral constraints over the whole prediction horizon {$x_k \in P, k=0, \ldots, N$} in the prediction.
Consider the same model as in the previous example
which operates under input constraints
and the following penalties
In this case, the constraints on the states will be activated over the whole prediction horizon using the setConstraint
filter
The finite horizon MPC optimization problem is solved parametrically over the horizon 4
The partition of the explicit controller is significantly smaller as in the previous example because the state constraints must be active over the whole horizon. The set constraints are depicted in the wired frame in the figure below.
The terminal set constraint is activated using the terminalSet
filter. The constraint is active on the signal at the end of the prediction horizon {$x_N \in P $} where {$P$} is the polyhedral set.
Consider the following example
with the penalties on the system state and input
The objective is to reach the value of the state {$ x_N = 3 $} at the end of the prediction horizon. The equality constraint {$ x_N = 3 $} can be modeled as the Polyhedron
object
and added to the MPC design using the terminalSet
filter
Constructing the MPCController
object with horizon 5 and evaluating the open-loop response for the zero initial value one obtains the result
One can observe that the desired terminal state has been achieved in five steps of the prediction.
The upper bound on a system signal, indicated by max
filter, is activated by default. The constraint is imposed over the whole prediction horizon and is considered as hard constraint {$ s_k \le \text{max}, k=0,\ldots, N $} on the signal {$s$}.
The lower bound on a system signal is indicated by min
filter. Similarly as the upper bound constraint, the filter is activated by default and the constraint is imposed over the whole prediction horizon {$ s_k \ge \text{min}, k=0,\ldots, N $} on the signal {$s$}.
The upper bound constraint on a signal rate can be activated using deltaMax
filter. It is given as {$ \Delta s_k \le \text{deltaMax}, k=0,\ldots, N $} on the signal {$s$} where {$\Delta s_k = s_k - s_{k-1} $} is the rate of the signal. The filter is typically used with the deltaMin
constraint, see the example below.
The lower bound constraint on a system signal is activated using deltaMin
filter. The constraint is given as {$ \Delta s_k \ge \text{deltaMin}, k=0,\ldots, N $} on the signal {$s$} where {$\Delta s_k = s_k - s_{k-1} $} is the rate of the signal.
The next example considers a linear-time invariant system with one output and one input subject to input constraints provided as min
and max
filters
To add limits on the slew rate for the input, the deltaMin
and deltaMax
filters are activated and specified as {$ -10 \le \Delta u_k \le 10 $}
The penalties are provided as quadratic functions on the states and inputs
The online controller is constructed with the horizon 10
The ClosedLoop
object is created and simulated for 15 samples for the initial condition x0 = [-1; -2; 3]
. Note that for {$\Delta u$} formulation it is required to provide initial condition for the inputs as well u0 = 0
which is achieved as follows
In the figure below one can see the closed loop trajectories of the MPC subject to input rate constraints. The first subfigure corresponds to the output of the system, the second subplot represent the input (with constraints in dashed line) and the third subplot shows input rate (with constraints in dashed line).
The filter softMax
represents soft upper bound on a system signal. The soft constraints are allowed to be slightly violated when the MPC controller run into infeasibility problems. If the violation occurs, the MPC controller heavily penalizes the differences versus the nominal constraint in order to bring the system back to feasible area. The penalty for the constraint violation can be adjusted after activating the filter in the fields maximalViolation
and penalty
. The maximalViolation
field corresponds to the maximu allowed limit for violation of the constraint. The penalty
field represents the penalty function to be added to nominal cost function to account for constraint violation.
The soft lower bound can be activated using softMin
filter. The filter is typically used together with softMax
constraint to represent soft bounds on a system signal. If the violation occurs, the MPC controller heavily penalizes the differences versus the nominal constraint in order to bring the system back to feasible area. The penalty for the constraint violation can be adjusted after activating the filter in the fields maximalViolation
and penalty
as explained in the softMax filter. To better understand the concept of soft constraints,
assume the continuous input-output model is represented by the following transfer function
{$$ G(s) = \frac{2} {s^2 + 2s + 1} $$}
Since MPT supports only discrete-time models reprensented in the state-space, the continuous model is discretized with the sample time {$T_s = 1$}
The discrete-time state-space model can be imported to MPT as follows
The control objective is to maintain the reference value of the output {$y = 1$} and reject any uncontrolled disturbances. The model operates under input constraints
and soft output constraints that are restricted within the interval {$ 0 \le y_k \le 1.2 $}
After activation of soft constraints, the default values for the penalization of the outputs are present in the fields maximalViolation
and penalty
. For the purpose of this example, these values will remain unchanged, but one can modify them accordingly.
Note that the reference for the output signal {$y=1$} lies close to the upper {$ 0\le y_k \le 1.2 $} which could be potentially violated with external disturbances.
The reference signal is added by activating the reference
filter
The penalties on the system signals are provided as one norm functions
The MPC controller is constructed with the horizon 5 and exported to its explicit form
In order to model the external disturbance, the closed loop simulation is performed manually over 20 instances and the external disturbance is added at the 10th sample:
Inspecting the closed loop trajection one can notice that the output constraint value was violated after the disturbance, but the controller maintained feasibility and returned to the nominal operation immediately
It is sometimes of interest to add penalization on the rate of the signal {$\Delta s_k = s_k - s_{k-1} $}. This can be achieved by activating the filter deltaPenalty
and specifying the penalty function. As an example, consider the simple model {$ x_{k+1} = x_{k} + u_{k} $}
subject to input and state constraints
The objective is to regulate the system by minimizing the quadratic optimization criterion {$ \sum_{k=0}^{N-1} (x_{k}^{T}Qx_k + u_k^{T}Ru_k + \Delta u_k^TS\Delta u_k) $}. To activate the penalty on the input rate the filter deltaPenalty
is provided:
The MPCController object is constructed with horizon 5 and exported to explicit form
Since the deltaPenalty
is activated, the explicit controller is designed for the augmented system where the previous value of the input is the second state variable. The explicit controller can be plotted
and simulated in the closed loop setting for the initial condition x0 = 10
, u0 = 0
The results of the simulation are plotted in the figure below with the constraints depicted with dashed lines
The terminalPenalty
filter activates penalization of the state variables at the end of the prediciton horizon. In general, the terminal penalty function can be artibrary but for stability reasons it is often required that the terminal penalty satisfies certain properties. Typically, the terminal penalty is often computed as a value function of an unconstrained infinite horizon optimal control problem which has associated a stabilizing controller.
Consider a stable linear system subject to convex constraints
The objective is to regulate the system to the origin by means of MPC. The performance criterion is a quadratic function with weighing factors {$ Q = I $} and {$ R = 0.1 $}
The finite horizon MPC controller is defined over the horizon 2 and exported to explicit form
The animated simulation for one initial condition reveals that the controller does not provide stabilizing feedback
To remedy the stabilizing properties of the controller, the terminal penalty and the terminal set constraint are computed with the help of LQRPenalty
and LQRSet
methods
Subsequently, the appropriate filters are activated
and the corresponding values are provided
The new MPC controller object is created and exported to explicit form
The closed loop simulation is invoked and tested for multiple initial conditions
The explicit controller ectrl_new
designed with the terminal penalty and terminal set constraint is defined over smaller feasible area than ectrl
but
is able to stabilize the closed loop system for all initial conditions inside the feasible area.
The system model used in MPC synthesis can be extended with reference signals by activating the reference
filter. If activated, the difference of the current signal {$s$} versus the given reference {$r$} is going to be penalized, i.e. {$ s - r $}. The value for the reference signal can be be constant, or time-varying. In the case of time varying signal, it is marked with a string as 'free'
. For more details on design with time-varying references, see the part on MPC tracking problems.
In the next example, a penalization to constant, non-zero reference is shown. The model is described with one input, one output and three states as follows
The input signal is constrained
The objective of the MPC design is to minimize the quadratic cost function {$ \sum_{k=0}^{N-1} ( u_{k}^{T}Ru_{k} + (y_{k}-r)^{T}Q(y_{k}-r) ) $} by steering the output to the reference value {$r = 2$}. In MPT this can be achieved by providing the corresponding penalties on the signals
The finite horizon optimal control problem is constructed with the prediction {$ N=4 $} by constructing the MPCController
object
The simulation of a closed loop system is performed over 10 samples
and plotted
Back to MPC synthesis overview.