Accelerating the pace of engineering and science

# getconstraint

Model Predictive Control custom constraint definitions

## Syntax

[E,F,G,V,S] = getconstraint(mpcobj)

## Description

[E,F,G,V,S] = getconstraint(mpcobj) returns the custom constraints previously defined for the mpc object, mpcobj. The constraints are in the general form

 $Eu\left(k+j\right)+Fy\left(k+j\right)+Sv\left(k+j\right)\le G+\epsilon V$ (1-1)

where:

• j = 0,...,p.

• p — MPC prediction horizon.

• k — current time index.

• u — column vector of manipulated variables.

• y — column vector of all plant output variables.

• v — column vector of measured disturbance variables.

• ε — scalar slack variable used for constraint softening.

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

getconstraint calculates the last constraint at time k+p assuming that u(k+p|k) = u(k+p-1|k). This is because u(k+p|k) is not optimized by the model predictive controller.

## Input Arguments

 mpcobj MPC controller, specified as an mpc object.

## Output Arguments

 E Constant used in custom constraints as defined in Equation 1-1. [] if mpcobj contains no custom constraints. E is an nc-by-nu matrix, where nc is the number of custom constraints and nu is the number of manipulated variables. F Constant used in custom constraints as defined in Equation 1-1. [] if mpcobj contains no custom constraints. F is an nc-by-ny matrix, where nc is the number of custom constraints and ny is the number of output variables (measured and unmeasured). G Constant used in custom constraints as defined in Equation 1-1. [] if mpcobj contains no custom constraints. G is an nc-by-1 vector, where nc is the number of custom constraints. V Constant used in custom constraints as defined in Equation 1-1. [] if mpcobj contains no custom constraints. V is an nc-by-1 vector, where nc is the number of custom constraints. If V(i) = 0 — the ith constraint is hardV(i) > 0 — the ith constraint is softWhere i = 1,...,nc.In general, as V(i) decreases, the controller decreases the allowed constraint violation, i.e. the constraint becomes harder. S Constant used in custom constraints as defined in Equation 1-1. [] if mpcobj contains no custom constraints or there are no measured disturbances in the custom constraints. S is an nc-by-nmd matrix, where nc is the number of custom constraints and nmd is the number of measured disturbance inputs.

## Examples

Obtain the constraints associated with an MPC controller.

Create an mpc object with 2 manipulated variables and 2 measured outputs.

```p = rss(3,2,3);
p.D = 0;
p = setmpcsignals(p,'mv',[1 2],'md',3);
c = mpc(p,0.1);
```

Assume that you have two soft constraints.

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

Set the constraints for the mpc object.

```E = [1 1; 0 0];
F = [0 0;0 1];
G = [5;10];
V = [1;1];
S = [0;1];
setconstraint(c,E,F,G,V,S);```

Obtain the constraints for c.

```[E F G V S] = getconstraint(c)
E =

1     1
0     0

F =

0     0
0     1

G =

5
10

V =

1
1

S =

0
1```