# 8.1.2. How to Incorporate Preview Information in the MPC Problem¶

## 8.1.2.1. Introduction¶

In this example the following discrete-time system is considered:

The control objective is to regulate the two states to zero using the input \(u_k\), while a disturbance \(w_k\) is acting on the system. The disturbance \(w_k\) gets predicted for a horizon of length \(N=10\), which is equal to the control horizon of the model predictive control problem solved at each time step by the FORCES Pro controller. At each time step \(k\), a predicted disturbance for the next \(N\) steps is considered by the FORCES Pro controller. For the cost function of the MPC problem, it is assumed that the relative importance of regulating the two states to zero is ten times as high as the penalty on applying an input. Further it is demanded, that the input magnitude of the input signal \(u\) lies in the range \([−1.8,1.8]\). The initial state of the system is set to zero, i. e. \(x_0=[0;0]\).

One can see that the disturbance drives the states far away from the desired value. In this example it is shown how FORCES Pro can significantly improve the dynamical behaviour by using the concept of ‘preview’ when such future information is available.

To implement a FORCES Pro controller with ‘preview’ one can either use the Simulink® interface or the MATLAB® interface. Here both options are presented. The result is the same.

## 8.1.2.2. Use preview information in the Simulink® interface¶

To implement a FORCES Pro controller which makes use of preview information, drag the `LTI_MPC`

block from the `LTI_MPC_lib`

from the `FORCES_PRO`

folder
into the Simulink® model. After renaming the block, double click on it and chose in the tab `Model`

the settings shown on the right side. In this example, the
preview information comes through the additive term `g`

. Check the option `parameter`

. `g`

is a parameter because at each time instant new disturbance
predictions enter the controller. Also note that the additive term `g`

is not constant over time, i.e. the disturbance prediction can vary over the prediction
horizon.

The rest of the configuration of the FORCES Pro block is the same as for the design of a standard MPC regulator described here. After finishing the configuration,
type `configure_block`

to obtain a customized solver for your controller.

The controller is now configured and the number of inputs ports to the controller is determined by the length of the preview horizon.

Add the data of the disturbance and its preview from the workspace to model and start the simulation. To see the impact of using preview information see the
section `Comparison of MPC with Preview and Standard MPC`

below.

You can download the Simulink® interface example `here`

.

## 8.1.2.3. Use preview information in the MATLAB® interface¶

The same problem can be solved using the MATLAB® Interface. The multistage problem is constructed as shown in the simple example here and is then extended as shown below.

As in the Simulink® interface, the parametric additive terms `g`

have to be defined. At each stage of the multistage problem, the
equality constraint change, therefore we have to define a parameter for each stage. In the definition of the parameters, `distx`

represents the name of the predicted disturbance at stage x of the multistage problem.

During runtime, the preview information is mapped to these parameters.

```
% RHS of first eq. constr. is a parameter: z1=-A*x0 -Bw*Road
parameter(1) = newParam('minusA_times_x0_BwDist',1,'eq.c');
% Parameter of Preview
parameter(2) = newParam('dist1',2,'eq.c');
parameter(3) = newParam('dist2',3,'eq.c');
parameter(4) = newParam('dist3',4,'eq.c');
parameter(5) = newParam('dist4',5,'eq.c');
parameter(6) = newParam('dist5',6,'eq.c');
parameter(7) = newParam('dist6',7,'eq.c');
parameter(8) = newParam('dist7',8,'eq.c');
parameter(9) = newParam('dist8',9,'eq.c');
parameter(10) = newParam('dist9',10,'eq.c');
```

After setting up the multistage problem with the parametric equality constraints, configure the solver settings (i. e. define solver
output and solver options), the solver can be generated by using the command `generateCode(...)`

. With the function provided by
FORCES Pro, the system is now ready for simulation.

You can download the Matlab code of this example to try it out for yourself by
clicking `here`

.

## 8.1.2.4. Comparison of MPC with Preview and Standard MPC¶

Figure 8.6 shows the dynamics of the system using a non-preview controller and a preview controller designed using FORCES Pro. One can see that the maximum deviation of the two states from their desired value is reduced by a factor 18, and 11, respectively. Compared to the open loop case, the magnitude of the deviation is reduced by a factor of 47, and 34, respectively.

Figure 8.5 shows the control action of both controllers. As expected, the input signal remains in the allowed range. One can see how the preview controller makes use of future information to provide a more aggressive control action that results in improved system performance.