分布式实验设计指导书(6)
发布时间:2021-06-07
发布时间:2021-06-07
零阶保持器处理方法:
四、实验参考程序
clear all; %Çå³ýµôËùÓÐÎļþ
close all; %¹Ø±ÕËùÓÐÎļþ
Ts=20; %¶¨Òåʱ¼ä
%Delay plant ¶¨ÒåÑÓ³Ùº¯Êý
K=1;
Tp=60;
tol=80; %¸³Öµ
sys=tf((K),[Tp,1],'inputdelay',tol); %¶¨Òåϵͳ´«µÝº¯Êý
dsys=c2d(sys,Ts,'zoh'); %ת»¯³Édzº¯Êý
[num,den]=tfdata(dsys,'v'); %»ñµÃZ´«µÝº¯ÊýµÄ·Ö×Ó·Öĸ
u_1=0.0;u_2=0.0;u_3=0.0;u_4=0.0;u_5=0.0; %Çå0£¬Ê¹ÏµÍ³³õʼ»¯
e_1=0;
ei=0;
y_1=0.0;
for k=1:1:300 %²ÉÑù±È£¬ÔÚ1¡ª300£¬ÇÒ¿ç·ùΪ1Ö®¼ä²ÉÑù
time(k)=k*Ts; %¶¨Òåtime(k)º¯Êý
yd(k)=1.0; %Tracting Step Signal ×·×Ù½×Ô¾ÐźÅ
y(k)=-den(2)*y_1+num(2)*u_5; %Êä³öº¯Êý
e(k)=yd(k)-y(k); %²î·Ö·½³Ì
de(k)=(e(k)-e_1)/Ts;
ei=ei+Ts*e(k);
delta=0.885; %Æ«²îµþ¼Ó
TI=160;
TD=40; %¸³Öµ
u(k)=delta*(e(K)+1/TI*ei+TD*de(k)); %¶¨ÒåÆ«²îu(k)º¯Êý
e_1=e(k);
u_5=u_4;u_4=u_3;u_3=u_2;u_2=u_1;u_1=u(k); %ÖØж¨ÒåвÎÊý
y_1=y(k);
end
figure(1); %ͼ1
plot(time,yd,'r',time,y,'k:','linewidth',2); %»-ͼ
xlabel('time(s)');ylabel('yd and y'); %xÖá±íʾtime(s)£¬yÖá±íʾyd and y legend('ideal position signal','position
tracking'); %ʵÏß±íʾtime(s)£¬ÐéÏß±íʾyd and y