Specifications

5 Designing and Testing Controllers in Simulink
5-18
Define the system parameters.
M1 = 1; % mass
M2 = 5; % mass
k1 = 1; % spring constant
k2 = 0.1; % spring constant
b1 = 0.3; % friction coefficient
b2 = 0.8; % friction coefficient
yeq1 = 10; % wall mount position
yeq2 = -10; % wall mount position
Define a model of M1 when the masses are separated. Its states are the position and
velocity of M1. Its inputs are the applied force, which will be the controller’s manipulated
variable (MV), and a spring constant calibration signal, which a measured disturbance
(MD) input.
A1 = [0 1;-k1/M1 -b1/M1];
B1 = [0 0;-1/M1 k1*yeq1/M1];
C1 = [1 0];
D1 = [0 0];
sys1 = ss(A1,B1,C1,D1);
sys1 = setmpcsignals(sys1,'MV',1,'MD',2);
The call to setmpcsignals specifies the input type for the two inputs.
Define another model (with the same input/output structure) to predict movement when
the two masses are joined.
A2 = [0 1;-(k1+k2)/(M1+M2) -(b1+b2)/(M1+M2)];
B2 = [0 0;-1/(M1+M2) (k1*yeq1+k2*yeq2)/(M1+M2)];
C2 = [1 0];
D2 = [0 0];
sys2 = ss(A2,B2,C2,D2);
sys2 = setmpcsignals(sys2,'MV',1,'MD',2);
Designing the Two Controllers
Next, define controllers for each case. Both controllers employ a 0.2 second sampling
period (Ts), a prediction horizon of p = 20, a control horizon of m = 1 and default values
for all other controller parameters.
The only property that distinguishes the two controllers is the prediction model.