Professional Documents
Culture Documents
MPC - Andini Vira
MPC - Andini Vira
MPC - Andini Vira
Written by:
Andini Vira Salsabilla Z.P
5023201065
Lecturer:
Dr. Achmad Arifin, S.T., M.Eng.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, TeEngine, Series, ExtCtrls, TeeProcs, Chart,
Math, ComCtrls, Spin, VclTee.TeeGDIPlus;
type
TForm1 = class(TForm)
btn1: TBitBtn;
btn2: TBitBtn;
btn5: TBitBtn;
btn6: TBitBtn;
lbl1: TLabel;
lbl2: TLabel;
lbl3: TLabel;
pgc1: TPageControl;
ts1: TTabSheet;
mmo1: TMemo;
cht1: TChart;
cht2: TChart;
ts2: TTabSheet;
cht3: TChart;
cht4: TChart;
lnsrsSeries3: TLineSeries;
lnsrsSeries4: TLineSeries;
lnsrsSeries1: TLineSeries;
lnsrsSeries2: TLineSeries;
rb1: TRadioButton;
rb2: TRadioButton;
pntsrsSeries1: TPointSeries;
pntsrsSeries2: TPointSeries;
lst1: TListBox;
lst2: TListBox;
ts3: TTabSheet;
cht5: TChart;
cht6: TChart;
cht7: TChart;
mmo2: TMemo;
mmo3: TMemo;
se1: TSpinEdit;
chk1: TCheckBox;
chk2: TCheckBox;
lbl8: TLabel;
lnsrsSeries5: TLineSeries;
pntsrsSeries3: TPointSeries;
pntsrsSeries4: TPointSeries;
lnsrsSeries6: TLineSeries;
pntsrsSeries5: TPointSeries;
lnsrsSeries7: TLineSeries;
lnsrsSeries8: TLineSeries;
btn3: TBitBtn;
lbl5: TLabel;
se2: TSpinEdit;
se3: TSpinEdit;
lbl6: TLabel;
procedure btn5Click(Sender: TObject);
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure BacaDataStep;
procedure BacaDataImpulse;
procedure btn3Click(Sender: TObject);
procedure se2Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
type Matrix = array[1..10, 1..10] of Real;
type Vector = array[1..10] of Real;
type Matrix1 = array[1..10] of Vector;
var
Form1: TForm1;
nc, np, Nsim1, baris,kolom,z,time,orde : Integer;
x1_step,x1_impulse,x1,x2 : array[0..5000] of Extended;
y1_step,y1_impulse,s_step,s_impulse : array[-5..5000] of Extended;
rw,k1,k2,k3,k4 : Extended;
A,B,C,I,M_inv,M,Mad,Mbd : array[0..2,0..2] of extended;
M_ka,M_kb,M_kc : array[0..2,0..2] of extended;
t,xdot,dt,x,u,xdotdot,u1 : real;
sgn_step,sgn_impulse,C4 : Real;
row,col,sample1,sample2 : Integer;
respon_step, respon_impulse,asli,dot : Real;
Ahat,Ae,Be1,Ce,h1,F,c1,v1,phit,phi : Matrix;
Bhat, Chat,C5 : Vector;
implementation
{$R *.dfm}
end;
nsim1 := 150;
dt := 0.001;
orde := 4;
B[0,0]:=1;
B[0,1]:=1;
B[0,2]:=3;
C[0,0]:=0;
C[1,0]:=1;
C[2,0]:=0;
I[0,0]:=1;
I[0,1]:=0;
I[0,2]:=0;
I[1,0]:=0;
I[1,1]:=1;
I[1,2]:=0;
I[2,0]:=0;
I[2,1]:=0;
I[2,2]:=1;
row := 2;
col := 2;
end;
B[0,0]:=0;
B[0,1]:=1;
C[0,0]:=0;
C[1,0]:=1;
I[0,0]:=1;
I[0,1]:=0;
I[1,0]:=0;
I[1,1]:=1;
row:=1;
col:=1;
end;
x1_impulse[k+1]:= x1_impulse[k+1]+m_kb[kolom,baris]*u1;
x1_impulse[k+1]:=x1_impulse[k+1]*((1-0.0005)/(1+0.0005));
y1_impulse[k] := m_kc[kolom,baris]*x1_impulse[k];
end;
end;
lnsrsSeries1.AddXY(k/100,x1_step[k]);
lnsrsSeries2.AddXY(k/100,x1_impulse[k]);
end;
end;
procedure difeq(x,xdot,u:real);
begin
xdotdot:=-0.5*xdot-x+u; //plant model
end;
procedure rk_pltA(x,xdot,u:real);
begin
difeq(x,xdot,u);
k1:=0.5*dt*xdotdot;
difeq(x+0.5*dt*(xdot+0.5*k1),xdot+k1,u+0.5*dt);
k2:=0.5*dt*xdotdot;
difeq(x+0.5*dt*(xdot+0.5*k1),xdot+k2,u+0.5*dt);
k3:=0.5*dt*xdotdot;
difeq(x+dt*(xdot+k3),xdot+2*k3,u+dt);
k4:=0.5*dt*xdotdot;
asli:=x+dt*(xdot+1/3*(k1+k2+k3));
dot:=xdot+1/3*(k1+2*k2+2*k3+k4);
end;
BacaDataStep;
BacaDataImpulse;
while i<=Nsim1 do
begin
if t>0 then
begin
sgn_step:=1;
sgn_impulse:=0;
end
else
begin
sgn_step:=0;
sgn_impulse:=1;
end;
//step
rk_pltA(hasil_x1,hasil_xdot1,sgn_step);
hasil_x1 := asli;
hasil_xdot1 := dot;
respon_step := hasil_x1;
//impulse
rk_pltA(hasil_x2,hasil_xdot2,sgn_impulse);
hasil_x2 := asli;
hasil_xdot2 := dot;
respon_impulse := s_impulse[i];
lnsrsSeries3.AddXY(t,respon_step);
lnsrsSeries4.AddXY(t,respon_impulse);
Inc(i);
t:=t+dt;
end;
for i:=1 to Nsim1-1 do
begin
pntsrsSeries1.AddXY(i*dt,s_step[i]);
pntsrsSeries2.AddXY(i*dt,s_impulse[i]);
lst1.Items.Add(FloatToStr(s_step[i]));
lst2.Items.Add(FloatToStr(s_impulse[i]));
end;
end;
procedure TForm1.BacaDataStep;
var
p,i:integer;
filename : textfile;
begin
assignfile(filename,'Step_state.txt');
reset(filename);
p:=1;
readln(filename) ;
procedure TForm1.BacaDataImpulse;
var
p,i:integer;
filename : textfile;
begin
assignfile(filename,'Impulse_state.txt');
reset(filename);
p:=1;
readln(filename) ;
nc := se2.Value;
np := se3.Value;
mmo2.Text:= mmo2.Text+#13#10;
mmo2.Text:= mmo2.Text+#13#10;
mmo2.Text:=mmo2.Text+#13#10;
mmo2.Text:=mmo2.Text+'C:'+#13#10;
end.
2. Answer :
3. Answer :
The time state 𝑥(𝑡)of the Plant is not known in general. The observer inputs are system input
𝑢(𝑡)
In the observer form, the state variable estimate 𝑥̂𝑚 (𝑘 + 1) consists of two terms. The
first term is the original model and the second term is the correction term based on the
error between the measured output
And the predicted output using the estimate 𝑥̂𝑚 (𝑘 + 1). To choose the observer gain 𝐾𝑜𝑏 ,
we examine the closed-loop error equation. By substituting 𝑦(𝑘) = 𝐶𝑚𝑋𝑚 (𝑘) into the
observer equation, with the definition of error state 𝑥̂𝑚 (𝑘) = 𝑥𝑚 (𝑘) − 𝑥̂𝑚 (𝑘), we obtain
that, and we can use initial error 𝑥̂𝑚 (0) we have.
By comparing the observer and open-loop error prediction, 𝐾𝑜𝑏 can be used to
manipulate the convergence rate of the error. A commonly used approach is to place the
closed-loop eigenvalues of the error system matrix 𝐴𝑚 − 𝐾𝑜𝑏 𝐶𝑚 at a desired location of
the complex plane, in case of single output.
Eigen Value (𝐴𝑚 − 𝐾𝑜𝑏 𝐶𝑚 ) should be at pole location of Observer (actual closed-loop
characteristics polynomial).