1 | function pmsm_ildp3
|
---|
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 = 5; %iterace
|
---|
10 | K = 5; %casy
|
---|
11 | N = 50; %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; 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)); %1.5;
|
---|
75 | rhoo = sqrt(mQ(3,3));%1.5;
|
---|
76 | rhot = sqrt(mQ(4,4));%1.5;
|
---|
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.2*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(25, 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-12));
|
---|
171 | % Uopt2(1,n)=sin(2*pi/20*k);
|
---|
172 | % Z = zeros(101,101);
|
---|
173 | % ii = 0;
|
---|
174 | % jj = 0;
|
---|
175 | % for ii = -50:50,
|
---|
176 | % for jj = -50:50,
|
---|
177 | % Z(ii+51,jj+51) = Hamilt([ii,jj]);
|
---|
178 | % end
|
---|
179 | % end
|
---|
180 | % surf(Z);
|
---|
181 | end
|
---|
182 |
|
---|
183 | % 3]
|
---|
184 | for n = 1:N,
|
---|
185 | Vn(n) = DELTAt*Hmin(n)/mag + Vtilde(k+1, Xkn(:, k, n), Pkn(:, :, k, n));
|
---|
186 |
|
---|
187 | end
|
---|
188 |
|
---|
189 | % 4]
|
---|
190 | %urceni aproximace V Bellmanovy funkce
|
---|
191 | for n = 1:N,
|
---|
192 | Epsilon(1:4, n) = Xkn(1:4, k, n) - Xstripe(1:4, k);
|
---|
193 | tpdiag = diag(Pkn(:, :, k, n) ./ Pstripe(:, :, k));
|
---|
194 | Epsilon(5:6, n) = tpdiag(3:4);
|
---|
195 | end
|
---|
196 | mFi = matrixFi(Epsilon);
|
---|
197 | FiFiTInvFi = inv(mFi*mFi'+1e-5*eye(25))*mFi;
|
---|
198 | Wv(:,k) = FiFiTInvFi * Vn';
|
---|
199 |
|
---|
200 | %urceni aproximace pi rizeni u
|
---|
201 | Kpi_alfa(k) = mean(Uopt2(1,:));
|
---|
202 | Kpi_beta(k) = mean(Uopt2(2,:));
|
---|
203 | % mPsi = ones(N,1);
|
---|
204 | % PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
205 | % Kpi_alfa(:, k) = PsiPsiTInvPsi * Uopt2(1,:)';
|
---|
206 | %
|
---|
207 | % mPsi = ones(N,1);
|
---|
208 | % PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
209 | % Kpi_beta(:, k) = PsiPsiTInvPsi * Uopt2(2,:)';
|
---|
210 | % mPsi = [sin(squeeze(Xkn(4, k, :))),...1
|
---|
211 | % cos(squeeze(Xkn(4, k, :))),...2
|
---|
212 | % (sin(squeeze(Xkn(4, k, :))).^2),...3
|
---|
213 | % (cos(squeeze(Xkn(4, k, :))).^2)];%4
|
---|
214 | % PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
215 | % Kpi_alfa(:, k) = PsiPsiTInvPsi * Uopt2(1,:)';
|
---|
216 | %
|
---|
217 | % mPsi = [sin(squeeze(Xkn(4, k, :))),...1
|
---|
218 | % cos(squeeze(Xkn(4, k, :))),...2
|
---|
219 | % (sin(squeeze(Xkn(4, k, :))).^2),...3
|
---|
220 | % (cos(squeeze(Xkn(4, k, :))).^2)];%4
|
---|
221 | % PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
222 | % Kpi_beta(:, k) = PsiPsiTInvPsi * Uopt2(2,:)';
|
---|
223 | % tmpUfi = squeeze(Xkn(4, k, :) + DELTAt*Xkn(3, k, :));
|
---|
224 | % tmpUamp = sqrt(Uopt2(1,:).^2 + Uopt2(2,:).^2)';
|
---|
225 | % mPsi = [Cd*Cd*squeeze(Xkn(3, k, :)),...1
|
---|
226 | % Cd*Ce*squeeze(Xkn(2, k, :).*cos(Xkn(4, k, :))),...2
|
---|
227 | % - Cd*Ce*squeeze(Xkn(1, k, :).*sin(Xkn(4, k, :))),...3
|
---|
228 | % Ce*Ca*squeeze(Xkn(2, k, :)).*cos(tmpUfi),...4
|
---|
229 | % - Ce*Cb*squeeze(Xkn(3, k, :).*cos(Xkn(4, k, :))).*cos(tmpUfi),...5
|
---|
230 | % Ce*Ca*squeeze(Xkn(1, k, :)).*sin(tmpUfi),...6
|
---|
231 | % Ce*Cb*squeeze(Xkn(3, k, :).*sin(Xkn(4, k, :))).*sin(tmpUfi),...7
|
---|
232 | % Ce*Cc*squeeze( (cos(tmpUfi)).^2 - (sin(tmpUfi)).^2 ).*tmpUamp,...8
|
---|
233 | % tmpUamp];%9
|
---|
234 | % PsiPsiTInvPsi = (mPsi'*mPsi)\mPsi';
|
---|
235 | % Kpi(:, k) = PsiPsiTInvPsi * (omega_t_stripe*ones(N, 1));
|
---|
236 | end
|
---|
237 | end
|
---|
238 |
|
---|
239 | %%%%%%%%%%%
|
---|
240 | toc
|
---|
241 | % keyboard
|
---|
242 | Kpi_alfa
|
---|
243 | Kpi_beta
|
---|
244 | %vykresleni grafu
|
---|
245 | clf
|
---|
246 | subplot(3,4,3);
|
---|
247 | plot(1:K,omega_t_stripe*ones(1,K));
|
---|
248 |
|
---|
249 | Ukn = zeros(2, K, N);
|
---|
250 | for n = 1:N,
|
---|
251 | Xkn(:, 1, n) = X0;
|
---|
252 | Ykn(:, 1, n) = Y0;
|
---|
253 | Pkn(:, :, 1, n) = P0;
|
---|
254 | for k = 1:K-1,
|
---|
255 | Ukn(:, k, n) = uPi(k, Xkn(:, k, n), Pkn(:, :, k, n));
|
---|
256 | mRy = mC * Pkn(:, :, k, n) * mC' + mR;
|
---|
257 | mKy = Pkn(:, :, k, n) * mC' / mRy;
|
---|
258 | 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
|
---|
259 | Ykn(:, k+1, n) = round(Xkn(1:2, k+1, n) / deltaI) * deltaI; %X kopie do Y se vzorkovanim 0.085
|
---|
260 | mA(1, 3) = Cb * sin(Xkn(4, k, n));
|
---|
261 | mA(1, 4) = Cb * Xkn(3, k, n) * cos(Xkn(4, k, n));
|
---|
262 | mA(2, 3) = - Cb * cos(Xkn(4, k, n));
|
---|
263 | mA(2, 4) = Cb * Xkn(3, k, n) * sin(Xkn(4, k, n));
|
---|
264 | mA(3, 1) = - Ce * sin(Xkn(4, k, n));
|
---|
265 | mA(3, 2) = Ce * cos(Xkn(4, k, n));
|
---|
266 | mA(3, 4) = - Ce * (Xkn(2, k, n) * sin(Xkn(4, k, n)) + Xkn(1, k, n) * cos(Xkn(4, k, n)));
|
---|
267 | Pkn(:, :, k+1, n) = mA * (Pkn(:, :, k, n) - Pkn(:, :, k, n) * mC' * inv(mRy) * mC * Pkn(:, :, k, n)) * mA' + mQ;
|
---|
268 | end
|
---|
269 |
|
---|
270 | hold all
|
---|
271 | subplot(3,4,1);
|
---|
272 | title('X:i_{\alpha}')
|
---|
273 | plot(1:K,Xkn(1,:,n))
|
---|
274 |
|
---|
275 | hold all
|
---|
276 | subplot(3,4,2);
|
---|
277 | title('X:i_{\beta}')
|
---|
278 | plot(1:K,Xkn(2,:,n))
|
---|
279 |
|
---|
280 | hold all
|
---|
281 | subplot(3,4,3);
|
---|
282 | title('X:\omega')
|
---|
283 | plot(1:K,Xkn(3,:,n))
|
---|
284 |
|
---|
285 | hold all
|
---|
286 | subplot(3,4,4);
|
---|
287 | title('X:\theta')
|
---|
288 | plot(1:K,Xkn(4,:,n))
|
---|
289 |
|
---|
290 | hold all
|
---|
291 | subplot(3,4,5);
|
---|
292 | title('Y:i_{\alpha}')
|
---|
293 | plot(1:K,Ykn(1,:,n))
|
---|
294 |
|
---|
295 | hold all
|
---|
296 | subplot(3,4,6);
|
---|
297 | title('Y:i_{\beta}')
|
---|
298 | plot(1:K,Ykn(2,:,n))
|
---|
299 |
|
---|
300 | hold all
|
---|
301 | subplot(3,4,7);
|
---|
302 | title('u_{\alpha}')
|
---|
303 | plot(1:K,Ukn(1,:,n))
|
---|
304 |
|
---|
305 | hold all
|
---|
306 | subplot(3,4,8);
|
---|
307 | title('u_{\beta}')
|
---|
308 | plot(1:K,Ukn(2,:,n))
|
---|
309 |
|
---|
310 | hold all
|
---|
311 | subplot(3,4,9);
|
---|
312 | title('P(1, 1)')
|
---|
313 | plot(1:K,squeeze(Pkn(1, 1, :, n)))
|
---|
314 |
|
---|
315 | hold all
|
---|
316 | subplot(3,4,10);
|
---|
317 | title('P(2, 2)')
|
---|
318 | plot(1:K,squeeze(Pkn(2, 2, :, n)))
|
---|
319 |
|
---|
320 | hold all
|
---|
321 | subplot(3,4,11);
|
---|
322 | title('P(3, 3)')
|
---|
323 | plot(1:K,squeeze(Pkn(3, 3, :, n)))
|
---|
324 |
|
---|
325 | hold all
|
---|
326 | subplot(3,4,12);
|
---|
327 | title('P(4, 4)')
|
---|
328 | plot(1:K,squeeze(Pkn(4, 4, :, n)))
|
---|
329 | end
|
---|
330 |
|
---|
331 | figure
|
---|
332 |
|
---|
333 | for n = 1:N,
|
---|
334 | Xkn(:, 1, n) = X0;
|
---|
335 | for k = 1:K-1,
|
---|
336 | Ukn(:, k, n) = uPi(k, Xkn(:, k, n), zeros(4));
|
---|
337 | Xkn(:, k+1, n) = fceG(Xkn(:, k, n), Ukn(:, k, n)) + noise * sqrtm(mQ) * randn(4, 1);
|
---|
338 | end
|
---|
339 |
|
---|
340 | hold all
|
---|
341 | subplot(2,3,1);
|
---|
342 | title('X:i_{\alpha}')
|
---|
343 | plot(1:K,Xkn(1,:,n))
|
---|
344 |
|
---|
345 | hold all
|
---|
346 | subplot(2,3,2);
|
---|
347 | title('X:i_{\beta}')
|
---|
348 | plot(1:K,Xkn(2,:,n))
|
---|
349 |
|
---|
350 | hold all
|
---|
351 | subplot(2,3,3);
|
---|
352 | title('X:\omega')
|
---|
353 | plot(1:K,Xkn(3,:,n))
|
---|
354 |
|
---|
355 | hold all
|
---|
356 | subplot(2,3,4);
|
---|
357 | title('X:\theta')
|
---|
358 | plot(1:K,Xkn(4,:,n))
|
---|
359 |
|
---|
360 | hold all
|
---|
361 | subplot(2,3,5);
|
---|
362 | title('u_{\alpha}')
|
---|
363 | plot(1:K,Ukn(1,:,n))
|
---|
364 |
|
---|
365 | hold all
|
---|
366 | subplot(2,3,6);
|
---|
367 | title('u_{\beta}')
|
---|
368 | plot(1:K,Ukn(2,:,n))
|
---|
369 |
|
---|
370 | end
|
---|
371 |
|
---|
372 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
373 | %pomocne funkce
|
---|
374 |
|
---|
375 | function [val_uPi] = uPi(k_uPi, x_uPi, p_uPi)
|
---|
376 | val_uPi = zeros(2, 1);
|
---|
377 | val_uPi(1) = Kpi_alfa(k_uPi);
|
---|
378 | val_uPi(2) = Kpi_beta(k_uPi);
|
---|
379 | % 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;
|
---|
380 | % 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;
|
---|
381 | % tmpfi = x_uPi(4) + DELTAt*x_uPi(3);
|
---|
382 | % 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)))...
|
---|
383 | % - Ce*( (Kpi(4, k_uPi)*Ca*x_uPi(2) - Kpi(5, k_uPi)*Cb*x_uPi(3)*cos(x_uPi(4)))*cos(tmpfi)...
|
---|
384 | % -(Kpi(6, k_uPi)*Ca*x_uPi(1) + Kpi(7, k_uPi)*Cb*x_uPi(3)*sin(x_uPi(4)))*sin(tmpfi) ) ) /...
|
---|
385 | % (Kpi(8, k_uPi)*Ce*Cc*( (cos(tmpfi))^2 - (sin(tmpfi))^2 ) + Kpi(9, k_uPi));
|
---|
386 | %
|
---|
387 | % if(tmpw > cC1)
|
---|
388 | % tmpw = cC1;
|
---|
389 | % elseif(tmpw < - cC1)
|
---|
390 | % tmpw = -cC1;
|
---|
391 | % end
|
---|
392 | % val_uPi(1) = tmpw*sin(tmpfi);
|
---|
393 | % val_uPi(2) = tmpw*cos(tmpfi);
|
---|
394 | end
|
---|
395 |
|
---|
396 | function [val_ham] = Hamilt(u_ham)
|
---|
397 | mRy = mC * Pkn(:, :, gka, gnu) * mC' + mR;
|
---|
398 | mKy = Pkn(:, :, gka, gnu) * mC' / mRy;
|
---|
399 | tXkn = fceG(Xkn(:, gka, gnu), u_ham) - mKy * (Ykn(:, gka, gnu) - fceH(Xkn(:, gka, gnu)));
|
---|
400 | mA(1, 3) = Cb * sin(Xkn(4, gka, gnu));
|
---|
401 | mA(1, 4) = Cb * Xkn(3, gka, gnu) * cos(Xkn(4, gka, gnu));
|
---|
402 | mA(2, 3) = - Cb * cos(Xkn(4, gka, gnu));
|
---|
403 | mA(2, 4) = Cb * Xkn(3, gka, gnu) * sin(Xkn(4, gka, gnu));
|
---|
404 | mA(3, 1) = - Ce * sin(Xkn(4, gka, gnu));
|
---|
405 | mA(3, 2) = Ce * cos(Xkn(4, gka, gnu));
|
---|
406 | mA(3, 4) = - Ce * (Xkn(2, gka, gnu) * sin(Xkn(4, gka, gnu)) + Xkn(1, gka, gnu) * cos(Xkn(4, gka, gnu)));
|
---|
407 | tPkn = mA * (Pkn(:, :, gka, gnu) - Pkn(:, :, gka, gnu) * mC' * inv(mRy) * mC * Pkn(:, :, gka, gnu)) * mA' + mQ;
|
---|
408 | tf = zeros(6,1);
|
---|
409 | tf(1:4) = tXkn;
|
---|
410 | tfpdiag = diag(tPkn);
|
---|
411 | tf(5:6) = tfpdiag(3:4);
|
---|
412 |
|
---|
413 | % loss = (tXkn(3) - omega_t_stripe)^2;
|
---|
414 | % 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;
|
---|
415 | % if(gka == 1)
|
---|
416 | % loss = (tXkn(3) - omega_t_stripe)^2;
|
---|
417 | % else
|
---|
418 | % 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;
|
---|
419 | % end
|
---|
420 | % 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;
|
---|
421 |
|
---|
422 |
|
---|
423 | % loss = loss + cPenPsi*(u_ham(1)^2 + u_ham(2)^2);
|
---|
424 | loss = ( Cd*(Cd*Xkn(3, gka, gnu)...
|
---|
425 | + Ce*Xkn(2, gka, gnu)*cos(Xkn(4, gka, gnu))...
|
---|
426 | - Ce*Xkn(1, gka, gnu)*sin(Xkn(4, gka, gnu)))...
|
---|
427 | + 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))...
|
---|
428 | -(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)))...
|
---|
429 | + Ce*Cc*u_ham(2)*cos(Xkn(4, gka, gnu)+DELTAt*Xkn(3, gka, gnu))...
|
---|
430 | - Ce*Cc*u_ham(1)*sin(Xkn(4, gka, gnu)+DELTAt*Xkn(3, gka, gnu))...
|
---|
431 | - omega_t_stripe )^2;
|
---|
432 |
|
---|
433 | val_ham = mag*(loss + tf' * Vtilde_dx(gka+1, Xkn(:, gka, gnu), Pkn(:, :, gka, gnu)) + 1/2 * trace(mQ * Vtilde_dx_dx(gka+1)));
|
---|
434 |
|
---|
435 | end
|
---|
436 |
|
---|
437 | function [val_Vt] = Vtilde(k_Vt, x_Vt, p_Vt)
|
---|
438 | if(k_Vt == K)
|
---|
439 | val_Vt = h_bel;
|
---|
440 | else
|
---|
441 | Epsl = zeros(6, 1);
|
---|
442 | Epsl(1:4) = x_Vt(1:4) - Xstripe(1:4, k_Vt);
|
---|
443 | tpdiag = diag(p_Vt ./ Pstripe(:, :, k));
|
---|
444 | Epsl(5:6) = tpdiag(3:4);
|
---|
445 |
|
---|
446 | val_Vt = vectFi(Epsl)' * Wv(:,k_Vt);
|
---|
447 | end
|
---|
448 | end
|
---|
449 |
|
---|
450 | function [val_Vt] = Vtilde_dx(k_Vt, x_Vt, p_Vt)
|
---|
451 | if(k_Vt == K)
|
---|
452 | val_Vt = h_beldx;
|
---|
453 | else
|
---|
454 | Epsl = zeros(6, 1);
|
---|
455 | Epsl(1:4) = x_Vt(1:4) - Xstripe(1:4, k_Vt);
|
---|
456 | tpdiag = diag(p_Vt ./ Pstripe(:, :, k));
|
---|
457 | Epsl(5:6) = tpdiag(3:4);
|
---|
458 |
|
---|
459 | val_Vt = difFi(Epsl)' * Wv(:,k_Vt);
|
---|
460 | end
|
---|
461 | end
|
---|
462 |
|
---|
463 | function [val_Fi] = vectFi(x_Fi)
|
---|
464 | val_Fi = [ ...
|
---|
465 | 1; ... %1
|
---|
466 | x_Fi(1); ... %Xi pro 1-4
|
---|
467 | x_Fi(2); ...
|
---|
468 | x_Fi(3); ...
|
---|
469 | x_Fi(4); ...
|
---|
470 | log(x_Fi(5)); ... %ln Xi pro 5-8 tj diagonala matice Pt 4x4
|
---|
471 | log(x_Fi(6)); ...
|
---|
472 | x_Fi(1)^2; ... %kvadraticke cleny jen v Xi 1-4 a kombinovane
|
---|
473 | x_Fi(1)*x_Fi(2); ...
|
---|
474 | x_Fi(1)*x_Fi(3); ...
|
---|
475 | x_Fi(1)*x_Fi(4); ...
|
---|
476 | x_Fi(1)*log(x_Fi(5)); ...
|
---|
477 | x_Fi(1)*log(x_Fi(6)); ...
|
---|
478 | x_Fi(2)^2; ...
|
---|
479 | x_Fi(2)*x_Fi(3); ...
|
---|
480 | x_Fi(2)*x_Fi(4); ...
|
---|
481 | x_Fi(2)*log(x_Fi(5)); ...
|
---|
482 | x_Fi(2)*log(x_Fi(6)); ...
|
---|
483 | x_Fi(3)^2; ...
|
---|
484 | x_Fi(3)*x_Fi(4); ...
|
---|
485 | x_Fi(3)*log(x_Fi(5)); ...
|
---|
486 | x_Fi(3)*log(x_Fi(6)); ...
|
---|
487 | x_Fi(4)^2; ...
|
---|
488 | x_Fi(4)*log(x_Fi(5)); ...
|
---|
489 | x_Fi(4)*log(x_Fi(6)); ...
|
---|
490 | ];
|
---|
491 | end
|
---|
492 |
|
---|
493 | function [val_Fi] = matrixFi(x_Fi)
|
---|
494 | val_Fi = [ ...
|
---|
495 | ones(1, N); ... %1
|
---|
496 | x_Fi(1, :); ... %Xi pro 1-4
|
---|
497 | x_Fi(2, :); ...
|
---|
498 | x_Fi(3, :); ...
|
---|
499 | x_Fi(4, :); ...
|
---|
500 | log(x_Fi(5, :)); ... %ln Xi pro 5-8 tj diagonala matice Pt 4x4
|
---|
501 | log(x_Fi(6, :)); ...
|
---|
502 | x_Fi(1, :).^2; ... %kvadraticke cleny jen v Xi 1-4 a kombinovane
|
---|
503 | x_Fi(1, :).*x_Fi(2, :); ...
|
---|
504 | x_Fi(1, :).*x_Fi(3, :); ...
|
---|
505 | x_Fi(1, :).*x_Fi(4, :); ...
|
---|
506 | x_Fi(1, :).*log(x_Fi(5, :)); ...
|
---|
507 | x_Fi(1, :).*log(x_Fi(6, :)); ...
|
---|
508 | x_Fi(2, :).^2; ...
|
---|
509 | x_Fi(2, :).*x_Fi(3, :); ...
|
---|
510 | x_Fi(2, :).*x_Fi(4, :); ...
|
---|
511 | x_Fi(2, :).*log(x_Fi(5, :)); ...
|
---|
512 | x_Fi(2, :).*log(x_Fi(6, :)); ...
|
---|
513 | x_Fi(3, :).^2; ...
|
---|
514 | x_Fi(3, :).*x_Fi(4, :); ...
|
---|
515 | x_Fi(3, :).*log(x_Fi(5, :)); ...
|
---|
516 | x_Fi(3, :).*log(x_Fi(6, :)); ...
|
---|
517 | x_Fi(4, :).^2; ...
|
---|
518 | x_Fi(4, :).*log(x_Fi(5, :)); ...
|
---|
519 | x_Fi(4, :).*log(x_Fi(6, :)); ...
|
---|
520 | ];
|
---|
521 |
|
---|
522 | end
|
---|
523 |
|
---|
524 | function [val_Fi] = difFi(x_Fi)
|
---|
525 | val_Fi = [ ...
|
---|
526 | 0 0 0 0 0 0; ...1
|
---|
527 | 1 0 0 0 0 0; ...2
|
---|
528 | 0 1 0 0 0 0; ...3
|
---|
529 | 0 0 1 0 0 0; ...4
|
---|
530 | 0 0 0 1 0 0; ...5
|
---|
531 | 0 0 0 0 1/x_Fi(5) 0; ...6
|
---|
532 | 0 0 0 0 0 1/x_Fi(6); ...7
|
---|
533 | 2*x_Fi(1) 0 0 0 0 0; ...8
|
---|
534 | x_Fi(2) x_Fi(1) 0 0 0 0; ...9
|
---|
535 | x_Fi(3) 0 x_Fi(1) 0 0 0; ...10
|
---|
536 | x_Fi(4) 0 0 x_Fi(1) 0 0; ...11
|
---|
537 | log(x_Fi(5)) 0 0 0 x_Fi(1)/x_Fi(5) 0; ...12
|
---|
538 | log(x_Fi(6)) 0 0 0 0 x_Fi(1)/x_Fi(6); ...13
|
---|
539 | 0 2*x_Fi(2) 0 0 0 0; ...14
|
---|
540 | 0 x_Fi(3) x_Fi(2) 0 0 0; ...15
|
---|
541 | 0 x_Fi(4) 0 x_Fi(2) 0 0; ...16
|
---|
542 | 0 log(x_Fi(5)) 0 0 x_Fi(2)/x_Fi(5) 0; ...17
|
---|
543 | 0 log(x_Fi(6)) 0 0 0 x_Fi(2)/x_Fi(6); ...18
|
---|
544 | 0 0 2*x_Fi(3) 0 0 0; ...19
|
---|
545 | 0 0 x_Fi(4) x_Fi(3) 0 0; ...20
|
---|
546 | 0 0 log(x_Fi(5)) 0 x_Fi(3)/x_Fi(5) 0; ...21
|
---|
547 | 0 0 log(x_Fi(6)) 0 0 x_Fi(3)/x_Fi(6); ...22
|
---|
548 | 0 0 0 2*x_Fi(4) 0 0; ...23
|
---|
549 | 0 0 0 log(x_Fi(5)) x_Fi(4)/x_Fi(5) 0; ...24
|
---|
550 | 0 0 0 log(x_Fi(6)) 0 x_Fi(4)/x_Fi(6); ...25
|
---|
551 | ];
|
---|
552 | end
|
---|
553 |
|
---|
554 | function [valvt] = Vtilde_dx_dx(kin)
|
---|
555 | if(kin == K)
|
---|
556 | valvt = h_beldxdx;
|
---|
557 | else
|
---|
558 | valvt = Wv(8, kin)*diag([2 0 0 0]) +...
|
---|
559 | Wv(9, kin)*[0 1 0 0; 1 0 0 0; 0 0 0 0; 0 0 0 0] +...
|
---|
560 | Wv(10, kin)*[0 0 1 0; 0 0 0 0; 1 0 0 0; 0 0 0 0] +...
|
---|
561 | Wv(11, kin)*[0 0 0 1; 0 0 0 0; 0 0 0 0; 1 0 0 0] +...
|
---|
562 | Wv(14, kin)*diag([0 2 0 0]) +...
|
---|
563 | Wv(15, kin)*[0 0 0 0; 0 0 1 0; 0 1 0 0; 0 0 0 0] +...
|
---|
564 | Wv(16, kin)*[0 0 0 0; 0 0 0 1; 0 0 0 0; 0 1 0 0] +...
|
---|
565 | Wv(19, kin)*diag([0 2 0 0]) +...
|
---|
566 | Wv(20, kin)*[0 0 0 0; 0 0 0 0; 0 0 0 1; 0 0 1 0] +...
|
---|
567 | Wv(23, kin)*diag([0 2 0 0]);
|
---|
568 | end
|
---|
569 | end
|
---|
570 |
|
---|
571 | function [c, ceq, GC, GCeq] = Cond2(x)
|
---|
572 | c = x(1)*x(1) + x(2)*x(2) - cC1^2;
|
---|
573 | ceq = [];
|
---|
574 | GC = [2*x(1); 2*x(2)];
|
---|
575 | GCeq = [];
|
---|
576 | end
|
---|
577 |
|
---|
578 | function [x_ret] = fceG(x_in, u_in)
|
---|
579 | x_ret = zeros(4, 1);
|
---|
580 | x_ret(1) = Ca * x_in(1) + Cb * x_in(3) * sin(x_in(4)) + Cc * u_in(1);
|
---|
581 | x_ret(2) = Ca * x_in(2) - Cb * x_in(3) * cos(x_in(4)) + Cc * u_in(2);
|
---|
582 | x_ret(3) = Cd * x_in(3) + Ce * (x_in(2) * cos(x_in(4)) - x_in(1) * sin(x_in(4)));
|
---|
583 | x_ret(4) = x_in(4) + x_in(3) * DELTAt;
|
---|
584 | end
|
---|
585 |
|
---|
586 | function [y_ret] = fceH(x_in)
|
---|
587 | y_ret = zeros(2, 1);
|
---|
588 | y_ret(1) = x_in(1);
|
---|
589 | y_ret(2) = x_in(2);
|
---|
590 | end
|
---|
591 |
|
---|
592 | end
|
---|