MATLAB Examples

Designing Model Predictive Controller at Equilibrium Operating Point

This example shows how to design a model predictive controller with non-zero nominal values.

The plant model is obtained by linearization of a nonlinear plant in Simulink® at a non-zero steady state operating point.

Contents

Linearize Nonlinear Plant Model

To run this example, Simulink® and Simulink Control Design® are required.

if ~mpcchecktoolboxinstalled('simulink')
    disp('Simulink(R) is required to run this example.')
    return
end
if ~mpcchecktoolboxinstalled('slcontrol')
    disp('Simulink Control Design(R) is required to run this example.')
    return
end

The nonlinear plant is implemented in Simulink® model "mpc_nloffsets" and linearized at the default operating condition using the "linearize" command from Simulink Control Design®.

Create operating point specification.

plant_mdl = 'mpc_nloffsets';
op = operspec(plant_mdl);
% Compute initial condition.
[op_point, op_report] = findop(plant_mdl,op);
% Obtain nominal values of x, y and u.
x0 = [op_report.States(1).x;op_report.States(2).x];
y0 = op_report.Outputs.y;
u0 = op_report.Inputs.u;
% Obtain linear plant at the initial condition.
plant = linearize(plant_mdl, op_point);
 Operating point search report:
---------------------------------

 Operating point search report for the Model mpc_nloffsets.
 (Time-Varying Components Evaluated at time t=0)

Operating point specifications were successfully met.
States: 
----------
(1.) mpc_nloffsets/Integrator
      x:         0.575      dx:     -1.82e-14 (0)
(2.) mpc_nloffsets/Integrator2
      x:          2.15      dx:     -8.38e-12 (0)

Inputs: 
----------
(1.) mpc_nloffsets/In1
      u:         -1.25    [-Inf Inf]

Outputs: 
----------
(1.) mpc_nloffsets/Out1
      y:        -0.529    [-Inf Inf]

Design MPC Controller

Create the controller object with sampling period, prediction and control horizons:

Ts = 0.1;                 % Sampling time
p = 20;
m = 3;
mpcobj = mpc(plant,Ts,p,m);
-->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.

Set nominal values in the controller.

mpcobj.Model.Nominal = struct('X', x0, 'U', u0, 'Y', y0);

Set output measurement noise model (white noise, zero mean, variance=0.01)

mpcobj.Model.Noise = 0.1;

Set MV constraint.

mpcobj.MV.Max = 0.2;

Simulate Using Simulink®

Reference signal for output vector

r0 = 1.5*y0;
% Simulate
mdl = 'mpc_offsets';
open_system(mdl)    % Open Simulink(R) Model
sim(mdl);           % Start Simulation
-->Converting model to discrete time.
-->Assuming output disturbance added to measured output channel #1 is integrated white noise.

Simulate Using SIM Command

Simulate

Tf = round(10/Ts);
r = r0*ones(Tf,1);
[y1,t1,u1,x1,xmpc1] = sim(mpcobj,Tf,r);

Plot and compare results.

subplot(121)
plot(y.time,y.signals.values,t1,y1,t1,r)
legend('Nonlinear','Linearized','Reference')
title('output')
grid
subplot(122)
plot(u.time,u.signals.values,t1,u1)
legend('Nonlinear','Linearized')
title('input')
grid
bdclose(plant_mdl);
bdclose(mdl);