Accelerating the pace of engineering and science

# Model Predictive Control Toolbox

## Using Custom Input and Output Constraints

This example shows how to design model predictive controller with mixed input/output constraints.

Setup MPC Controller

The basic setup of the MPC controller includes:

• A double integrator as the prediction model

• Prediction horizon of 20

• Control horizon of 20

• Input constraints -1 <= u(t) <= 1

Define the MPC Controller setup:

```model = tf(1,[1 0 0]);                          % Prediction model
Ts = .1;                                        % Sampling time
p = 20;                                         % Prediction horizon
m = 20;                                         % Control horizon
mpc_controller = mpc(model,Ts,p,m);             % MPC object
mpc_controller.MV = struct('Min',-1,'Max',1);   % Input saturation constraints
```
```-->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 Mixed Input/Output (I/O) Constraint

The sum of the input u(t) and output y(t) must be nonnegative and smaller than 1.2:

`                0 <= u(t) + y(t) <= 1.2`

To impose this combined (mixed) I/O constraint, formulate it as a set of inequality constraints involving u(t) and y(t):

```                u(t) +  y(t) <= 1.2
-u(t) + -y(t) <= 0```
```setconstraint(mpc_controller,[1;-1],[1;-1],[1.2;0]);
```

Define initial conditions:

```x01 = 0;                                        % Initial state: First integrator
x02 = 0;                                        % Initial state: Second integrator
```

Open and simulate the Simulink® model:

```if ~mpcchecktoolboxinstalled('simulink')
disp('Simulink(R) is required to run this example.')
return
end
```-->Converting the "Model.Plant" property of "mpc" object to state-space.
```bdclose('mpc_mixedconstraints');