Setting Targets for Manipulated Variables

This example shows how to design a model predictive controller for a plant with two inputs and one output with target setpoint for one of the two manipulated variables.

Define Plant Model

The linear plant model has two inputs and one output. Define the plant as a transfer function, convert it to state space, specify the initial state, and extract the plant matrices for later use within the Simulink model.

plant = ss(tf({[3 1],[2 1]},{[1 2*.3 1],[1 2*.5 1]}));
x0 = [0 0 0 0]';
A = plant.A;
B = plant.B;
C = plant.C;
D = plant.D;

Design MPC Controller

Create an MPC controller with sampling time 0.4 s, and prediction and control horizons of 20 and 5 steps, respectively.

mpcobj = mpc(plant,0.4,20,5);
-->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.

Specify weights for both manipulated variables and output.

mpcobj.weights.manipulated = [0.3 0]; % weight difference MV#1 - Target#1
mpcobj.weights.manipulatedrate = [0 0];
mpcobj.weights.output = 1;

Define constraints for the manipulated variable rate.

mpcobj.MV = struct('RateMin',{-0.5;-0.5},'RateMax',{0.5;0.5});

Set a target for one manipulated variable

Specify target setpoint u = 2 for the first manipulated variable.

mpcobj.MV(1).Target=2;

Define the model name and open the Simulink model. Note that the output reference is a square wave. Then simulate the model, using the sim command.

mdl = 'mpc_utarget';
open_system(mdl)
sim(mdl);
-->Converting model to discrete time.
-->Assuming output disturbance added to measured output channel #1 is integrated white noise.
-->The "Model.Noise" property of the "mpc" object is empty. Assuming white noise on each measured output channel.   The first plot shows that the first manipulated variable reaches its set point after about 6 seconds, while the plant output reaches its reference.

bdclose(mdl)        % close the Simulink model