%Delay Control with Dalin Algorithm clear all; close all; ts=0.5; %Plant sys1=tf([1],[0.4,1],'inputdelay',0.76); dsys1=c2d(sys1,ts,'zoh'); [num1,den1]=tfdata(dsys1,'v'); %Ideal closed loop sys2=tf([1],[0.15,1],'inputdelay',0.76); dsys2=c2d(sys2,ts,'zoh'); %Design Dalin controller dsys=1/dsys1*dsys2/(1-dsys2); [num,den]=tfdata(dsys,'v'); u_1=0.0;u_2=0.0;u_3=0.0;u_4=0.0;u_5=0.0; y_1=0.0; error_1=0.0;error_2=0.0;error_3=0.0; ei=0; for k=1:1:50 time(k)=k*ts; rin(k)=1.0; %Tracing Step Signal yout(k)=-den1(2)*y_1+num1(2)*u_2+num1(3)*u_3; error(k)=rin(k)-yout(k); M=1; if M==1 %Using Dalin Method u(k)=(num(1)*error(k)+num(2)*error_1+num(3)*error_2+num(4)*error_3... -den(3)*u_1-den(4)*u_2-den(5)*u_3-den(6)*u_4-den(7)*u_5)/den(2); elseif M==2 %Using PID Method ei=ei+error(k)*ts; u(k)=1.0*error(k)+0.10*(error(k)-error_1)/ts+0.50*ei; end %----------Return of dalin parameters------------ u_5=u_4;u_4=u_3;u_3=u_2;u_2=u_1;u_1=u(k); y_1=yout(k); error_3=error_2;error_2=error_1;error_1=error(k); end plot(time,rin,'b',time,yout,'r'); xlabel('time(s)');ylabel('rin,yout');
解读函数:
sys1=tf([1],[0.4,1],'inputdelay',0.76); dsys1=c2d(sys1,ts,'zoh'); [num1,den1]=tfdata(dsys1,'v'); sys1=tf([1],[0.4,1],'inputdelay',0.76); %系统传递函数 dsys1=c2d(sys1,ts,'zoh'); 转化成dz函数 [num1,den1]=tfdata(dsys1,'v'); 获得z传函的分子和分母 %Ideal closed loop 期望鼻环传递函数 sys2=tf([1],[0.15,1],'inputdelay',0.76); 系统传递函数 dsys2=c2d(sys2,ts,'zoh'); 转化成d(z)函数 %Design Dalin controller 设计大林控制器 dsys=1/dsys1*dsys2/(1-dsys2); dz=就是d(z)的公式 [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; y_1=0.0; error_1=0.0;error_2=0.0;error_3=0.0; ei=0; 应该是清零 for k=1:1:50 采样的比 time(k)=k*ts; 定义time k rin(k)=1.0; %Tracing Step Signal 跟踪阶跃信号 yout(k)=-den1(2)*y_1+num1(2)*u_2+num1(3)*u_3; error(k)=rin(k)-yout(k); 差分方程 M=1 大林算法 M=2 pid算法 结束 绘图