# setconstraint

Set mixed input/output constraints for model predictive controller

## Syntax

``setconstraint(MPCobj,E,F,G)``
``setconstraint(MPCobj,E,F,G,V)``
``setconstraint(MPCobj,E,F,G,V,S)``
``setconstraint(MPCobj)``

## Description

example

````setconstraint(MPCobj,E,F,G)` specifies mixed input/output constraints of the following form for the MPC controller, `MPCobj`:Eu(k + j|k) + Fy(k + j|k) ≤ G + ε For more information, see Mixed Input/Output Constraints.```

example

````setconstraint(MPCobj,E,F,G,V)` adds constraints of the following form:Eu(k + j|k) + Fy(k + j|k) ≤ G + εVUse this syntax to specify hard custom constraints or to change the default constraint softening.```

example

````setconstraint(MPCobj,E,F,G,V,S)` adds constraints of the following form:Eu(k + j|k) + Fy(k + j|k) + Sv(k + j|k) ≤ G + εVUse this syntax if your mixed input/output constraints include measured disturbances.```

example

````setconstraint(MPCobj)` removes all mixed input/output constraints from the MPC controller.```

## Examples

collapse all

Specify a constraint of the form $0\le {u}_{2}-2{u}_{3}+{y}_{2}\le 15$ on an MPC controller.

Create a third-order plant model with three manipulated variables and two measured outputs.

```plant = rss(3,2,3); plant.D = 0;```

Create an MPC controller for this plant.

`MPCobj = mpc(plant,0.1);`
```-->The "PredictionHorizon" property of "mpc" object is empty. Trying PredictionHorizon = 10. -->The "ControlHorizon" property of the "mpc" object is empty. Assuming 2. -->The "Weights.ManipulatedVariables" property of "mpc" object is empty. Assuming default 0.00000. -->The "Weights.ManipulatedVariablesRate" property of "mpc" object is empty. Assuming default 0.10000. -->The "Weights.OutputVariables" property of "mpc" object is empty. Assuming default 1.00000. ```

Formulate the constraint in the required form:

`$\left[\begin{array}{l}\begin{array}{ccc}0& -1& 2\end{array}\\ \begin{array}{ccc}0& 1& -2\end{array}\end{array}\right]\left[\begin{array}{c}{u}_{1}\\ {u}_{2}\\ {u}_{3}\end{array}\right]+\left[\begin{array}{cc}0& -1\\ 0& 1\end{array}\right]\left[\begin{array}{c}{y}_{1}\\ {y}_{2}\end{array}\right]\le \left[\begin{array}{c}0\\ 15\end{array}\right]+\epsilon \left[\begin{array}{c}1\\ 1\end{array}\right]$`

Specify the constraint matrices.

```E = [0 -1 2;0 1 -2]; F = [0 -1;0 1]; G = [0;15];```

Set the constraints in the MPC controller.

`setconstraint(MPCobj,E,F,G)`

Create a third-order plant model with two manipulated variables and two measured outputs.

```plant = rss(3,2,2); plant.D = 0;```

Create an MPC controller for this plant.

`MPCobj = mpc(plant,0.1);`
```-->The "PredictionHorizon" property of "mpc" object is empty. Trying PredictionHorizon = 10. -->The "ControlHorizon" property of the "mpc" object is empty. Assuming 2. -->The "Weights.ManipulatedVariables" property of "mpc" object is empty. Assuming default 0.00000. -->The "Weights.ManipulatedVariablesRate" property of "mpc" object is empty. Assuming default 0.10000. -->The "Weights.OutputVariables" property of "mpc" object is empty. Assuming default 1.00000. ```

Assume that you have two hard constraints.

`$\begin{array}{l}{u}_{1}+{u}_{2}\le 5\\ {y}_{1}+{y}_{2}\le 10\end{array}$`

Specify the constraint matrices.

```E = [1 1; 0 0]; F = [0 0; 1 1]; G = [5;10];```

Specify the constraints as hard by setting `V` to zero for both constraints.

`V = [0;0];`

Set the constraints in the MPC controller.

`setconstraint(MPCobj,E,F,G,V)`

Create a third-order plant model with two manipulated variables, two measured disturbances, and two measured outputs.

```plant = rss(3,2,4); plant.D = 0; plant = setmpcsignals(plant,'mv',[1 2],'md',[3 4]);```

Create an MPC controller for this plant.

`MPCobj = mpc(plant,0.1);`
```-->The "PredictionHorizon" property of "mpc" object is empty. Trying PredictionHorizon = 10. -->The "ControlHorizon" property of the "mpc" object is empty. Assuming 2. -->The "Weights.ManipulatedVariables" property of "mpc" object is empty. Assuming default 0.00000. -->The "Weights.ManipulatedVariablesRate" property of "mpc" object is empty. Assuming default 0.10000. -->The "Weights.OutputVariables" property of "mpc" object is empty. Assuming default 1.00000. ```

Assume that you have three soft constraints.

`$\begin{array}{l}{u}_{1}+{u}_{2}\le 5\\ {y}_{1}+{v}_{1}\le 10\\ {y}_{2}+{v}_{2}\le 12\end{array}$`

Specify the constraint matrices.

```E = [1 1; 0 0; 0 0]; F = [0 0; 1 0; 0 1]; G = [5;10;12]; S = [0 0; 1 0; 0 1];```

Set the constraints in the MPC controller using the default value for `V`.

`setconstraint(MPCobj,E,F,G,[],S)`

Define a plant model and create an MPC controller.

```plant = rss(3,2,2); plant.D = 0; MPCobj = mpc(plant,0.1);```
```-->The "PredictionHorizon" property of "mpc" object is empty. Trying PredictionHorizon = 10. -->The "ControlHorizon" property of the "mpc" object is empty. Assuming 2. -->The "Weights.ManipulatedVariables" property of "mpc" object is empty. Assuming default 0.00000. -->The "Weights.ManipulatedVariablesRate" property of "mpc" object is empty. Assuming default 0.10000. -->The "Weights.OutputVariables" property of "mpc" object is empty. Assuming default 1.00000. ```

Define controller custom constraints.

```E = [-1 2; 1 -2]; F = [0 1; 0 -1]; G = [0; 10]; setconstraint(MPCobj,E,F,G)```

Remove the custom constraints.

`setconstraint(MPCobj)`
```-->Removing mixed input/output constraints. ```

## Input Arguments

collapse all

Model predictive controller, specified as an MPC controller object. To create an MPC controller, use `mpc`.

Manipulated variable constraint constant, specified as an Nc-by-Nmv array, where Nc is the number of constraints, and Nmv is the number of manipulated variables.

Controlled output constraint constant, specified as an Nc-by-Ny array, where Ny is the number of controlled outputs (measured and unmeasured).

Mixed input/output constraint constant, specified as a column vector of length Nc.

Constraint softening constant representing the equal concern for the relaxation (ECR), specified as a column vector of length Nc.

If `V` is not specified, a default value of `1` is applied to all constraint inequalities and all constraints are soft. This behavior is the same as the default behavior for output bounds, as described in Standard Cost Function.

To make the ith constraint hard, specify V(i) = 0.

To make the ith constraint soft, specify V(i) > 0 in keeping with the constraint violation magnitude you can tolerate. The magnitude violation depends on the numerical scale of the variables involved in the constraint.

In general, as V(i) decreases, the controller hardens the constraints by decreasing the constraint violation that is allowed.

Note

If a constraint is difficult to satisfy, reducing its V(i) value to make it harder can be counterproductive. Doing so can lead to erratic control actions, instability, or failure of the QP solver that determines the control action.

Measured disturbance constraint constant, specified as an Nc-by-Nmd array, where Nmd is the number of measured disturbances.

## Tips

• The outputs, y, are being predicted using a model. If the model is imperfect, there is no guarantee that a constraint can be satisfied.

• Since the MPC controller does not optimize u(k + p|k), the last constraint at time k + p assumes that u(k+p|k) = u(k+p–1|k).

• When simulating an MPC controller, you can update the `E`, `F`, `G`, and `S` constraint arrays at run time. For more information, see Update Constraints at Run Time.

## Algorithms

collapse all

### Mixed Input/Output Constraints

The general form of the mixed input/output constraints is:

Eu(k + j) + Fy(k + j) + Sv(k + j) ≤ G + εV

Here, j = 0,...,p, and:

• p is the prediction horizon.

• k is the current time index.

• u is a column vector manipulated variables.

• y is a column vector of all plant output variables.

• v is a column vector of measured disturbance variables.

• ε is a scalar slack variable used for constraint softening (as in Standard Cost Function).

• E, F, G, V, and S are constant matrices.