資源簡介
PID control on the language of the simulation program matlab m

代碼片段和文件信息
%PID?Controller
clear?all;
close?all;
ts=0.001;
sys=tf(5.235e005[187.351.047e0040]);
dsys=c2d(systs‘z‘);
[numden]=tfdata(dsys‘v‘);
u_1=0.0;u_2=0.0;u_3=0.0;
r_1=rand;
y_1=0;y_2=0;y_3=0;
x=[000]‘;
error_1=0;
for?k=1:1:3000
time(k)=k*ts;
kp=1.0;ki=2.0;kd=0.01;
???
S=1;???
if?S==1???%Triangle?Signal
???if?mod(time(k)2)<1?????
???rin(k)=mod(time(k)1);
else
???rin(k)=1-mod(time(k)1);
end
???rin(k)=rin(k)-0.5;
end
if?S==2???%Sawtooth?Signal
???rin(k)=mod(time(k)1.0);
end
if?S==3???%Random?Signal
rin(k)=rand;??
vr(k)=(rin(k)-r_1)/ts;??%Max?speed?is?5.0
while?abs(vr(k))>=5.0
??? rin(k)=rand;??
vr(k)=abs((rin(k)-r_1)/ts);
end
end
u(k)=kp*x(1)+kd*x(2)+ki*x(3);???%PID?Controller
%Restricting?the?output?of?controller
if?u(k)>=10
???u(k)=10;
end
if?u(k)<=-10
???u(k)=-10;
end
%Linear?model
yout(k)=-den(2)*y_1-den(3)*y_2-den(4)*y_3+num(2)*u_1+num(3)*u_2+num(4)*u_3;
error(k)=rin(k)-yout(k);
r_1=rin(k);
u_3=u_2;u_2=u_1;u_1=u(k);
y_3=y_2;y_2=y_1;y_1=yout(k);
???
x(1)=error(k);????????????????%Calculating?P
x(2)=(error(k)-error_1)/ts;???%Calculating?D
x(3)=x(3)+error(k)*ts;????????%Calculating?I
xi(k)=x(3);
error_1=error(k);
D=0;
if?D==1??%Dynamic?Simulation?Display
plot(timerin‘b‘timeyout‘r‘);
pause(0.00000000000000000);
end
end
plot(timerin‘r‘timeyout‘b‘);
xlabel(‘time(s)‘);ylabel(‘rinyout‘);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄??????????0??2007-05-18?21:41??PID程序
?????目錄??????????0??2007-06-10?20:47??PID程序\chap1
?????文件??????10020??2004-06-07?07:32??PID程序\chap1\chap1_1.mdl
?????文件???????1418??2004-06-13?12:10??PID程序\chap1\chap1_10.m
?????文件??????16387??2004-06-13?12:17??PID程序\chap1\chap1_11.mdl
?????文件????????897??2004-06-13?12:19??PID程序\chap1\chap1_12.m
?????文件???????1242??2004-06-13?12:20??PID程序\chap1\chap1_13.m
?????文件??????11066??2004-06-13?12:21??PID程序\chap1\chap1_14.mdl
?????文件????????155??2004-06-13?12:21??PID程序\chap1\chap1_14f.m
?????文件???????1441??2004-06-13?12:22??PID程序\chap1\chap1_15.m
?????文件???????1192??2004-06-13?12:22??PID程序\chap1\chap1_16.m
?????文件????????623??2004-06-13?12:24??PID程序\chap1\chap1_17.m
?????文件???????1684??2004-06-13?12:25??PID程序\chap1\chap1_18.m
?????文件??????14775??2004-06-13?12:26??PID程序\chap1\chap1_19.mdl
?????文件????????248??2004-06-13?12:26??PID程序\chap1\chap1_19f.m
?????文件???????9520??2004-06-07?07:37??PID程序\chap1\chap1_2.mdl
?????文件???????1311??2004-06-13?12:27??PID程序\chap1\chap1_20.m
?????文件???????1188??2004-06-13?12:27??PID程序\chap1\chap1_21.m
?????文件???????1499??2004-06-13?12:28??PID程序\chap1\chap1_22.m
?????文件???????1058??2004-06-13?12:29??PID程序\chap1\chap1_23.m
?????文件???????1332??2004-06-13?12:29??PID程序\chap1\chap1_24.m
?????文件????????924??2004-06-13?11:35??PID程序\chap1\chap1_25.m
?????文件????????691??2004-06-13?12:31??PID程序\chap1\chap1_26.m
?????文件???????1706??2004-06-13?12:31??PID程序\chap1\chap1_27.m
?????文件?????????79??2007-06-06?21:54??PID程序\chap1\chap1_2plot.asv
?????文件?????????79??2007-06-06?21:55??PID程序\chap1\chap1_2plot.m
?????文件???????9896??2004-06-02?09:26??PID程序\chap1\chap1_3.mdl
?????文件????????908??2004-06-02?09:29??PID程序\chap1\chap1_3plant.m
?????文件????????807??2004-06-02?09:29??PID程序\chap1\chap1_3s.m
?????文件??????13183??2004-06-13?11:59??PID程序\chap1\chap1_4.mdl
............此處省略162個文件信息
- 上一篇:SPWM交流調速的MATLAB仿真
- 下一篇:指紋識別算法MATLAB版本
評論
共有 條評論