1 | function [A_k, C_k, pre_k, A_l] = assembDeriv(ksi, iab, ksi0, Q, R, ref_ome, inddq) |
---|
2 | a = 0.9898; |
---|
3 | b = 0.0072; |
---|
4 | c = 0.0361; |
---|
5 | d = 1.0; |
---|
6 | e = 0.0149; |
---|
7 | dt = 0.000125; |
---|
8 | |
---|
9 | Rs = 0.28; |
---|
10 | Ls = 0.003465; |
---|
11 | psi = 0.1989; |
---|
12 | B = 0; |
---|
13 | kp = 1.5; |
---|
14 | pp = 4.0; |
---|
15 | J = 0.04; |
---|
16 | Lq = 1.0*Ls; |
---|
17 | Ld = 0.9*Ls; |
---|
18 | kpp = kp*pp*pp; |
---|
19 | kppj = kpp/J; |
---|
20 | |
---|
21 | ome = ksi(1); |
---|
22 | the = ksi(2); |
---|
23 | P = [ksi(3), ksi(4); ksi(4), ksi(5)]; |
---|
24 | ia = iab(1); |
---|
25 | ib = iab(2); |
---|
26 | A_k = zeros(5); |
---|
27 | A_l = zeros(6); |
---|
28 | |
---|
29 | |
---|
30 | %puvodni matice derivaci |
---|
31 | if(inddq == 0) |
---|
32 | %stejne indukcnosti |
---|
33 | A = [d, -e*(ia*cos(the)+ib*sin(the)); dt, 1.0]; |
---|
34 | else |
---|
35 | %ruzne indukcnosti |
---|
36 | A = [d, -dt*kppj*(psi*(ia*cos(the) + ib*sin(the)) + (Ld - Lq)*(ia*cos(the) + ib*sin(the))^2 - (Ld - Lq)*(ib*cos(the) - ia*sin(the))^2); dt, 1.0]; |
---|
37 | end |
---|
38 | C = [b*sin(the), b*ome*cos(the); -b*cos(the), b*ome*sin(the)]; |
---|
39 | |
---|
40 | %dalsi matice EKF |
---|
41 | Pp = A*P*A' + Q; |
---|
42 | S = C*Pp*C' + R; |
---|
43 | K = Pp*C'/S; |
---|
44 | Pnew = (eye(2) - K*C)*Pp; |
---|
45 | |
---|
46 | %derivace zakladnich matic EKF stavu |
---|
47 | % dAdom = zeros(4); |
---|
48 | dAdth = [0, e*(ia*sin(the)-ib*cos(the)); 0, 0]; |
---|
49 | % dAdP = zeros(4); |
---|
50 | dCdom = [0, b*cos(the); 0, b*sin(the)]; |
---|
51 | dCdth = [b*cos(the), -b*ome*sin(the); b*sin(the), b*ome*cos(the)]; |
---|
52 | % dCdP = zeros(4); |
---|
53 | % dPdomth = zeros(4); |
---|
54 | dPdPo = [1, 0; 0, 0]; |
---|
55 | dPdPot = [0, 1; 1, 0]; |
---|
56 | dPdPt = [0, 0; 0, 1]; |
---|
57 | |
---|
58 | %derivace dalsich matic EKF stavu |
---|
59 | % dPpdom = zeros(4); |
---|
60 | dPpdth = dAdth*P*A' + A*P*dAdth'; |
---|
61 | dPpdPo = A*dPdPo*A'; |
---|
62 | dPpdPot = A*dPdPot*A'; |
---|
63 | dPpdPt = A*dPdPt*A'; |
---|
64 | |
---|
65 | dSdom = dCdom*Pp*C' + C*Pp*dCdom'; |
---|
66 | dSdth = dCdth*Pp*C' + C*dPpdth*C' + C*Pp*dCdth'; |
---|
67 | dSdPo = C*dPpdPo*C'; |
---|
68 | dSdPot = C*dPpdPot*C'; |
---|
69 | dSdPt = C*dPpdPt*C'; |
---|
70 | |
---|
71 | dKdom = Pp*dCdom'/S - Pp*C'/S*dSdom/S; |
---|
72 | dKdth = dPpdth*C'/S + Pp*dCdth'/S - Pp*C'/S*dSdth/S; |
---|
73 | dKdPo = dPpdPo*C'/S - Pp*C'/S*dSdPo/S; |
---|
74 | dKdPot = dPpdPot*C'/S - Pp*C'/S*dSdPot/S; |
---|
75 | dKdPt = dPpdPt*C'/S - Pp*C'/S*dSdPt/S; |
---|
76 | |
---|
77 | dPnewdom = - dKdom*C*Pp - K*dCdom*Pp; |
---|
78 | dPnewdth = dPpdth - dKdth*C*Pp - K*dCdth*Pp - K*C*dPpdth; |
---|
79 | dPnewdPo = dPpdPo - dKdPo*C*Pp - K*C*dPpdPo; |
---|
80 | dPnewdPot = dPpdPot - dKdPot*C*Pp - K*C*dPpdPot; |
---|
81 | dPnewdPt = dPpdPt - dKdPt*C*Pp - K*C*dPpdPt; |
---|
82 | |
---|
83 | A_k(1,1) = d; |
---|
84 | A_k(1,2) = -e*(ia*cos(the)+ib*sin(the)); |
---|
85 | % A_k(1,3) = 0; |
---|
86 | % A_k(1,4) = 0; |
---|
87 | % A_k(1,5) = 0; |
---|
88 | |
---|
89 | A_k(2,1) = dt; |
---|
90 | A_k(2,2) = 1.0; |
---|
91 | % A_k(2,3) = 0; |
---|
92 | % A_k(2,4) = 0; |
---|
93 | % A_k(2,5) = 0; |
---|
94 | |
---|
95 | A_k(3,1) = dPnewdom(1,1); |
---|
96 | A_k(3,2) = dPnewdth(1,1); |
---|
97 | A_k(3,3) = dPnewdPo(1,1); |
---|
98 | A_k(3,4) = dPnewdPot(1,1); |
---|
99 | A_k(3,5) = dPnewdPt(1,1); |
---|
100 | |
---|
101 | A_k(4,1) = dPnewdom(1,2); |
---|
102 | A_k(4,2) = dPnewdth(1,2); |
---|
103 | A_k(4,3) = dPnewdPo(1,2); |
---|
104 | A_k(4,4) = dPnewdPot(1,2); |
---|
105 | A_k(4,5) = dPnewdPt(1,2); |
---|
106 | |
---|
107 | A_k(5,1) = dPnewdom(2,2); |
---|
108 | A_k(5,2) = dPnewdth(2,2); |
---|
109 | A_k(5,3) = dPnewdPo(2,2); |
---|
110 | A_k(5,4) = dPnewdPot(2,2); |
---|
111 | A_k(5,5) = dPnewdPt(2,2); |
---|
112 | |
---|
113 | phi = zeros(5,1); |
---|
114 | phi(1) = d*ksi0(1) + e*(ib*cos(ksi0(2)) - ia*sin(ksi0(2))); |
---|
115 | phi(2) = ksi0(2) + dt*ksi0(1); |
---|
116 | phi(3) = Pnew(1,1); |
---|
117 | phi(4) = Pnew(1,2); |
---|
118 | phi(5) = Pnew(2,2); |
---|
119 | |
---|
120 | A_l(1:5,1:5) = A_k; |
---|
121 | A_l(1:5,6) = phi - A_k*ksi0; |
---|
122 | A_l(6,6) = 1.0; |
---|
123 | |
---|
124 | %%% |
---|
125 | A_l(1,2) = 0; %maze clen e*(...), ktery se prevede do B |
---|
126 | A_l(1:2,6) = [0;dt*ref_ome]; %zmena korekce, protoze je to tam uz linearni, ale posun |
---|
127 | %%% |
---|
128 | |
---|
129 | C_k = zeros(2,5); |
---|
130 | C_k(1:2,1:2) = C; |
---|
131 | |
---|
132 | pre_k = zeros(3,1); |
---|
133 | pre_k(1) = Pnew(1,1); |
---|
134 | pre_k(2) = Pnew(1,2); |
---|
135 | pre_k(3) = Pnew(2,2); |
---|
136 | %max x(5) = pi^2/3 ... variance of uniform -pi,pi |
---|
137 | if(pre_k(3) > pi^2/3) |
---|
138 | pre_k(3) = pi^2/3; |
---|
139 | end |
---|
140 | end |
---|