Changeset 1245 for applications/pmsm/simulator_zdenek/test_UD.cpp
- Timestamp:
- 11/02/10 21:20:26 (14 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
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.