1 | function pmsm_ildp4
|
---|
2 | %verze ildp algoritmu s uvazovanim P (v logaritmu) pro PMSM motor
|
---|
3 | %rozsirena verze o diag P v pi aproximaci u
|
---|
4 | tic
|
---|
5 |
|
---|
6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
7 | %pocatecni konstanty
|
---|
8 |
|
---|
9 | Iterace = 20; %iterace
|
---|
10 | K = 20; %casy
|
---|
11 | N = 100; %vzorky
|
---|
12 |
|
---|
13 | %konstanty motoru
|
---|
14 | %Rs = 0.28;
|
---|
15 | %Ls = 0.003465;
|
---|
16 | %PSIpm = 0.1989;
|
---|
17 | %kp = 1.5;
|
---|
18 | %p = 4.0;
|
---|
19 | %J = 0.04;
|
---|
20 | DELTAt = 0.000125;
|
---|
21 |
|
---|
22 | %upravene konstanty
|
---|
23 | Ca = 0.9898;
|
---|
24 | Cb = 0.0072;
|
---|
25 | Cc = 0.0361;
|
---|
26 | Cd = 1.0;
|
---|
27 | Ce = 0.0149;
|
---|
28 |
|
---|
29 | %omezeni rizeni
|
---|
30 | cC1 = 100;
|
---|
31 | % cLb = -50;
|
---|
32 | % cUb = 50;
|
---|
33 |
|
---|
34 | %presnost mereni proudu
|
---|
35 | deltaI = 0.085;
|
---|
36 |
|
---|
37 | %matice
|
---|
38 | %kovariancni matice Q a R
|
---|
39 | mQ = diag([0.0013 0.0013 5.0e-6 1.0e-10]);
|
---|
40 | mR = diag([0.0006 0.0006]);
|
---|
41 |
|
---|
42 | %matice pro vypocet
|
---|
43 | %matice A zavisla na parametrech
|
---|
44 | mA = zeros(4);
|
---|
45 | mA(1,1) = Ca;
|
---|
46 | mA(2,2) = Ca;
|
---|
47 | mA(3,3) = Cd;
|
---|
48 | mA(4,4) = 1;
|
---|
49 | mA(4,3) = DELTAt;
|
---|
50 |
|
---|
51 | %macite C konstantni
|
---|
52 | mC = [ 1 0 0 0; 0 1 0 0];
|
---|
53 |
|
---|
54 | %pozadovana hodnota otacek
|
---|
55 | omega_t_stripe = 1.0015;
|
---|
56 |
|
---|
57 | %penalizace za vstupy
|
---|
58 | cPenPsi = 0;%0.000009;
|
---|
59 |
|
---|
60 | %pocatecni hodnoty
|
---|
61 | X0 = [0; 0; 1; pi/2];
|
---|
62 | Y0 = [0; 0];
|
---|
63 | P0 = diag([0.01 0.01 0.01 0.01]);
|
---|
64 |
|
---|
65 | h_bel = 0;
|
---|
66 | h_beldx = [0; 0; 0; 0;];
|
---|
67 | h_beldxdx = zeros(4);
|
---|
68 |
|
---|
69 | %velikost okoli pro lokalni metodu
|
---|
70 | % rhoi = 0.0001;
|
---|
71 | % rhoo = 0.00015;
|
---|
72 | % rhot = 0.00005;
|
---|
73 | % rhop = 0.0001;
|
---|
74 | rhoi = sqrt(mQ(1,1));
|
---|
75 | rhoo = sqrt(mQ(3,3));
|
---|
76 | rhot = sqrt(mQ(4,4));
|
---|
77 | rhop = 0.001;
|
---|
78 |
|
---|
79 | %zvetseni hamiltonianu pro minimalizace
|
---|
80 | % mag = 1000;
|
---|
81 | mag = 1;
|
---|
82 |
|
---|
83 | %prepinac sumu on/off
|
---|
84 | noise = 0;
|
---|
85 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
86 | %globalni promenne
|
---|
87 |
|
---|
88 | Kpi_alfa = -0.3*ones(1, K); %konstanty aproximace slozky rizeni u_alfa
|
---|
89 | Kpi_beta = 0.01*ones(1, K); %konstanty aproximace slozky rizeni u_beta
|
---|
90 | % Kpi_alfa = ones(1, K); %konstanty aproximace slozky rizeni u_alfa
|
---|
91 | % Kpi_beta = ones(1, K); %konstanty aproximace slozky rizeni u_beta
|
---|
92 | % Kpi_alfa = zeros(4, K); %konstanty aproximace slozky rizeni u_alfa
|
---|
93 | % Kpi_alfa(1, :) = 1000*Cc*Ce*ones(1, K);
|
---|
94 | % Kpi_alfa(2, :) = 1000*Cc*Ce*ones(1, K);
|
---|
95 | %
|
---|
96 | % Kpi_beta = zeros(4, K); %konstanty aproximace slozky rizeni u_beta
|
---|
97 | % Kpi_beta(1, :) = Cc*Ce*ones(1, K);
|
---|
98 | % Kpi_beta(2, :) = Cc*Ce*ones(1, K);
|
---|
99 | Kpi = ones(9, K);
|
---|
100 |
|
---|
101 |
|
---|
102 | Wv = zeros(6, K); %konstanty aproximace Bellmanovy fce
|
---|
103 |
|
---|
104 | Xkn = zeros(4, K, N); % X = [i_alfa, i_beta, omega, theta]
|
---|
105 | Ykn = zeros(2, K, N); % Y = [i_alfa, i_beta]
|
---|
106 | Pkn = zeros(4, 4, K, N); % P = N vzorku posloupnosti K matic 4x4
|
---|
107 |
|
---|
108 | mKy = zeros(4, 2); % K = pomocna matice pro vypocet
|
---|
109 | mRy = zeros(2, 2); % R = pomocna matice pro vypocet
|
---|
110 |
|
---|
111 | Xstripe = zeros(4, K);
|
---|
112 | Pstripe = zeros(4, 4, K);
|
---|
113 |
|
---|
114 | Epsilon = zeros(6, N); %globalni promena pro vypocet Bellmanovy fce z odchylek (X - Xprum)
|
---|
115 |
|
---|
116 | gka = 0; %globalni promenna pro prenos casu k
|
---|
117 | gnu = 0; %globalni promenna pro prenos vzorku n
|
---|
118 |
|
---|
119 | Uopt2 = zeros(2, N);
|
---|
120 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
121 | %hlavni iteracni smycka
|
---|
122 | for i = 1:Iterace,
|
---|
123 |
|
---|
124 | disp(['Iterace: ', num2str(i)]);
|
---|
125 | %generovani stavu
|
---|
126 | for n = 1:N,
|
---|
127 | Xkn(:, 1, n) = X0;
|
---|
128 | Ykn(:, 1, n) = Y0;
|
---|
129 | Pkn(:, :, 1, n) = P0;
|
---|
130 |
|
---|
131 | for k = 1:K-1,
|
---|
132 | Uk = uPi(k, Xkn(:, k, n), Pkn(:, :, k, n));
|
---|
133 |
|
---|
134 | mRy = mC * Pkn(:, :, k, n) * mC' + mR;
|
---|
135 | mKy = Pkn(:, :, k, n) * mC' / mRy;
|
---|
136 | Xkn(:, k+1, n) = fceG(Xkn(:, k, n), Uk) - mKy * (Ykn(:, k, n) - fceH(Xkn(:, k, n))) + noise * sqrtm(mQ) * randn(4, 1);%+gauss sum s rozptylem odmocnina mQ
|
---|
137 | Ykn(:, k+1, n) = round(Xkn(1:2, k+1, n) / deltaI) * deltaI; %X kopie do Y se vzorkovanim 0.085
|
---|
138 | mA(1, 3) = Cb * sin(Xkn(4, k, n));
|
---|
139 | mA(1, 4) = Cb * Xkn(3, k, n) * cos(Xkn(4, k, n));
|
---|
140 | mA(2, 3) = - Cb * cos(Xkn(4, k, n));
|
---|
141 | mA(2, 4) = Cb * Xkn(3, k, n) * sin(Xkn(4, k, n));
|
---|
142 | mA(3, 1) = - Ce * sin(Xkn(4, k, n));
|
---|
143 | mA(3, 2) = Ce * cos(Xkn(4, k, n));
|
---|
144 | mA(3, 4) = - Ce * (Xkn(2, k, n) * sin(Xkn(4, k, n)) + Xkn(1, k, n) * cos(Xkn(4, k, n)));
|
---|
145 | Pkn(:, :, k+1, n) = mA * (Pkn(:, :, k, n) - Pkn(:, :, k, n) * mC' * inv(mRy) * mC * Pkn(:, :, k, n)) * mA' + mQ;
|
---|
146 | end
|
---|
147 | end
|
---|
148 | Xstripe = mean(Xkn, 3);
|
---|
149 | Pstripe = mean(Pkn, 4);
|
---|
150 |
|
---|
151 | for k = K-1:-1:1,
|
---|
152 | gka = k;
|
---|
153 |
|
---|
154 | % 1]
|
---|
155 | for n = 1:N,
|
---|
156 | %krive okoli
|
---|
157 | Xkn(1, k, n) = Xstripe(1, k) + rhoi*randn();
|
---|
158 | Xkn(2, k, n) = Xstripe(2, k) + rhoi*randn();
|
---|
159 | Xkn(3, k, n) = Xstripe(3, k) + rhoo*randn();
|
---|
160 | Xkn(4, k, n) = Xstripe(4, k) + rhot*randn();
|
---|
161 |
|
---|
162 | Ykn(:, k, n) = round(Xkn(1:2, k, n) / deltaI) * deltaI;
|
---|
163 |
|
---|
164 | Pkn(:, :, k, n) = Pstripe(:, :, k) .* exp(rhop*randn(4));
|
---|
165 | end
|
---|
166 |
|
---|
167 | % 2]
|
---|
168 | for n = 1:N,
|
---|
169 | gnu = n;
|
---|
170 | % [Uopt2(:, n), Hmin(n)] = fmincon(@Hamilt, uPi(k, Xkn(:, k, n),Pkn(:, :, k, n)), [], [], [], [], [], [], @Cond2, optimset('GradConstr','on','Display','notify','Algorithm','active-set','TolFun',1e-20));
|
---|
171 | [Uopt2(:, n), Hmin(n)] = minimum(Xkn(:, k, n));
|
---|
172 | % Uopt2(1,n)=sin(2*pi/20*k);
|
---|
173 | % Z = zeros(101,101);
|
---|
174 | % ii = 0;
|
---|
175 | % jj = 0;
|
---|
176 | % for ii = -50:50,
|
---|
177 | % for jj = -50:50,
|
---|
178 | % Z(ii+51,jj+51) = Hamilt([ii,jj]);
|
---|
179 | % end
|
---|
180 | % end
|
---|
181 | % surf(Z);
|
---|
182 | end
|
---|
183 |
|
---|
184 | % 3]
|
---|
185 | for n = 1:N,
|
---|
186 | Vn(n) = DELTAt*Hmin(n)/mag + Vtilde(k+1, Xkn(:, k, n), Pkn(:, :, k, n));
|
---|
187 |
|
---|
188 | end
|
---|
189 |
|
---|
190 | % 4]
|
---|
191 | %urceni aproximace V Bellmanovy funkce
|
---|
192 | for n = 1:N,
|
---|
193 | Epsilon(1:4, n) = Xkn(1:4, k, n) - Xstripe(1:4, k);
|
---|
194 | tpdiag = diag(Pkn(:, :, k, n) ./ Pstripe(:, :, k));
|
---|
195 | Epsilon(5:6, n) = tpdiag(3:4);
|
---|
196 | end
|
---|
197 | mFi = matrixFi(Epsilon);
|
---|
198 | FiFiTInvFi = (mFi*mFi')\mFi;
|
---|
199 | Wv(:,k) = FiFiTInvFi * Vn';
|
---|
200 |
|
---|
201 | %urceni aproximace pi rizeni u
|
---|
202 | Kpi_alfa(k) = mean(Uopt2(1,:));
|
---|
203 | Kpi_beta(k) = mean(Uopt2(2,:));
|
---|
204 | % mPsi = ones(N,1);
|
---|
205 | % PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
206 | % Kpi_alfa(:, k) = PsiPsiTInvPsi * Uopt2(1,:)';
|
---|
207 | %
|
---|
208 | % mPsi = ones(N,1);
|
---|
209 | % PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
210 | % Kpi_beta(:, k) = PsiPsiTInvPsi * Uopt2(2,:)';
|
---|
211 | % mPsi = [sin(squeeze(Xkn(4, k, :))),...1
|
---|
212 | % cos(squeeze(Xkn(4, k, :))),...2
|
---|
213 | % (sin(squeeze(Xkn(4, k, :))).^2),...3
|
---|
214 | % (cos(squeeze(Xkn(4, k, :))).^2)];%4
|
---|
215 | % PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
216 | % Kpi_alfa(:, k) = PsiPsiTInvPsi * Uopt2(1,:)';
|
---|
217 | %
|
---|
218 | % mPsi = [sin(squeeze(Xkn(4, k, :))),...1
|
---|
219 | % cos(squeeze(Xkn(4, k, :))),...2
|
---|
220 | % (sin(squeeze(Xkn(4, k, :))).^2),...3
|
---|
221 | % (cos(squeeze(Xkn(4, k, :))).^2)];%4
|
---|
222 | % PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
223 | % Kpi_beta(:, k) = PsiPsiTInvPsi * Uopt2(2,:)';
|
---|
224 |
|
---|
225 | % tmpUfi = squeeze(Xkn(4, k, :) + DELTAt*Xkn(3, k, :));
|
---|
226 | % tmpUamp = sqrt(Uopt2(1,:).^2 + Uopt2(2,:).^2)';
|
---|
227 | % mPsi = [Cd*Cd*squeeze(Xkn(3, k, :)),...1
|
---|
228 | % Cd*Ce*squeeze(Xkn(2, k, :).*cos(Xkn(4, k, :))),...2
|
---|
229 | % - Cd*Ce*squeeze(Xkn(1, k, :).*sin(Xkn(4, k, :))),...3
|
---|
230 | % Ce*Ca*squeeze(Xkn(2, k, :)).*cos(tmpUfi),...4
|
---|
231 | % - Ce*Cb*squeeze(Xkn(3, k, :).*cos(Xkn(4, k, :))).*cos(tmpUfi),...5
|
---|
232 | % Ce*Ca*squeeze(Xkn(1, k, :)).*sin(tmpUfi),...6
|
---|
233 | % Ce*Cb*squeeze(Xkn(3, k, :).*sin(Xkn(4, k, :))).*sin(tmpUfi),...7
|
---|
234 | % Ce*Cc*squeeze( (cos(tmpUfi)).^2 - (sin(tmpUfi)).^2 ).*tmpUamp,...8
|
---|
235 | % tmpUamp];%9
|
---|
236 | % PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
237 | % Kpi(:, k) = PsiPsiTInvPsi * (omega_t_stripe*ones(N, 1));
|
---|
238 | end
|
---|
239 | end
|
---|
240 |
|
---|
241 | %%%%%%%%%%%
|
---|
242 | toc
|
---|
243 | % keyboard
|
---|
244 | Kpi
|
---|
245 | Kpi_alfa
|
---|
246 | Kpi_beta
|
---|
247 | %vykresleni grafu
|
---|
248 | clf
|
---|
249 | subplot(3,4,3);
|
---|
250 | plot(1:K,omega_t_stripe*ones(1,K));
|
---|
251 |
|
---|
252 | Ukn = zeros(2, K, N);
|
---|
253 | for n = 1:N,
|
---|
254 | Xkn(:, 1, n) = X0;
|
---|
255 | Ykn(:, 1, n) = Y0;
|
---|
256 | Pkn(:, :, 1, n) = P0;
|
---|
257 | for k = 1:K-1,
|
---|
258 | Ukn(:, k, n) = uPi(k, Xkn(:, k, n), Pkn(:, :, k, n));
|
---|
259 | mRy = mC * Pkn(:, :, k, n) * mC' + mR;
|
---|
260 | mKy = Pkn(:, :, k, n) * mC' / mRy;
|
---|
261 | Xkn(:, k+1, n) = fceG(Xkn(:, k, n), Ukn(:, k, n)) - mKy * (Ykn(:, k, n) - fceH(Xkn(:, k, n))) + noise * sqrtm(mQ) * randn(4, 1);%+gauss sum s rozptylem odmocnina mQ
|
---|
262 | Ykn(:, k+1, n) = round(Xkn(1:2, k+1, n) / deltaI) * deltaI; %X kopie do Y se vzorkovanim 0.085
|
---|
263 | mA(1, 3) = Cb * sin(Xkn(4, k, n));
|
---|
264 | mA(1, 4) = Cb * Xkn(3, k, n) * cos(Xkn(4, k, n));
|
---|
265 | mA(2, 3) = - Cb * cos(Xkn(4, k, n));
|
---|
266 | mA(2, 4) = Cb * Xkn(3, k, n) * sin(Xkn(4, k, n));
|
---|
267 | mA(3, 1) = - Ce * sin(Xkn(4, k, n));
|
---|
268 | mA(3, 2) = Ce * cos(Xkn(4, k, n));
|
---|
269 | mA(3, 4) = - Ce * (Xkn(2, k, n) * sin(Xkn(4, k, n)) + Xkn(1, k, n) * cos(Xkn(4, k, n)));
|
---|
270 | Pkn(:, :, k+1, n) = mA * (Pkn(:, :, k, n) - Pkn(:, :, k, n) * mC' * inv(mRy) * mC * Pkn(:, :, k, n)) * mA' + mQ;
|
---|
271 | end
|
---|
272 |
|
---|
273 | hold all
|
---|
274 | subplot(3,4,1);
|
---|
275 | title('X:i_{\alpha}')
|
---|
276 | plot(1:K,Xkn(1,:,n))
|
---|
277 |
|
---|
278 | hold all
|
---|
279 | subplot(3,4,2);
|
---|
280 | title('X:i_{\beta}')
|
---|
281 | plot(1:K,Xkn(2,:,n))
|
---|
282 |
|
---|
283 | hold all
|
---|
284 | subplot(3,4,3);
|
---|
285 | title('X:\omega')
|
---|
286 | plot(1:K,Xkn(3,:,n))
|
---|
287 |
|
---|
288 | hold all
|
---|
289 | subplot(3,4,4);
|
---|
290 | title('X:\theta')
|
---|
291 | plot(1:K,Xkn(4,:,n))
|
---|
292 |
|
---|
293 | hold all
|
---|
294 | subplot(3,4,5);
|
---|
295 | title('Y:i_{\alpha}')
|
---|
296 | plot(1:K,Ykn(1,:,n))
|
---|
297 |
|
---|
298 | hold all
|
---|
299 | subplot(3,4,6);
|
---|
300 | title('Y:i_{\beta}')
|
---|
301 | plot(1:K,Ykn(2,:,n))
|
---|
302 |
|
---|
303 | hold all
|
---|
304 | subplot(3,4,7);
|
---|
305 | title('u_{\alpha}')
|
---|
306 | plot(1:K,Ukn(1,:,n))
|
---|
307 |
|
---|
308 | hold all
|
---|
309 | subplot(3,4,8);
|
---|
310 | title('u_{\beta}')
|
---|
311 | plot(1:K,Ukn(2,:,n))
|
---|
312 |
|
---|
313 | hold all
|
---|
314 | subplot(3,4,9);
|
---|
315 | title('P(1, 1)')
|
---|
316 | plot(1:K,squeeze(Pkn(1, 1, :, n)))
|
---|
317 |
|
---|
318 | hold all
|
---|
319 | subplot(3,4,10);
|
---|
320 | title('P(2, 2)')
|
---|
321 | plot(1:K,squeeze(Pkn(2, 2, :, n)))
|
---|
322 |
|
---|
323 | hold all
|
---|
324 | subplot(3,4,11);
|
---|
325 | title('P(3, 3)')
|
---|
326 | plot(1:K,squeeze(Pkn(3, 3, :, n)))
|
---|
327 |
|
---|
328 | hold all
|
---|
329 | subplot(3,4,12);
|
---|
330 | title('P(4, 4)')
|
---|
331 | plot(1:K,squeeze(Pkn(4, 4, :, n)))
|
---|
332 | end
|
---|
333 |
|
---|
334 | figure
|
---|
335 |
|
---|
336 | for n = 1:N,
|
---|
337 | Xkn(:, 1, n) = X0;
|
---|
338 | for k = 1:K-1,
|
---|
339 | Ukn(:, k, n) = uPi(k, Xkn(:, k, n), zeros(4));
|
---|
340 | Xkn(:, k+1, n) = fceG(Xkn(:, k, n), Ukn(:, k, n)) + noise * sqrtm(mQ) * randn(4, 1);
|
---|
341 | end
|
---|
342 |
|
---|
343 | hold all
|
---|
344 | subplot(2,3,1);
|
---|
345 | title('X:i_{\alpha}')
|
---|
346 | plot(1:K,Xkn(1,:,n))
|
---|
347 |
|
---|
348 | hold all
|
---|
349 | subplot(2,3,2);
|
---|
350 | title('X:i_{\beta}')
|
---|
351 | plot(1:K,Xkn(2,:,n))
|
---|
352 |
|
---|
353 | hold all
|
---|
354 | subplot(2,3,3);
|
---|
355 | title('X:\omega')
|
---|
356 | plot(1:K,Xkn(3,:,n))
|
---|
357 |
|
---|
358 | hold all
|
---|
359 | subplot(2,3,4);
|
---|
360 | title('X:\theta')
|
---|
361 | plot(1:K,Xkn(4,:,n))
|
---|
362 |
|
---|
363 | hold all
|
---|
364 | subplot(2,3,5);
|
---|
365 | title('u_{\alpha}')
|
---|
366 | plot(1:K,Ukn(1,:,n))
|
---|
367 |
|
---|
368 | hold all
|
---|
369 | subplot(2,3,6);
|
---|
370 | title('u_{\beta}')
|
---|
371 | plot(1:K,Ukn(2,:,n))
|
---|
372 |
|
---|
373 | end
|
---|
374 |
|
---|
375 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
376 | %pomocne funkce
|
---|
377 |
|
---|
378 | function [val_uPi] = uPi(k_uPi, x_uPi, p_uPi)
|
---|
379 | val_uPi = zeros(2, 1);
|
---|
380 | val_uPi(1) = Kpi_alfa(k_uPi);
|
---|
381 | val_uPi(2) = Kpi_beta(k_uPi);
|
---|
382 | % val_uPi(1) = Kpi_alfa(1, k_uPi)*sin(x_uPi(4)) + Kpi_alfa(2, k_uPi)*cos(x_uPi(4)) + Kpi_alfa(3, k_uPi)*(sin(x_uPi(4)))^2 + Kpi_alfa(4, k_uPi)*(cos(x_uPi(4)))^2;
|
---|
383 | % val_uPi(2) = Kpi_beta(1, k_uPi)*sin(x_uPi(4)) + Kpi_beta(2, k_uPi)*cos(x_uPi(4)) + Kpi_beta(3, k_uPi)*(sin(x_uPi(4)))^2 + Kpi_beta(4, k_uPi)*(cos(x_uPi(4)))^2;
|
---|
384 | % tmpfi = x_uPi(4) + DELTAt*x_uPi(3);
|
---|
385 | % tmpw = ( omega_t_stripe - Cd*(Kpi(1, k_uPi)*Cd*x_uPi(3) + Kpi(2, k_uPi)*Ce*x_uPi(2)*cos(x_uPi(4)) - Kpi(3, k_uPi)*Ce*x_uPi(1)*sin(x_uPi(4)))...
|
---|
386 | % - Ce*( (Kpi(4, k_uPi)*Ca*x_uPi(2) - Kpi(5, k_uPi)*Cb*x_uPi(3)*cos(x_uPi(4)))*cos(tmpfi)...
|
---|
387 | % -(Kpi(6, k_uPi)*Ca*x_uPi(1) + Kpi(7, k_uPi)*Cb*x_uPi(3)*sin(x_uPi(4)))*sin(tmpfi) ) ) /...
|
---|
388 | % (Kpi(8, k_uPi)*Ce*Cc*( (cos(tmpfi))^2 - (sin(tmpfi))^2 ) + Kpi(9, k_uPi));
|
---|
389 | %
|
---|
390 | % if(tmpw > cC1)
|
---|
391 | % tmpw = cC1;
|
---|
392 | % elseif(tmpw < - cC1)
|
---|
393 | % tmpw = -cC1;
|
---|
394 | % end
|
---|
395 | % val_uPi(1) = tmpw*sin(tmpfi);
|
---|
396 | % val_uPi(2) = tmpw*cos(tmpfi);
|
---|
397 | end
|
---|
398 |
|
---|
399 | function [val_ham] = Hamilt(u_ham)
|
---|
400 | mRy = mC * Pkn(:, :, gka, gnu) * mC' + mR;
|
---|
401 | mKy = Pkn(:, :, gka, gnu) * mC' / mRy;
|
---|
402 | tXkn = fceG(Xkn(:, gka, gnu), u_ham) - mKy * (Ykn(:, gka, gnu) - fceH(Xkn(:, gka, gnu)));
|
---|
403 | mA(1, 3) = Cb * sin(Xkn(4, gka, gnu));
|
---|
404 | mA(1, 4) = Cb * Xkn(3, gka, gnu) * cos(Xkn(4, gka, gnu));
|
---|
405 | mA(2, 3) = - Cb * cos(Xkn(4, gka, gnu));
|
---|
406 | mA(2, 4) = Cb * Xkn(3, gka, gnu) * sin(Xkn(4, gka, gnu));
|
---|
407 | mA(3, 1) = - Ce * sin(Xkn(4, gka, gnu));
|
---|
408 | mA(3, 2) = Ce * cos(Xkn(4, gka, gnu));
|
---|
409 | mA(3, 4) = - Ce * (Xkn(2, gka, gnu) * sin(Xkn(4, gka, gnu)) + Xkn(1, gka, gnu) * cos(Xkn(4, gka, gnu)));
|
---|
410 | tPkn = mA * (Pkn(:, :, gka, gnu) - Pkn(:, :, gka, gnu) * mC' * inv(mRy) * mC * Pkn(:, :, gka, gnu)) * mA' + mQ;
|
---|
411 | tf = zeros(4,1);
|
---|
412 | tf(1:2) = tXkn(3:4);
|
---|
413 | tfpdiag = diag(tPkn);
|
---|
414 | tf(3:4) = tfpdiag(3:4);
|
---|
415 |
|
---|
416 | % loss = (tXkn(3) - omega_t_stripe)^2;
|
---|
417 | % loss = (Cd * Xkn(3, gka, gnu) + Ce * ((Ca * Xkn(2, gka, gnu) - Cb * Xkn(3, gka, gnu) * cos(Xkn(4, gka, gnu)) + Cc * u_ham(2)) * cos(Xkn(4, gka, gnu)) - (Ca * Xkn(1, gka, gnu) + Cb * Xkn(3, gka, gnu) * sin(Xkn(4, gka, gnu)) + Cc * u_ham(1)) * sin(Xkn(4, gka, gnu))) - omega_t_stripe)^2;
|
---|
418 | % if(gka == 1)
|
---|
419 | % loss = (tXkn(3) - omega_t_stripe)^2;
|
---|
420 | % else
|
---|
421 | % loss = (Cd * Xkn(3, gka, gnu) + Ce * ((Ca * Xkn(2, gka-1, gnu) - Cb * Xkn(3, gka-1, gnu) * cos(Xkn(4, gka-1, gnu)) + Cc * u_ham(2)) * cos(Xkn(4, gka, gnu)) - (Ca * Xkn(1, gka-1, gnu) + Cb * Xkn(3, gka-1, gnu) * sin(Xkn(4, gka-1, gnu)) + Cc * u_ham(1)) * sin(Xkn(4, gka, gnu))) - omega_t_stripe)^2;
|
---|
422 | % end
|
---|
423 | % loss = (Cd * tXkn(3) + Ce * ((Ca * Xkn(2, gka, gnu) - Cb * Xkn(3, gka, gnu) * cos(Xkn(4, gka, gnu)) + Cc * u_ham(2)) * cos(tXkn(4)) - (Ca * Xkn(1, gka, gnu) + Cb * Xkn(3, gka, gnu) * sin(Xkn(4, gka, gnu)) + Cc * u_ham(1)) * sin(tXkn(4))) - omega_t_stripe)^2;
|
---|
424 |
|
---|
425 |
|
---|
426 | % loss = loss + cPenPsi*(u_ham(1)^2 + u_ham(2)^2);
|
---|
427 | loss = ( Cd*(Cd*Xkn(3, gka, gnu)...
|
---|
428 | + Ce*Xkn(2, gka, gnu)*cos(Xkn(4, gka, gnu))...
|
---|
429 | - Ce*Xkn(1, gka, gnu)*sin(Xkn(4, gka, gnu)))...
|
---|
430 | + Ce*( (Ca*Xkn(2, gka, gnu) - Cb*Xkn(3, gka, gnu)*cos(Xkn(4, gka, gnu)) )*cos(Xkn(4, gka, gnu)+DELTAt*Xkn(3, gka, gnu))...
|
---|
431 | -(Ca*Xkn(1, gka, gnu) + Cb*Xkn(3, gka, gnu)*sin(Xkn(4, gka, gnu)) )*sin(Xkn(4, gka, gnu)+DELTAt*Xkn(3, gka, gnu)))...
|
---|
432 | + Ce*Cc*u_ham(2)*cos(Xkn(4, gka, gnu)+DELTAt*Xkn(3, gka, gnu))...
|
---|
433 | - Ce*Cc*u_ham(1)*sin(Xkn(4, gka, gnu)+DELTAt*Xkn(3, gka, gnu))...
|
---|
434 | - omega_t_stripe )^2;
|
---|
435 |
|
---|
436 | val_ham = mag*(loss + tf' * Vtilde_dx(gka+1, Xkn(:, gka, gnu), Pkn(:, :, gka, gnu)) + 1/2 * trace(mQ * Vtilde_dx_dx(gka+1, Xkn(:, gka, gnu), Pkn(:, :, gka, gnu))));
|
---|
437 |
|
---|
438 | end
|
---|
439 |
|
---|
440 | function [val_Vt] = Vtilde(k_Vt, x_Vt, p_Vt)
|
---|
441 | if(k_Vt == K)
|
---|
442 | val_Vt = h_bel;
|
---|
443 | else
|
---|
444 | Epsl = zeros(6, 1);
|
---|
445 | Epsl(1:4) = x_Vt(1:4) - Xstripe(1:4, k_Vt);
|
---|
446 | tpdiag = diag(p_Vt ./ Pstripe(:, :, k));
|
---|
447 | Epsl(5:6) = tpdiag(3:4);
|
---|
448 |
|
---|
449 | val_Vt = vectFi(Epsl)' * Wv(:,k_Vt);
|
---|
450 | end
|
---|
451 | end
|
---|
452 |
|
---|
453 | function [val_Vt] = Vtilde_dx(k_Vt, x_Vt, p_Vt)
|
---|
454 | if(k_Vt == K)
|
---|
455 | val_Vt = h_beldx;
|
---|
456 | else
|
---|
457 | Epsl = zeros(6, 1);
|
---|
458 | Epsl(1:4) = x_Vt(1:4) - Xstripe(1:4, k_Vt);
|
---|
459 | tpdiag = diag(p_Vt ./ Pstripe(:, :, k));
|
---|
460 | Epsl(5:6) = tpdiag(3:4);
|
---|
461 |
|
---|
462 | val_Vt = difFi(Epsl)' * Wv(:,k_Vt);
|
---|
463 | end
|
---|
464 | end
|
---|
465 |
|
---|
466 | function [val_Fi] = vectFi(x_Fi)
|
---|
467 | val_Fi = [ ...
|
---|
468 | 1; ... %1
|
---|
469 | x_Fi(3); ...
|
---|
470 | % x_Fi(4); ...
|
---|
471 | log(x_Fi(5)); ... %ln Xi pro 5-8 tj diagonala matice Pt 4x4
|
---|
472 | % log(x_Fi(6)); ...
|
---|
473 | x_Fi(3)^2; ...
|
---|
474 | % x_Fi(3)*x_Fi(4); ...
|
---|
475 | x_Fi(3)*log(x_Fi(5)); ...
|
---|
476 | % x_Fi(3)*log(x_Fi(6)); ...
|
---|
477 | % x_Fi(4)^2; ...
|
---|
478 | % x_Fi(4)*log(x_Fi(5)); ...
|
---|
479 | % x_Fi(4)*log(x_Fi(6)); ...
|
---|
480 | log(x_Fi(5))^2;...
|
---|
481 | % log(x_Fi(5))*log(x_Fi(6));...
|
---|
482 | % log(x_Fi(6))^2
|
---|
483 | ];
|
---|
484 | end
|
---|
485 |
|
---|
486 | function [val_Fi] = matrixFi(x_Fi)
|
---|
487 | val_Fi = [ ...
|
---|
488 | ones(1, N); ... %1
|
---|
489 | x_Fi(3, :); ...
|
---|
490 | % x_Fi(4, :); ...
|
---|
491 | log(x_Fi(5, :)); ... %ln Xi pro 5-8 tj diagonala matice Pt 4x4
|
---|
492 | % log(x_Fi(6, :)); ...
|
---|
493 | x_Fi(3, :).^2; ...
|
---|
494 | % x_Fi(3, :).*x_Fi(4, :); ...
|
---|
495 | x_Fi(3, :).*log(x_Fi(5, :)); ...
|
---|
496 | % x_Fi(3, :).*log(x_Fi(6, :)); ...
|
---|
497 | % x_Fi(4, :).^2; ...
|
---|
498 | % x_Fi(4, :).*log(x_Fi(5, :)); ...
|
---|
499 | % x_Fi(4, :).*log(x_Fi(6, :)); ...
|
---|
500 | log(x_Fi(5, :)).^2;...
|
---|
501 | % log(x_Fi(5, :)).*log(x_Fi(6, :));...
|
---|
502 | % log(x_Fi(6, :)).^2
|
---|
503 | ];
|
---|
504 |
|
---|
505 | end
|
---|
506 |
|
---|
507 | function [val_Fi] = difFi(x_Fi)
|
---|
508 | val_Fi = [ ...
|
---|
509 | 0 0 0 0; ... %1
|
---|
510 | 1 0 0 0; ... %2
|
---|
511 | % 0 1 0 0; ...%3
|
---|
512 | 0 0 1/(x_Fi(5)) 0; ... %4 %ln Xi pro 5-8 tj diagonala matice Pt 4x4
|
---|
513 | % 0 0 0 1/(x_Fi(6)); ... %5
|
---|
514 | 2*x_Fi(3) 0 0 0; ...%6
|
---|
515 | % x_Fi(4) x_Fi(3) 0 0; ...%7
|
---|
516 | log(x_Fi(5)) 0 x_Fi(3)/(x_Fi(5)) 0; ...%8
|
---|
517 | % log(x_Fi(6)) 0 0 x_Fi(3)/(x_Fi(6)); ... %9
|
---|
518 | % 0 2*x_Fi(4) 0 0; ...%10
|
---|
519 | % 0 log(x_Fi(5)) x_Fi(4)/(x_Fi(5)) 0; ...%11
|
---|
520 | % 0 log(x_Fi(6)) 0 x_Fi(4)/(x_Fi(6)); ... %12
|
---|
521 | 0 0 2*log(x_Fi(5))/(x_Fi(5)) 0;...%13
|
---|
522 | % 0 0 log(x_Fi(6))/(x_Fi(5)) log(x_Fi(5))/(x_Fi(6));...%14
|
---|
523 | % 0 0 0 2*log(x_Fi(6))/(x_Fi(6))
|
---|
524 | ];%15
|
---|
525 | end
|
---|
526 |
|
---|
527 | function [valvt] = Vtilde_dx_dx(kin, x_Vt, p_Vt)
|
---|
528 | if(kin == K)
|
---|
529 | valvt = h_beldxdx;
|
---|
530 | else
|
---|
531 | % valvt = Wv(4, kin)*diag([0 0 -1/(p_Vt(3,3)^2) 0]) +...
|
---|
532 | % Wv(5, kin)*diag([0 0 0 -1/(p_Vt(4,4)^2)]) +...
|
---|
533 | % Wv(6, kin)*diag([2 0 0 0]) +...
|
---|
534 | % Wv(7, kin)*[0 1 0 0; 1 0 0 0; 0 0 0 0; 0 0 0 0] +...
|
---|
535 | % Wv(8, kin)*[0 0 1/p_Vt(3,3) 0; 0 0 0 0; 1/p_Vt(3,3) 0 -x_Vt(3)/(p_Vt(3,3)^2) 0; 0 0 0 0] +...
|
---|
536 | % Wv(9, kin)*[0 0 1/p_Vt(4,4) 0; 0 0 0 0; 0 0 0 0; 1/p_Vt(4,4) 0 0 -x_Vt(3)/(p_Vt(4,4)^2)] +...
|
---|
537 | % Wv(10, kin)*diag([0 2 0 0]) +...
|
---|
538 | % Wv(11, kin)*[0 0 0 0; 0 0 1/p_Vt(3,3) 0; 0 1/p_Vt(3,3) -x_Vt(4)/(p_Vt(3,3)^2) 0; 0 0 0 0] +...
|
---|
539 | % Wv(12, kin)*[0 0 0 0; 0 0 0 1/p_Vt(4,4); 0 0 0 0; 0 1/p_Vt(4,4) 0 -x_Vt(4)/(p_Vt(4,4)^2)] +...
|
---|
540 | % Wv(13, kin)*[0 0 0 0; 0 0 0 0; 0 0 2*(1-log(p_Vt(3,3)))/(p_Vt(3,3)^2) 0; 0 0 0 0] +...
|
---|
541 | % Wv(14, kin)*[0 0 0 0; 0 0 0 0; 0 0 -log(p_Vt(4,4))/(p_Vt(3,3)^2) 1/(p_Vt(4,4))/(p_Vt(3,3)); 0 0 1/(p_Vt(4,4))/(p_Vt(3,3)) -log(p_Vt(3,3))/(p_Vt(4,4)^2)] +...
|
---|
542 | % Wv(15, kin)*[0 0 0 0; 0 0 0 0; 0 0 0 0; 0 0 0 2*(1-log(p_Vt(4,4)))/(p_Vt(4,4)^2)];
|
---|
543 | valvt = Wv(3, kin)*diag([0 0 0 -1/(p_Vt(3,3)^2)]) +...%
|
---|
544 | Wv(4, kin)*diag([2 0 0 0]) +...
|
---|
545 | Wv(5, kin)*[0 0 1/p_Vt(3,3) 0; 0 0 0 0; 1/p_Vt(3,3) 0 -x_Vt(3)/(p_Vt(3,3)^2) 0; 0 0 0 0] +...
|
---|
546 | Wv(6, kin)*[0 0 0 0; 0 0 0 0; 0 0 2*(1-log(p_Vt(3,3)))/(p_Vt(3,3)^2) 0; 0 0 0 0];
|
---|
547 | end
|
---|
548 | end
|
---|
549 |
|
---|
550 | function [c, ceq, GC, GCeq] = Cond2(x)
|
---|
551 | c = x(1)*x(1) + x(2)*x(2) - cC1^2;
|
---|
552 | ceq = [];
|
---|
553 | GC = [2*x(1); 2*x(2)];
|
---|
554 | GCeq = [];
|
---|
555 | end
|
---|
556 |
|
---|
557 | function [x_ret] = fceG(x_in, u_in)
|
---|
558 | x_ret = zeros(4, 1);
|
---|
559 | x_ret(1) = Ca * x_in(1) + Cb * x_in(3) * sin(x_in(4)) + Cc * u_in(1);
|
---|
560 | x_ret(2) = Ca * x_in(2) - Cb * x_in(3) * cos(x_in(4)) + Cc * u_in(2);
|
---|
561 | x_ret(3) = Cd * x_in(3) + Ce * (x_in(2) * cos(x_in(4)) - x_in(1) * sin(x_in(4)));
|
---|
562 | x_ret(4) = x_in(4) + x_in(3) * DELTAt;
|
---|
563 | end
|
---|
564 |
|
---|
565 | function [y_ret] = fceH(x_in)
|
---|
566 | y_ret = zeros(2, 1);
|
---|
567 | y_ret(1) = x_in(1);
|
---|
568 | y_ret(2) = x_in(2);
|
---|
569 | end
|
---|
570 |
|
---|
571 | function [Uopt_ret, Hmin_ret] = minimum(xin)
|
---|
572 | w = (Cd*(Cd*xin(3) + Ce*(xin(2)*cos(xin(4) - xin(1)*sin(xin(4))))) - omega_t_stripe +...
|
---|
573 | Ce*((Ca*xin(2)-Cb*xin(3)*cos(xin(4)))*cos(xin(4)+DELTAt*xin(3))-(Ca*xin(1)+Cb*xin(3)*sin(xin(4)))*sin(xin(4)+DELTAt*xin(3)))) / ...
|
---|
574 | (Ce*Cc*(sin(xin(4)*sin(xin(4)+DELTAt*xin(3))) - cos(xin(4)*cos(xin(4)+DELTAt*xin(3)))));
|
---|
575 | if(w > cC1)
|
---|
576 | w = cC1;
|
---|
577 | elseif(w < - cC1)
|
---|
578 | w = -cC1;
|
---|
579 | end
|
---|
580 | Uopt_ret(1) = w*sin(xin(4));
|
---|
581 | Uopt_ret(2) = w*cos(xin(4));
|
---|
582 | Hmin_ret = Hamilt(Uopt_ret);
|
---|
583 | end
|
---|
584 |
|
---|
585 | end
|
---|