0001 function stepPIDcompare(num,den,tau)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 global PIDPARAMETERS
0026
0027
0028 P = tf(num,den,'IODelay',tau);
0029 [y,t] = step(P);
0030 Ts = min(real(abs(pole(P))))/50;
0031 [y,t] = step(P,0:Ts:t(end));
0032 Tf = t(end);
0033
0034
0035 modelFOPDT = idareas(y,1,Ts);
0036
0037
0038 [Gm,Pm,Wcg,Wcp] = margin(P);
0039 modelPI.A = 2/Gm;
0040 modelPI.T = 2*pi/Wcg;
0041
0042
0043 load_system('steppidsupport')
0044 simhandle = 'steppidsupport';
0045 set_param([simhandle '/Plant'],'Numerator',['[' num2str(num) ']']);
0046 set_param([simhandle '/Plant'],'Denominator',['[' num2str(den) ']']);
0047 set_param([simhandle '/PlantDelay'],'DelayTime',num2str(tau));
0048 set_param([simhandle '/spWorkspace'],'SampleTime',num2str(Ts));
0049 set_param([simhandle '/cvWorkspace'],'SampleTime',num2str(Ts));
0050 set_param([simhandle '/pvWorkspace'],'SampleTime',num2str(Ts));
0051 set_param([simhandle '/toutWorkspace'],'SampleTime',num2str(Ts));
0052 set_param([simhandle '/ISA PID'],'Ts',num2str(Ts));
0053 set_param(simhandle,'StopTime',num2str(2*Tf));
0054
0055 set_param([simhandle '/SetPoint'],'Time',num2str(0));
0056 set_param([simhandle '/SetPoint'],'After',num2str(1));
0057 set_param([simhandle '/Disturbance'],'Time',num2str(4/3*Tf));
0058 set_param([simhandle '/Disturbance'],'After',num2str(0.1));
0059
0060 figure(...
0061 'Name', 'Step response',...
0062 'NumberTitle', 'off');
0063
0064
0065
0066 [K,Ti,Td,N,b] = pid_tuning(modelFOPDT,'ZN (OL)',[],'PID');
0067 PIDPARAMETERS = [K,Ti,Td,N,b];
0068 sim('steppidsupport');
0069 subplot(211)
0070 plot(tout,pvVec,'b')
0071 set(gca,'XColor',[0.4 0.4 0.4],'YColor',[0.4 0.4 0.4],...
0072 'FontSize',8)
0073 hold on
0074 subplot(212)
0075 plot(tout,cvVec,'b')
0076 set(gca,'XColor',[0.4 0.4 0.4],'YColor',[0.4 0.4 0.4],...
0077 'FontSize',8)
0078 hold on
0079
0080
0081
0082 [K,Ti,Td,N,b] = pid_tuning(modelFOPDT,'KT',2,'PID');
0083 PIDPARAMETERS = [K,Ti,Td,N,b];
0084 sim('steppidsupport');
0085 subplot(211)
0086 plot(tout,pvVec,'r')
0087 subplot(212)
0088 plot(tout,cvVec,'r')
0089
0090
0091
0092
0093 [K,Ti,Td,N,b] = pid_tuning(modelFOPDT,'IMC',Tf/10,'PID');
0094 PIDPARAMETERS = [K,Ti,Td,N,b];
0095 sim('steppidsupport');
0096 subplot(211)
0097 plot(tout,pvVec,'g')
0098 subplot(212)
0099 plot(tout,cvVec,'g')
0100
0101
0102 [K,Ti,Td,N,b] = pid_tuning(modelPI,'ZN (CL)',[],'PID');
0103 PIDPARAMETERS = [K,Ti,Td,N,b];
0104 sim('steppidsupport');
0105 subplot(211)
0106 plot(tout,pvVec,'m',tout,spVec,'k:')
0107 title('Step and Load Disturbance Response',...
0108 'Color',[0 0 0],'FontSize',8)
0109 ylabel('Process Value',...
0110 'Color',[0 0 0],'FontSize',8)
0111 legend('STEP + ZN(OL)','STEP + KT','STEP + IMC','RELAY + ZN(CL)',4)
0112 subplot(212)
0113 plot(tout,cvVec,'m')
0114 xlabel('Time [sec]',...
0115 'Color',[0 0 0],'FontSize',8)
0116 ylabel('Control Variable',...
0117 'Color',[0 0 0],'FontSize',8)