Sie sind auf Seite 1von 9

DMC REPORT Ronak Jain

Note !

Please find the code at the following link.

https://github.com/ronakj91/Model-Predictive-Control-Dynamic-Matrix-Controller-DMC-Receding-
Horizon-Controller

Kindly use MATLAB2015a or higher to run the code

DMC on SISO system


Transfer Function Taken

Initialization
Some factors which are constant like and the matrix consisting of step response
difference terms are generated by a matlab program. For that purpose Values which are taken.

No. of past control moves

Prediction Horizon

Control Horizon

Tuning Factor

Sampling Time sec

Integration step size for plant sec

Code for generation of constants for DMC SISO


%DMC SISO Data Generator

clear;
close all;
clc;

N = 1700; %no. of past control moves


Ts = 0.01; %Integration Rate for plant
T_sampling = 0.1; %Sample rate for collection of step response coefficients

u_old = 0; %This is the control which was implemented at previous


s = tf('s'); %instant
K11 = (12.8*exp(-s))/(16.7*s+1); %Transfer Function

https://github.com/ronakj91/Model-Predictive-Control-Dynamic-Matrix-Controller-DMC-Receding-
Horizon-Controller
t_vec = 0:T_sampling:100; %
g11 = step(K11,t_vec); %step response coefficients are being
%collected in g11

g11 = [g11;g11(end)*ones(N-length(g11),1)];

P=600; %Prediction Horizon


M=200; %Control Horizon
lambda=60; %Tuning Factor
u = zeros(N,1); %Past control moves
y_meas = 0;
G=zeros(P,M+1);
g=g11; %Step response coefficients for the plant has

for k=1:M+1
for i = k:P
j = k;
G(i,j)= g(i-k+1);
end
end
Fac=(inv(G'*G+lambda*eye(M+1)))*(G');

g_1 = [g;g(N)*ones(P,1)];

temp_g2 = repmat(g_1(1:N)',P,1);
temp_g1 = g_1(2:P+1);
for i = 1:N-1
temp_g1 = [temp_g1 g_1(2+i:P+1+i)];
end
temp_f = temp_g1 - temp_g2;

Code for DMC


function u_optimal = fcn(y_meas,Fac,temp_f)
%#codegen
coder.extrinsic('evalin', 'assignin')
r = y_meas;
y_sp = 10;
u = zeros(1700,1); % here in triggered system zeros(N,1) is giving error
u = evalin('base','u'); % Read value from workspace
u_old = 0;
u_old = evalin('base','u_old');
alpha = 0.9;
ref = zeros(1,600);
for i =1:600
r = alpha*r + (1-alpha)*y_sp;
ref(i) = r;
end
f = y_meas*ones(600,1);
f = f + temp_f*u;
u_temp = Fac*(ref'-f);
u_optimal = u_old + u_temp(1);

https://github.com/ronakj91/Model-Predictive-Control-Dynamic-Matrix-Controller-DMC-Receding-
Horizon-Controller
u = [u_temp(1);u(1:end-1,1)];
assignin('base','u',u);
assignin('base','u_old',u_optimal);
end

https://github.com/ronakj91/Model-Predictive-Control-Dynamic-Matrix-Controller-DMC-Receding-
Horizon-Controller
Simulation Results
Set Point

https://github.com/ronakj91/Model-Predictive-Control-Dynamic-Matrix-Controller-DMC-Receding-
Horizon-Controller
DMC on MIMO system
Transfer Matrix Taken

Initialization
No. of past control moves

Prediction Horizon

Control Horizon

Tuning Factor

Sampling Time sec

Integration step size for plant sec

Code for generating constants for DMC MIMO


% DMC MIMO Data Generator
clear
clc

T_sampling = 0.1;
Ts = 0.01;
u_old_1 = 0;
u_old_2 = 0;

%% Definition of transfer functions


s = tf('s');
K11 = (12.8*exp(-s))/(16.7*s+1);
K12 = (-18.9*exp(-3*s))/(21*s+1);
K21 = (6.6*exp(-7*s))/(10.9*s+1);
K22 = (-19.4*exp(-3*s))/(14.4*s+1);

t_vec = 0:T_sampling:199.9;

g11 = step(K11,t_vec);
g12 = step(K12,t_vec);
g21 = step(K21,t_vec);
g22 = step(K22,t_vec);

lambda=100; %Tuning Factor


N = 1000; % Past control moves;
P=900; %Prediction Horizon
M=600; %Control Horizon
u1 = zeros(N,1); %Past control moves
u2 = zeros(N,1);

https://github.com/ronakj91/Model-Predictive-Control-Dynamic-Matrix-Controller-DMC-Receding-
Horizon-Controller
g11 = [g11;g11(end)*ones(P,1)];
g12 = [g12;g12(end)*ones(P,1)];
g21 = [g21;g21(end)*ones(P,1)];
g22 = [g22;g22(end)*ones(P,1)];

G11=zeros(P,M+1);
G12=zeros(P,M+1);
G21=zeros(P,M+1);
G22=zeros(P,M+1);

for k=1:M+1
for i = k:P
j = k;
G11(i,j)= g11(i-k+1);
G12(i,j)= g12(i-k+1);
G21(i,j)= g21(i-k+1);
G22(i,j)= g22(i-k+1);
end
end

G = [G11 G12;G21 G22];

Fac=(inv(G'*G+lambda*eye(2*(M+1))))*(G'); % 2(M+1)x 2P

temp_g2_g11 = repmat(g11(1:N)',P,1);
temp_g2_g12 = repmat(g12(1:N)',P,1);
temp_g2_g21 = repmat(g21(1:N)',P,1);
temp_g2_g22 = repmat(g22(1:N)',P,1);

temp_g1_g11 = g11(2:P+1);
temp_g1_g12 = g12(2:P+1);
temp_g1_g21 = g21(2:P+1);
temp_g1_g22 = g22(2:P+1);

for i = 1:N-1
temp_g1_g11 = [temp_g1_g11 g11(2+i:P+1+i)];
temp_g1_g12 = [temp_g1_g12 g12(2+i:P+1+i)];
temp_g1_g21 = [temp_g1_g21 g21(2+i:P+1+i)];
temp_g1_g22 = [temp_g1_g22 g22(2+i:P+1+i)];
end

temp_f_11 = temp_g1_g11 - temp_g2_g11;


temp_f_12 = temp_g1_g12 - temp_g2_g12;
temp_f_21 = temp_g1_g21 - temp_g2_g21;
temp_f_22 = temp_g1_g22 - temp_g2_g22;

temp_f = [temp_f_11 temp_f_12;temp_f_21 temp_f_22];

u = [u1;u2];
save('dmc_mimo_data');

https://github.com/ronakj91/Model-Predictive-Control-Dynamic-Matrix-Controller-DMC-Receding-
Horizon-Controller
Code for DMC
function [u_opt_1,u_opt_2] = fcn(y_meas_1,y_meas_2,temp_f,Fac)
%#codegen
coder.extrinsic('evalin', 'assignin')
r1 = y_meas_1;
r2 = y_meas_2;
y_sp_1 = 1;
y_sp_2 = -1;
alpha = 0.9;
u = zeros(2000,1); % 2Nx1; past moves
u = evalin('base','u'); % Read value from workspace
u_old_1 = 0;
u_old_2 = 0;
u_old_1 = evalin('base','u_old_1');
u_old_2 = evalin('base','u_old_2');
ref_1 = zeros(1,900); % 1,P
ref_2 = zeros(1,900);
for i =1:900 %1:P
r1 = alpha*r1 + (1-alpha)*y_sp_1;
r2 = alpha*r2 + (1-alpha)*y_sp_2;
ref_1(i) = r1;
ref_2(i) = r2;
end
ref = [ref_1';ref_2'];
f_1 = y_meas_1*ones(900,1);
f_2 = y_meas_2*ones(900,1);
y_meas = [f_1;f_2];
f = y_meas + temp_f*u; % Free Response
u_temp = Fac*(ref-f);
u_opt_1 = u_old_1 + u_temp(1);
u_opt_2 = u_old_2 + u_temp(601);
u = [u_temp(1);u(1:999);u_temp(601);u(1001:1999)];
assignin('base','u',u);
assignin('base','u_old_1',u_opt_1);
assignin('base','u_old_2',u_opt_2);
end

https://github.com/ronakj91/Model-Predictive-Control-Dynamic-Matrix-Controller-DMC-Receding-
Horizon-Controller
Simulation Results
Set Point_1 = 1 Set Point_2 = -1

Set Point_1 = 1 Set Point_2 = 1

https://github.com/ronakj91/Model-Predictive-Control-Dynamic-Matrix-Controller-DMC-Receding-
Horizon-Controller
Analysis

For the tuning parameters taken DMC is working good for SISO system with settling time of < 8sec while
PID is taking > 15 seconds to settle.

Settling Time DMC PID


Set Point = 10 < 8sec > 15sec

For MIMO system simulation has been run for two set of set points and results are as follows.

Settling Time DMC PID


Set Point_1 = 1 < 250 sec < 150 sec
Set Point_2 = -1 < 250 sec > 400 sec

Set Point_1 = 1 < 250 sec < 150 sec


Set Point_1 = 1 < 250 sec > 700 sec

References

Eduardo Camacho, F and Carlos Bordons (2002). Model Predictive Control. London. Springer.

https://github.com/ronakj91/Model-Predictive-Control-Dynamic-Matrix-Controller-DMC-Receding-
Horizon-Controller

Das könnte Ihnen auch gefallen