Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- close all
- T1 = 3;
- T2 = 0.5;
- T3=2;
- k = 3;
- kr=4.86; %4.86 crit, 2.43 for P controller
- kcrit=4.86;
- kP=0.5*kr;
- kPI=0.45*kr;
- kPID=0.6*kr;
- Tosc=34.18;
- TiPI=0.85*Tosc;
- TiPID=0.5*Tosc;
- Td=0.125*Tosc;
- Ti = [0.85*Tosc 0.5*Tosc];
- Td = 0.125*Tosc;
- kc = [0.5*kcrit 0.45*kcrit 0.6*kcrit];
- s=tf('s');
- K=(kr*k)/((1+3*s)*(1+0.5*s)*(1+2*s)); %plant
- Kcl=K/(1+K); %cls plant
- Kunc=(k)/((1+3*s)*(1+0.5*s)*(1+2*s)); %uncompensated system
- Kucl=Kunc/(1+Kunc); %cls uncomp
- KuAT=1/(1+Kunc);
- Kr= [kc(1) kc(2)*(1 + 1/(s*Ti(1))) kc(3)*(1 + Td*s + 1/(s*Ti(2)) )];
- Kcont = k*Kr/((1+s*T1)*(1+s*T2)*(1+s*T3));
- for i = 1:3
- Kcontcl(i) = Kcont(i)/(1 + Kcont(i));
- KcontAT(i)=1/(1 + Kcont(i));
- end
- P = bodeoptions('cstprefs');
- P.FreqScale = 'linear';
- P.MagUnits = 'abs';
- P.MagScale = 'linear';
- N = nyquistoptions('cstprefs');
- N.ShowFullContour = 'off';
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %%%%%%%%%%%%%%% PART A %%%%%%%%%%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %TASK 2
- figure(1)
- nyquist(Kcont(1),N);
- title('Nyquist diagram for system with P controller')
- %TASK 3
- [Gm1,Pm1,Wgm1,Wpm1] = margin(Kcontcl(1))
- %TASK 4
- figure(2)
- bodemag(KcontAT(1),P)
- hold on
- bodemag(Kucl,P)
- axis([0 6 0 3.5])
- title('attenuation index for system with P controller')
- legend('with P controller','without controller','Location','northeast');
- %TASK 5
- figure(3)
- bodemag(Kcontcl(1),P)
- hold on
- bodemag(KuAT,P)
- axis([0 6 0 3])
- title('tracking index for system with P controller')
- legend('with P controller','without controller','Location','northeast');
- %TASK 6
- figure(4)
- step(Kcontcl(1))
- hold on
- step(Kucl)
- title('step responses of system with and without P controller')
- legend('with P controller','without controller','Location','northeast');
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %%%%%%%%%%%%%%% PART B %%%%%%%%%%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %TASK 2
- figure(5)
- nyquist(Kcont(2),N);
- title('Nyquist diagram for system with PI controller')
- %TASK 3
- [Gm2,Pm2,Wgm2,Wpm2] = margin(Kcontcl(1))
- %TASK 4
- figure(6)
- bodemag(KcontAT(2),P)
- hold on
- bodemag(Kucl,P)
- axis([0 6 0 3.5])
- title('attenuation index for system with PI controller')
- legend('with PI controller','without controller','Location','northeast');
- %TASK 5
- figure(7)
- bodemag(Kcontcl(2),P)
- hold on
- bodemag(KuAT,P)
- axis([0 6 0 3])
- title('tracking index for system with PI controller')
- legend('with PI controller','without controller','Location','northeast');
- %TASK 6
- figure(8)
- step(Kcontcl(2))
- hold on
- step(Kucl)
- axis([0 60 0 1.45])
- title('step responses of system with and without PI controller')
- legend('with PI controller','without controller','Location','northeast');
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %%%%%%%%%%%%%%% PART C %%%%%%%%%%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %TASK 2
- figure(9)
- nyquist(Kcont(3),N);
- title('Nyquist diagram for system with PID controller')
- %TASK 3
- [Gm3,Pm3,Wgm3,Wpm3] = margin(Kcontcl(3))
- %TASK 4
- figure(10)
- bodemag(KcontAT(3),P)
- hold on
- bodemag(Kucl,P)
- axis([0 20 0 2])
- title('attenuation index for system with PID controller')
- legend('with PID controller','without controller','Location','northeast');
- %TASK 5
- figure(11)
- bodemag(Kcontcl(3),P)
- hold on
- bodemag(KuAT,P)
- axis([0 20 0 2])
- title('tracking index for system with PID controller')
- legend('with PID controller','without controller','Location','northeast');
- %TASK 6
- figure(12)
- step(Kcontcl(3))
- hold on
- step(Kucl)
- axis([0 30 0 1.2])
- title('step responses of system with and without PID controller')
- legend('with PID controller','without controller','Location','northeast');
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %%%%%%%%%%%%%%% PART D %%%%%%%%%%%%%%%%%%%%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- figure(13)
- nyquist(Kcont(1),N);
- hold on
- nyquist(Kcont(2),N);
- nyquist(Kcont(3),N);
- nyquist(Kunc,N);
- axis([-1.63 7.44 -13.4 10])
- title('Nyquist diagrams')
- legend('with P controller','with PI controller','with PID controller','without controller','Location','northeast');
- figure(14)
- bodemag(KcontAT(1),P)
- hold on
- bodemag(KcontAT(2),P)
- bodemag(KcontAT(3),P)
- bodemag(KuAT,P)
- axis([0 20 0 3.5])
- title('Attenuation indices')
- legend('with P controller','with PI controller','with PID controller','without controller','Location','northeast');
- figure(15)
- bodemag(Kcontcl(1),P)
- hold on
- bodemag(Kcontcl(2),P)
- bodemag(Kcontcl(3),P)
- bodemag(Kucl,P)
- axis([0 10 0 3])
- title('Tracking indices')
- legend('with P controller','with PI controller','with PID controller','without controller','Location','northeast');
- figure(16)
- step(Kcontcl(1))
- hold on
- step(Kcontcl(2))
- step(Kcontcl(3))
- step(Kucl)
- axis([0 30 0 1.45])
- title('Step responses')
- legend('with P controller','with PI controller','with PID controller','without controller','Location','northeast');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement