Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
лабораторная работа / nastroyka_pid_regulyatora.doc
Скачиваний:
37
Добавлен:
22.02.2014
Размер:
302.59 Кб
Скачать
  1. Картины сходимости настраиваемых параметров.

Параметр q1 (начальные значения –q11=2,q12=10,q13=14).

Параметр q2 (начальные значения –q21=1,q22=5,q23=6).

Параметр q3 (начальные значения –q31=0,q32=0,5,q33=0,7).

  1. Листинг фрагмента программы, относящегося к моделированию заданной автоматической системы.

const

dt=0.002;

L=5;

t=1;

var

Form1: TForm1;

kk:tk;

integ:real;

counter: word;

function f0(y:real; T:real; v: real):real;

begin

result:=(v-y)/T;

end;

procedure pid(g:real; Series:TLineseries );

const

tau=0.1;

var

n,j,i,count: integer;

mas, mas_p: array[0..10000] of extended;

mas1, mas1_p: array[0..2,0..10000] of extended;

SummDt,summ,y_p,y1,dy,y_os,k1,ns,y, x, x_last,y1_p, q1, q1_last,q2_last,q3_last,q2, q3, u, u1, u2, u3,u33, ksi_x, shag_q,shag_q3,integ_last:extended;

dudq,ksi,u22,yy,ksi_last,yy1,yy_p, yy1_p, dIdq, dIdq_last : array of extended;

err, opt, first: boolean;

begin

Form1.Series1.Clear;

Form1.Series2.Clear;

Form1.Series3.Clear;

Form1.Series14.Clear;

Form1.Series15.Clear;

Form1.Series16.Clear;

Form1.Series17.Clear;

first:=true;

ns:=tau/dt;

SetLength(dudq,3);

SetLength(ksi,3);

SetLength(u22,3);

SetLength(yy,3);

SetLength(yy1,3);

SetLength(yy_p,3);

SetLength(yy1_p,3);

SetLength(ksi_last,3);

SetLength(dIdq_last,3);

SetLength(dIdq,3);

shag_q:=0.03;

q1:=StrToFloat(Form1.Edit2.Text);

q2:=StrToFloat(Form1.Edit3.Text);

q3:=StrToFloat(Form1.Edit4.Text);

q1_last:=q1;

q2_last:=q2;

q3_last:=q3;

count:=0;

if Form1.RadioButton2.Checked then

opt:=false;

integ:=0;

repeat

if Form1.RadioButton1.Checked then

opt:=true;

if (first) and (Form1.RadioButton2.Checked) then

integ_last:=1000

else

integ_last:=integ;

integ:=0;

SummDt:=0;

y1:=0;

y_os:=0;

k1:=1;

err :=true;

u1:=0;

u2:=0;

u3:=0;

u:=0;

j:=0;

n:=0;

y_p:=0;

ksi_x:=0;

for i:=0 to 2 do

begin

dudq[i]:=0;

ksi[i]:=0;

u22[i]:=0;

yy[i]:=0;

ksi_last[i]:=0;

yy1[i]:=0;

if (opt) or (first) then

dIdq[i]:=0;

yy_p[i]:=0;

yy1_p[i]:=0;

dIdq_last[i]:=0;

end;

x:=1;

Form1.Series4.Clear;

Form1.Series11.Clear;

Form1.Series12.Clear;

Form1.Series13.Clear;

repeat

x_last:=x;

x:=g - y_os;

u1:= q1 * x;

u2:= u2+ x * dt;

u3:= -y_p;

u:= u1+ q2 *u2+ q3 * u3;

kk[1]:=dt*f0(y1, 1, u);

kk[2]:=dt*f0(y1+kk[1]/2, 1, u);

kk[3]:=dt*f0(y1+kk[2]/2, 1, u);

kk[4]:=dt*f0(y1+kk[3], 1, u);

dy:=(kk[1]+2*(kk[2]+kk[3])+kk[4])/6;

y1:=y1+ dy;

y1_p:=(u-y1)/T;

inc(n);

if (opt) or (first) then

begin

for i:=0 to 2 do

begin

u1:= q1 * ksi[i];

u22[i]:= u22[i]+ ksi[i] * dt;

u33:= yy_p[i];

if i=0 then ksi_x:=x;

if i=1 then ksi_x:=u2;

if i=2 then ksi_x:=u3;

dudq[i] := ksi_x - u1- q2 *u22[i]- q3 * u33;

kk[1]:=dt*f0(yy1[i], 1, dudq[i]);

kk[2]:=dt*f0(yy1[i] + kk[1]/2, 1, dudq[i]);

kk[3]:=dt*f0(yy1[i] + kk[2]/2, 1, dudq[i]);

kk[4]:=dt*f0(yy1[i] + kk[3], 1, dudq[i]);

dy:=(kk[1]+2*(kk[2]+kk[3])+kk[4])/6;

yy1[i]:=yy1[i]+dy;

yy1_p[i]:=(dudq[i]-yy1[i])/T;

end;

end;

if (n>ns) then

begin

if (j>=ns) then

j:=0;

inc(j);

y:=mas[j];

mas[j]:=y1;

y_p:=mas_p[j];

mas_p[j]:=y1_p;

if (opt) or (first) then

begin

for i:=0 to 2 do

begin

yy[i]:=mas1[i][j];

mas1[i][j]:=yy1[i];

yy_p[i]:=mas1_p[i][j];

mas1_p[i][j]:=yy1_p[i];

end;

end;

end

else

begin

y:=0;

mas[n]:=y1;

mas_p[n]:=y1_p;

y_p:=0;

if (opt) or (first) then

begin

for i:=0 to 2 do

begin

mas1[i][n]:=yy1[i];

mas1_p[i][n]:=yy1_p[i];

end;

for i:=0 to 2 do

begin

yy[i]:=0;

yy_p[i]:=0;

end;

end;

end;

y_os:=y;

if (opt) or (first) then

begin

for i:=0 to 2 do

begin

ksi_last[i]:=ksi[i];

ksi[i]:=yy[i];

end;

end;

Form1.Series4.AddXY(SummDt,y);

if (opt) or (first) then

begin

Form1.Series11.AddXY(SummDt,yy[0]);

Form1.Series12.AddXY(SummDt,yy[1]);

Form1.Series13.AddXY(SummDt,yy[2]);

end;

if first then

Form1.Series2.AddXY(SummDt,y);

integ:=integ+(sqr(x))*dt;//

if (opt) or (first) then

begin

for i:=0 to 2 do

dIdq[i]:=dIdq[i]-2*x*ksi[i]*dt; //

end;

SummDt:=SummDt+dt;

until SummDt>L;

first:=false;

opt:=false;

form1.Series14.AddXY(count,integ);

if integ_last<integ then

begin

shag_q:=shag_q/2;

if Form1.RadioButton2.Checked then

begin

opt:=true;

q1:=q1_last;

q2:=q2_last;

q3:=q3_last;

end;

end

else

shag_q:=shag_q*1.2;

summ:=0;

for i:=0 to 2 do

summ:=summ+sqr(dIdq[i]);

q1_last:=q1;

q2_last:=q2;

q3_last:=q3;

q1:=q1-shag_q*dIdq[0]/sqrt(summ);

q2:=q2-shag_q*dIdq[1]/sqrt(summ);

q3:=q3-shag_q*dIdq[2]/sqrt(summ);

form1.Series15.AddXY(count,dIdq[0]);

form1.Series16.AddXY(count,dIdq[1]);

form1.Series17.AddXY(count,dIdq[2]);

inc(count);

form1.ProgressBar1.Position:=count;

until count=form1.ProgressBar1.Max;

form1.Edit1.Text:=Floattostr(integ);

Form1.Label6.Caption:=FloatToStr(shag_q);

form1.Edit2.Text:=Floattostr(q1);

form1.Edit3.Text:=Floattostr(q2);

form1.Edit4.Text:=Floattostr(q3);

end;

Соседние файлы в папке лабораторная работа