## Design Workflow for Explicit MPC

To create an explicit MPC controller, you must first design a traditional (implicit) MPC controller. You then generate an explicit MPC controller based on the traditional controller design.

### Traditional (Implicit) MPC Design

First design a traditional (implicit) MPC for your application and test it in simulations. Key considerations are as follows:

The explicit MPC control law generated by the Model Predictive Control Toolbox™ software is such that the manipulated variable vector is piecewise function of the following variables:

*n*controller state variables (plant, disturbance, and measurement noise model states)._{xc}*n*(≥ 1) output reference values, where_{y}*n*is the number of plant output variables._{y}*n*(≥ 0) measured plant disturbance signals._{v}

Thus, you must fix all the other MPC design parameters to specific values before creating an explicit MPC controller. Fixed parameters include prediction models (plant, disturbance and measurement noise), scale factors, horizons, penalty weights, manipulated variable targets, and constraint bounds.

For information about designing a traditional MPC controller, see Controller Creation.

For information about tuning traditional MPC controllers, see Refinement.

Reference and measured disturbance previewing are not supported for explicit MPC. At each control interval, the current

*n*reference and_{y}*n*measured disturbance signals apply for the entire prediction horizon._{v}To limit the number of regions needed by explicit MPC, include only essential constraints.

When including a constraint on a manipulated variable (MV), use a short control horizon or MV blocking. See Choose Sample Time and Horizons, and Manipulated Variable Blocking.

Avoid constraints on plant outputs. If such a constraint is essential, consider imposing it for selected prediction horizon steps rather than the entire prediction horizon.

Establish upper and lower bounds for each of the

*n*=_{x}*n*+_{xc}*n*+_{y}*n*independent variables. You might know some of these bounds a priori. However, you must run simulations that record at least the_{v}*n*controller states as the system operates over the range of expected conditions. It is important that you do not underestimate this range, because the explicit MPC control function is not defined for independent variables outside the range._{xc}For information about specifying bounds, see

`generateExplicitRange`

.For information about simulating a traditional MPC controller, see Simulation.

### Explicit MPC Generation

Given the constant MPC design parameters and the
*n _{x}* upper and lower bounds on the independent
variables of the control law, that is,

${x}_{l}\le x(k)\le {x}_{u},$

the `generateExplicitMPC`

command determines
*n _{r}* regions. Each of these regions is defined by an
inequality constraint and the corresponding control law constants:

$\begin{array}{c}{H}_{i}x\left(k\right)\le {K}_{i},\text{\hspace{1em}}i=1\text{\hspace{0.17em}}\text{to}\text{\hspace{0.17em}}{n}_{r}\\ u\left(k\right)={F}_{i}x\left(k\right)+{G}_{i},\text{\hspace{1em}}i=1\text{\hspace{0.17em}}\text{to}\text{\hspace{0.17em}}{n}_{r}\end{array}$

The `explicitMPC`

object
contains the constants *H _{i}*,

*K*,

_{i}*F*, and

_{i}*G*for each region. The Explicit MPC Controller object also holds the original (implicit) design and independent variable bounds. As long as

_{i}*x*(

*k*) stays within the specified bounds and you retain all

*n*regions, the explicit MPC object provides the same optimal MV adjustments,

_{r}*u*(

*k*), as the equivalent implicit MPC object.

For details about explicit MPC, see [1]. For details about how the explicit MPC controller is generated, see [2].

### Explicit MPC Simplification

Even a relatively simple explicit MPC controller might require many regions
(*n _{r}* >> 100) to characterize the QP
solution completely. If the number of regions is large, consider the following:

Visualize the solution using the

`plotSection`

command.Use the

`simplify`

command to reduce the number of regions. Sometimes, this reduction can be done with no (or negligible) impact on control law optimality. For example, pairs of adjacent regions might employ essentially the same*F*and_{i}*K*constants. If so, and if the union of the two regions forms a convex set, they can be merged into a single region._{i}Alternatively, you can eliminate relatively small regions or retain selected regions only. During operation, as long as

*x*(*k*) stays within the specified bounds, if the current*x*(*k*) is not contained in any of the retained regions, the explicit MPC returns a suboptimal*u*(*k*), as follows:$u\left(k\right)={F}_{j}x\left(k\right)+{G}_{j}.$

Here,

*j*is the index of the region whose bounding constraint,*H*(_{j}x*k*) ≤*K*, is least violated. See the following section for more details._{j}

### Implementation

During operation, for a given *x*(*k*), the explicit MPC
controller performs the following steps:

Verifies that

*x*(*k*) satisfies the specified bounds,*x*≤ x(_{l}*k*) ≤*x*. If not, the controller returns an error status and sets_{u}*u*(*k*) =*u*(*k*–1).Beginning with region

*i*= 1, tests the regions one by one to determine whether*x*(*k*) belongs. If*H*(_{i}x*k*) ≤*K*, then_{i}*x*(*k*) belongs to region*i*. If*x*(*k*) belongs to region*i*, then the controller:Obtains

*F*and_{i}*G*from memory, and computes_{i}*u*(*k*) =*F*_{i}*x*(*k*) +*G*._{i}Signals successful completion, by returning a status code and the index

*i*.Returns without testing the remaining regions.

If

*x*(*k*) does not belong to region*i*, the controller:Computes the violation term

*v*, which is the largest (positive) component of the vector (_{i}*H*(_{i}x*k*) –*K*)._{i}If

*v*is the minimum violation for this_{i}*x*(*k*), the controller sets*j*=*i*, and sets*v*=_{min}*v*._{i}The controller then increments

*i*and tests the next region.

If all regions have been tested and

*x*(*k*) does not belong to any region (for example, due to a numerical precision issue), the controller:Obtains

*F*and_{j}*G*from memory, and computes_{j}*u*(*k*) =*F*_{j}*x*(*k*) +*G*._{j}Sets status to indicate a suboptimal solution and returns.

Thus, the maximum computational time per control interval is the time required to test each region, computing the violation term in each case and then calculating the suboptimal control adjustment.

### Simulation

You can perform command-line simulations using the `sim`

or `mpcmoveExplicit`

commands.

You can use the Explicit MPC Controller block to connect an explicit MPC
to a plant modeled in Simulink^{®}.

## References

[1] A. Bemporad, M. Morari, V. Dua, and E.N. Pistikopoulos, "The
explicit linear quadratic regulator for constrained systems,"
*Automatica*, vol. 38, no. 1, pp. 3–20, 2002.

[2] A. Bemporad, "A multi-parametric quadratic programming algorithm with polyhedral computations based on nonnegative least squares," 2014, Submitted for publication.

## See Also

`generateExplicitMPC`

| `mpcmoveExplicit`

| Explicit
MPC Controller