Changeset 1245 for applications/pmsm/simulator_zdenek
- Timestamp:
- 11/02/10 21:20:26 (14 years ago)
- Location:
- applications/pmsm/simulator_zdenek
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.cpp
r1241 r1245 661 661 662 662 // Tuning of matrix R 663 R[0]=prevod(0. 05,15); // 0.05663 R[0]=prevod(0.1,15); // 0.05 664 664 R[3]=R[0]; 665 665 -
applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.cpp
r1241 r1245 114 114 } 115 115 116 116 // Thorton procedure - Kalman predictive variance in UD 117 void thorton(int16 *U, int16 *D, int16 *PSIU, int16 *Q, int16 *G, int16 *Dold, unsigned int16 rows) { 118 thorton_fast(U, D, PSIU, Q, G, Dold, rows); 119 } 120 117 121 // Thorton procedure - Kalman predictive variance in UD 118 122 void thorton_fast(int16 *U, int16 *D, int16 *PSIU, int16 *Q, int16 *G, int16 *Dold, unsigned int16 rows) { … … 284 288 285 289 sigma = sigma >> 15; // navrat do Q15 286 if (sigma>32767)sigma=32767;290 // if (sigma>32767)sigma=32767; 287 291 288 292 for (j=0;j<dimx;j++) … … 393 397 } 394 398 } 395 } 396 for (j=0; j<i; j++){ 397 tmp_long=(long(Ch[i*dimx+i])*Ch[i*dimx+i]+long(Ch[i*dimx+j])*Ch[i*dimx+j]); 398 if (tmp_long>0){ 399 rho=sqrt((double)(tmp_long)); 400 s=(long(Ch[i*dimx+j])<<15)/rho; 401 c=(long(Ch[i*dimx+i])<<15)/rho; 402 for (k=0; k<=i; k++){ 403 tau=(long(c)*Ch[k*dimx+j]-long(s)*Ch[k*dimx+i])>>15; 404 Ch[k*dimx+i]=(long(s)*Ch[k*dimx+j]+long(c)*Ch[k*dimx+i])>>15; 405 Ch[k*dimx+j]=tau; 399 400 for (j=0; j<i; j++){ 401 tmp_long=(long(Ch[i*dimx+i])*Ch[i*dimx+i]+long(Ch[i*dimx+j])*Ch[i*dimx+j]); 402 if (tmp_long>0){ 403 rho=sqrt((double)(tmp_long)); 404 s=(long(Ch[i*dimx+j])<<15)/rho; 405 c=(long(Ch[i*dimx+i])<<15)/rho; 406 for (k=0; k<=i; k++){ 407 tau=(long(c)*Ch[k*dimx+j]-long(s)*Ch[k*dimx+i])>>15; 408 Ch[k*dimx+i]=(long(s)*Ch[k*dimx+j]+long(c)*Ch[k*dimx+i])>>15; 409 Ch[k*dimx+j]=tau; 410 } 406 411 } 407 412 } 413 408 414 } 409 415 } -
applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.h
r1241 r1245 13 13 #define qAU 14 14 14 #define qD 14 15 #define qCh 1 515 #define qCh 14 16 16 17 #define int16 shortint18 #define int32 int17 #define int16 int 18 #define int32 long 19 19 20 20 /* Matrix multiply Full matrix by upper diagonal matrix with unit diagonal; */ -
applications/pmsm/simulator_zdenek/test_UD.cpp
r1228 r1245 2 2 #include "ekf_example/ekf_obj.h" 3 3 int main(){ 4 int i;4 int16 i; 5 5 mat A = 0.99*eye(5); 6 6 A(0.3) = 0.06; … … 13 13 14 14 mat U=eye(5); 15 for (int i=0; i<5;i++) {16 for (int j=i+1; j<5;j++) U(i,j)=2*randu(1)(0)-1;15 for (int16 i=0; i<5;i++) { 16 for (int16 j=i+1; j<5;j++) U(i,j)=2*randu(1)(0)-1; 17 17 } 18 18 mat Q = diag(vec(" 0.2000 0.3000 0.4000 0.5000 0.6")); … … 22 22 vec xref = ones(5); 23 23 24 int PSI[25];25 int PSIU[25]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};26 int Uf[25]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};27 int Gf[25]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0};28 int Df[5]={0,0,0,0,0};29 int Dfold[5]={0,0,0,0,0};24 int16 PSI[25]; 25 int16 PSIU[25]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0}; 26 int16 Uf[25]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0}; 27 int16 Gf[25]={0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0, 0,0,0,0,0}; 28 int16 Df[5]={0,0,0,0,0}; 29 int16 Dfold[5]={0,0,0,0,0}; 30 30 31 int multip=1<<15;31 int16 multip=1<<15; 32 32 33 33 /////////// COPY 34 34 imat Af=round_i(A*multip); 35 mat_to_int (Af, PSI);36 mat_to_int (round_i(U*multip),Uf);37 vec_to_int (round_i(D*multip), Df);38 int Qf[25];39 mat_to_int (round_i(Q*multip), Qf);40 int Rf[2];41 vec_to_int (round_i(R*multip), Rf);35 mat_to_int16(Af, PSI); 36 mat_to_int16(round_i(U*multip),Uf); 37 vec_to_int16(round_i(D*multip), Df); 38 int16 Qf[25]; 39 mat_to_int16(round_i(Q*multip), Qf); 40 int16 Rf[2]; 41 vec_to_int16(round_i(R*multip), Rf); 42 42 43 43 … … 52 52 cout << "Delta PSI: " << round_i(PhiU*multip-(1<<(15-qAU))*PUcmp) <<endl; 53 53 54 mat_to_int (round_i(PhiU*multip/(1<<(15-qAU))),PSIU); //<< make is same54 mat_to_int16(round_i(PhiU*multip/(1<<(15-qAU))),PSIU); //<< make is same 55 55 56 56 /////////// Test Thorton: 57 int dim=5;double sigma; intj,k;57 int16 dim=5;double sigma; int16 j,k; 58 58 vec Din = D; 59 59 mat G=eye(5); … … 102 102 103 103 // synchronize 104 mat_to_int (round_i(U*multip),Uf);105 vec_to_int (round_i(D*multip), Df);104 mat_to_int16(round_i(U*multip),Uf); 105 vec_to_int16(round_i(D*multip), Df); 106 106 107 107 … … 109 109 vec xp = 2*randu(5)-1; 110 110 111 int difz[2];112 vec_to_int (round_i(ydif*multip), difz);113 int xf[5];114 vec_to_int (round_i(xp*multip), xf);111 int16 difz[2]; 112 vec_to_int16(round_i(ydif*multip), difz); 113 int16 xf[5]; 114 vec_to_int16(round_i(xp*multip), xf); 115 115 116 116 cout << "x: "<< round_i(xp*multip) <<endl; … … 118 118 119 119 120 int xf_old[5];121 vec_to_int (ivec(xf,5),xf_old);120 int16 xf_old[5]; 121 vec_to_int16(ivec(xf,5),xf_old); 122 122 123 123 /////// Test bierman … … 127 127 mat C = zeros(2,5); 128 128 C(0,0)=1.0;C(1,1)=1.0; 129 for (int iy=0; iy<2; iy++){129 for (int16 iy=0; iy<2; iy++){ 130 130 a = U.T()*C.get_row(iy); // a is not modified, but 131 131 b = elem_mult(D,a); // b is modified to become unscaled Kalman gain.