Advertisement
Tamjow

cflab6

Apr 12th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 4.80 KB | None | 0 0
  1. close all
  2. T1 = 3;
  3. T2 = 0.5;
  4. T3=2;
  5. k = 3;
  6. kr=4.86; %4.86 crit, 2.43 for P controller
  7. kcrit=4.86;
  8. kP=0.5*kr;
  9. kPI=0.45*kr;
  10. kPID=0.6*kr;
  11. Tosc=34.18;
  12. TiPI=0.85*Tosc;
  13. TiPID=0.5*Tosc;
  14. Td=0.125*Tosc;
  15.  
  16. Ti = [0.85*Tosc 0.5*Tosc];
  17. Td = 0.125*Tosc;
  18. kc = [0.5*kcrit 0.45*kcrit 0.6*kcrit];
  19.  
  20. s=tf('s');
  21. K=(kr*k)/((1+3*s)*(1+0.5*s)*(1+2*s)); %plant
  22. Kcl=K/(1+K); %cls plant
  23. Kunc=(k)/((1+3*s)*(1+0.5*s)*(1+2*s)); %uncompensated system
  24. Kucl=Kunc/(1+Kunc); %cls uncomp
  25. KuAT=1/(1+Kunc);
  26. Kr= [kc(1) kc(2)*(1 + 1/(s*Ti(1))) kc(3)*(1 + Td*s + 1/(s*Ti(2)) )];
  27. Kcont = k*Kr/((1+s*T1)*(1+s*T2)*(1+s*T3));
  28. for i = 1:3
  29.     Kcontcl(i) = Kcont(i)/(1 + Kcont(i));
  30.     KcontAT(i)=1/(1 + Kcont(i));
  31. end
  32.  
  33. P = bodeoptions('cstprefs');
  34. P.FreqScale = 'linear';
  35. P.MagUnits = 'abs';
  36. P.MagScale = 'linear';
  37.  
  38. N = nyquistoptions('cstprefs');
  39. N.ShowFullContour = 'off';
  40. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  41. %%%%%%%%%%%%%%% PART A %%%%%%%%%%%%%%%%%%%%
  42. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  43.  
  44. %TASK 2
  45. figure(1)
  46. nyquist(Kcont(1),N);
  47. title('Nyquist diagram for system with P controller')
  48. %TASK 3
  49. [Gm1,Pm1,Wgm1,Wpm1] = margin(Kcontcl(1))
  50. %TASK 4
  51. figure(2)
  52. bodemag(KcontAT(1),P)
  53. hold on
  54. bodemag(Kucl,P)
  55. axis([0 6 0 3.5])
  56. title('attenuation index for system with P controller')
  57. legend('with P controller','without controller','Location','northeast');
  58. %TASK 5
  59. figure(3)
  60. bodemag(Kcontcl(1),P)
  61. hold on
  62. bodemag(KuAT,P)
  63. axis([0 6 0 3])
  64. title('tracking index for system with P controller')
  65. legend('with P controller','without controller','Location','northeast');
  66. %TASK 6
  67. figure(4)
  68. step(Kcontcl(1))  
  69. hold on
  70. step(Kucl)
  71. title('step responses of system with and without P controller')
  72. legend('with P controller','without controller','Location','northeast');
  73.  
  74. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  75. %%%%%%%%%%%%%%% PART B %%%%%%%%%%%%%%%%%%%%
  76. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  77.  
  78. %TASK 2
  79. figure(5)
  80. nyquist(Kcont(2),N);
  81. title('Nyquist diagram for system with PI controller')
  82. %TASK 3
  83. [Gm2,Pm2,Wgm2,Wpm2] = margin(Kcontcl(1))
  84. %TASK 4
  85. figure(6)
  86. bodemag(KcontAT(2),P)
  87. hold on
  88. bodemag(Kucl,P)
  89. axis([0 6 0 3.5])
  90. title('attenuation index for system with PI controller')
  91. legend('with PI controller','without controller','Location','northeast');
  92. %TASK 5
  93. figure(7)
  94. bodemag(Kcontcl(2),P)
  95. hold on
  96. bodemag(KuAT,P)
  97. axis([0 6 0 3])
  98. title('tracking index for system with PI controller')
  99. legend('with PI controller','without controller','Location','northeast');
  100. %TASK 6
  101. figure(8)
  102. step(Kcontcl(2))  
  103. hold on
  104. step(Kucl)
  105. axis([0 60 0 1.45])
  106. title('step responses of system with and without PI controller')
  107. legend('with PI controller','without controller','Location','northeast');
  108.  
  109. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  110. %%%%%%%%%%%%%%% PART C %%%%%%%%%%%%%%%%%%%%
  111. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  112.  
  113. %TASK 2
  114. figure(9)
  115. nyquist(Kcont(3),N);
  116. title('Nyquist diagram for system with PID controller')
  117. %TASK 3
  118. [Gm3,Pm3,Wgm3,Wpm3] = margin(Kcontcl(3))
  119. %TASK 4
  120. figure(10)
  121. bodemag(KcontAT(3),P)
  122. hold on
  123. bodemag(Kucl,P)
  124. axis([0 20 0 2])
  125. title('attenuation index for system with PID controller')
  126. legend('with PID controller','without controller','Location','northeast');
  127. %TASK 5
  128. figure(11)
  129. bodemag(Kcontcl(3),P)
  130. hold on
  131. bodemag(KuAT,P)
  132. axis([0 20 0 2])
  133. title('tracking index for system with PID controller')
  134. legend('with PID controller','without controller','Location','northeast');
  135. %TASK 6
  136. figure(12)
  137. step(Kcontcl(3))  
  138. hold on
  139. step(Kucl)
  140. axis([0 30 0 1.2])
  141. title('step responses of system with and without PID controller')
  142. legend('with PID controller','without controller','Location','northeast');
  143.  
  144. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  145. %%%%%%%%%%%%%%% PART D %%%%%%%%%%%%%%%%%%%%
  146. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  147.  
  148. figure(13)
  149. nyquist(Kcont(1),N);
  150. hold on
  151. nyquist(Kcont(2),N);
  152. nyquist(Kcont(3),N);
  153. nyquist(Kunc,N);
  154. axis([-1.63 7.44 -13.4 10])
  155. title('Nyquist diagrams')
  156. legend('with P controller','with PI controller','with PID controller','without controller','Location','northeast');
  157.  
  158. figure(14)
  159. bodemag(KcontAT(1),P)
  160. hold on
  161. bodemag(KcontAT(2),P)
  162. bodemag(KcontAT(3),P)
  163. bodemag(KuAT,P)
  164. axis([0 20 0 3.5])
  165. title('Attenuation indices')
  166. legend('with P controller','with PI controller','with PID controller','without controller','Location','northeast');
  167.  
  168.  
  169. figure(15)
  170. bodemag(Kcontcl(1),P)
  171. hold on
  172. bodemag(Kcontcl(2),P)
  173. bodemag(Kcontcl(3),P)
  174. bodemag(Kucl,P)
  175. axis([0 10 0 3])
  176. title('Tracking indices')
  177. legend('with P controller','with PI controller','with PID controller','without controller','Location','northeast');
  178.  
  179. figure(16)
  180. step(Kcontcl(1))
  181. hold on
  182. step(Kcontcl(2))
  183. step(Kcontcl(3))  
  184. step(Kucl)
  185. axis([0 30 0 1.45])
  186. title('Step responses')
  187. legend('with P controller','with PI controller','with PID controller','without controller','Location','northeast');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement