Advertisement
aprsc7

Tutorial Design via State Space

Dec 18th, 2020 (edited)
1,491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.63 KB | None | 0 0
  1. clear
  2. clc
  3. sympref('FloatingPointOutput',true)
  4. syms s k1 k2 k3 k4 ke zeros;
  5.  
  6. %% Input:
  7.  
  8. % Problem 3
  9. numg = [20]; % Define numerator of G(s)
  10. deng = poly([2 4 8]); % Define denominator of G(s)
  11. Os = 15; % Overshoot (%)
  12. Ts = 0.75;  % Time settling
  13.  
  14. % Problem 4
  15. %numg = [20 40]; % Define numerator of G(s)
  16. %deng = poly([0 5 7]); % Define denominator of G(s)
  17. %Os = 10; % Overshoot (%)
  18. %Ts = 2;  % Time settling
  19.  
  20. % Problem 5
  21. %numg = [1 6]; % Define numerator of G(s)
  22. %deng = poly([3 8 10]); % Define denominator of G(s)
  23. %Os = 10; % Overshoot (%)
  24. %Ts = 1;  % Time settling
  25. %zeros = -6
  26.  
  27. zeta = (-log(Os/100))/(sqrt(pi^2+log(Os/100)^2));
  28. Wn = 4/(zeta*Ts);
  29.  
  30. zeros =  real(solve(s^2 + 2*zeta*Wn*s + Wn^2))*10;  % Third pole / Open loop zero
  31. %speed = 10 % observer speed
  32.  
  33. %% Process
  34.  
  35. G = tf(numg,deng)   % Generate transfer function G(s)
  36. [Ac Bc Cc Dc] = tf2ss(numg,deng);
  37. P = [0 0 1; 0 1 0; 1 0 0];
  38. A = inv(P)*Ac*P
  39. B = inv(P)*Bc
  40. C = Cc*P
  41. D = Dc
  42.  
  43. Cm = det(ctrb(A,B))      % Controlbility
  44. Om = det(obsv(A,C))      % Observability
  45.  
  46. %% controller
  47.  
  48. %state-feedback control
  49. pole1 = s^2 + 2*zeta*Wn*s + Wn^2
  50. pole2 = s-zeros(1)
  51. Anew = A-(B*[k1 k2 k3])
  52.  
  53. %Integral control
  54. %pole1 = s^2 + 2*zeta*Wn*s + Wn^2
  55. %pole2 = s-zeros(1)
  56. %a11 = A-(B*[k1 k2 k3]);
  57. %a12 = B*ke;
  58. %a21 = -C;
  59. %Anew = [a11 a12; a21 0];
  60.  
  61. % Observer
  62. %pole1 = s+zeta*Wn*speed + (Wn*sqrt(1-zeta^2))*speed*1i;
  63. %pole2 = s+zeta*Wn*speed - (Wn*sqrt(1-zeta^2))*speed*1i;
  64. %pole3 = s+zeta*Wn*speed*10;
  65. %Anew = A-[L1; L2; L3]*C;
  66.  
  67. Ds = expand(pole1*pole2)
  68. Ts = det(s*eye(3)-Anew)
  69.  
  70. % Solve
  71. Dsm = coeffs(Ds,s);
  72. Tsm = coeffs(Ts,s);
  73. k = vpa(struct2cell((solve(Dsm==Tsm))))
  74.  
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement