Advertisement
Guest User

Kalman vs pole plac

a guest
Feb 28th, 2024
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1.  
  2. clc
  3. clear all
  4.  
  5. format long
  6. w=0.00007291;
  7. r=422000;
  8.  
  9.  
  10.  
  11.  
  12.  
  13. As=[0 1 0 0;3*w*w 0 0 2*r*w;0 0 0 1;0 -(2*w)/r 0 0]
  14. Bs=[0 0 ;1 0; 0 0 ; 0 1/r]
  15. Cs=[1/r 0 0 0; 0 0 1 0]
  16. %Cs=eye(4)
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. [p, n]=size(Cs);
  26. Ag=[As zeros(n,p); -Cs zeros(p,p)]
  27. Bg=[Bs; zeros(p,p)]
  28. Cg=[Cs zeros(p,p)]
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. p1=-0.236619558550974
  36. p2= -0.236619558550973
  37. p3= -0.010598006934913;
  38. p4= -0.069459950787419
  39. p5= -0.034729982561367
  40. p6= -0.034729982561367
  41.  
  42.  
  43.  
  44. K=place(Ag,Bg,[p1 p2 p3 p4 p5 p6]);
  45.  
  46.  
  47.  
  48.  
  49.  
  50. Kf=K(:,1:4)
  51. Ki=K(:,5:end) %% simple feedback control with integrator
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. %%Kalman
  59.  
  60.  
  61. Qk=diag([1 1 10 10 2000000000 900000000]);
  62. Rk=diag([16000000 1800000000000000]);
  63. KKottimo=lqr(Ag,Bg,Qk,Rk)
  64.  
  65. Kkfottimo=KKottimo(:,1:4); // matrix for the lqg control
  66. Kkiottimo=KKottimo(:,5:end);
  67.  
  68.  
  69. Q=0.05
  70. v_y=0.00000000003;
  71.  
  72. Qtilde=Q*diag([1 1 1 1]);
  73. Rtilde=v_y*diag([1 1]);
  74. Lk=lqr(As',Cs',Qtilde,Rtilde)';
  75. Afk=As-Lk*Cs; %%matrix of the kalman filter
  76. Bfk=[Bs-Lk*D Lk];
  77. Cfk=eye(4);
  78. Dfk=zeros(4,4);
  79.  
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement