Changeset 1182 for applications/pmsm

Show
Ignore:
Timestamp:
09/10/10 11:11:24 (14 years ago)
Author:
smidl
Message:

bug in sigma += Q(i) found

Location:
applications/pmsm/simulator_zdenek/ekf_example
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.cpp

    r1180 r1182  
    228228        const vec &u=cond; 
    229229        int dim = dimension(); 
    230          
     230        ///// !!!!!!!!!!!!!!!! 
    231231        U = est._R()._L().T(); 
    232232        D =  est._R()._D(); 
    233          
     233        if (false){ 
     234                mat L; 
     235                ivec tmp; 
     236                mat X=randn(5,5); 
     237                mat XX=X*X.T(); 
     238                mat T=diag(sqrt(1.0/diag(XX))); 
     239                XX= T*XX*T; 
     240                 
     241                ldmat ldd(XX); 
     242                U = ldd._L().T(); 
     243                D = ldd._D()*0.9; 
     244        } 
     245                 
    234246        //////////// 
    235247         
     
    246258        xref(3) = 3.141593; 
    247259        xref(4) = 34.0; 
     260         
     261        if (false){ 
     262                xref = ones(5); 
     263        } 
    248264         
    249265        imat Utf; 
     
    255271        mat_to_int(Utf,Uf);              
    256272        vec_to_int(Dtf, Df);  
     273 
     274//      cout << Dtf << endl; 
    257275         
    258276        // A*U == PSI*U 
     
    285303                        sigma2 += G(i,j)*G(i,j) * Q(j,j); 
    286304                }*/ 
    287                  
    288 /*              UDtof(U,D,Utf,Dtf,xref); 
     305                D(i) = sigma;  
     306                 
     307        /*      UDtof(U,D,Utf,Dtf,xref); 
    289308                cout << "d=sig"<<endl; 
    290                 cout << Utf << endl << Dtf << endl; 
    291                 cout << G << endl << Din << endl<<endl;*/ 
    292                  
    293                 D(i) = sigma;  
     309                cout << Dtf << endl; 
     310        */       
    294311                for (j=0;j<i;j++){  
    295312//                      cout << i << "," << j << endl; 
     
    316333                        } 
    317334                 
    318 /*                      cout << "end"<<endl; 
    319                         UDtof(U,D,Utf,Dtf,xref); 
    320                         cout << G << endl << Din << endl; 
    321                         cout << Utf << endl << Dtf << endl<<endl;*/ 
    322335                } 
     336                UDtof(U,D,Utf,Dtf,xref); 
     337                //      cout << G << endl << Din << endl; 
     338                imat Urw=Utf.T(); 
     339                cout << ivec(Urw._data(),25) << endl << Dtf << endl; 
    323340        } 
    324341 
     
    328345        mat_to_int(Qrnd,Qf); 
    329346 
     347//      cout << Df <<endl; 
    330348        thorton(Uf,Df,PSIU,Qf,Gf,Dfold,5); 
    331349         
    332         cout << "bierman double I" <<endl; 
     350/*      cout << "bierman double I" <<endl; 
    333351        UDtof(U,D,Utf,Dtf,xref); 
    334352        cout << "Uf: " << Utf << endl; 
    335353        cout << "Df: " << Dtf << endl; 
    336         cout << "xf:" << round_i(elem_div(_mu,xref)*(1<<15)) <<endl; 
     354        cout << "xf:" << round_i(elem_div(_mu,xref)*(1<<15)) <<endl;*/ 
    337355        mat_to_int(Utf,Uf);              
    338356        vec_to_int(Dtf, Df);  
     
    374392        } 
    375393 
    376 UDtof(U,D,Utf,Dtf,xref); 
    377 cout << "Uf: " << Utf << endl; 
    378 cout << "Df: " << Dtf << endl; 
    379 cout << "xf:" << round_i(elem_div(_mu,xref)*(1<<15)) <<endl; 
     394// UDtof(U,D,Utf,Dtf,xref); 
     395// cout << "Uf: " << Utf << endl; 
     396// cout << "Df: " << Dtf << endl; 
     397// cout << "xf:" << round_i(elem_div(_mu,xref)*(1<<15)) <<endl; 
    380398 
    381399        int difz[2]; 
     
    387405        //beirman(int *difz, int *xp, int *U, int *D, int *R, unsigned int dimy, unsigned int dimx  
    388406         
    389         cout <<endl<< "bierman fixed" <<endl; 
    390         for (i=0; i<25;i++) cout << Uf[i] << ","; cout <<endl; 
    391         for (i=0; i<5;i++) cout << Df[i] << ","; cout << endl; 
    392         for (i=0; i<5;i++) cout << xf[i] << ","; cout << endl; 
    393  
    394         for (i=0; i<2;i++) cout << difz[i] << ","; cout << endl; 
     407//      cout <<endl<< "bierman fixed" <<endl; 
     408//      for (i=0; i<25;i++) cout << Uf[i] << ","; cout <<endl; 
     409//      for (i=0; i<5;i++) cout << Df[i] << ","; cout << endl; 
     410//      for (i=0; i<5;i++) cout << xf[i] << ","; cout << endl; 
     411//  
     412//      for (i=0; i<2;i++) cout << difz[i] << ","; cout << endl; 
    395413 
    396414        int xf_old[5]; 
     
    399417         
    400418        UDtof(U,D,Utf,Dtf,xref); 
    401         for (i=0; i<25;i++) cout << Uf[i] << ","; cout <<endl; 
     419/*      for (i=0; i<25;i++) cout << Uf[i] << ","; cout <<endl; 
    402420        for (i=0; i<5;i++) cout << Df[i] << ","; cout << endl; 
    403421        for (i=0; i<5;i++) cout << xf[i] << ","; cout << endl; 
    404         cout << endl; 
     422        cout << endl;*/ 
    405423         
    406424         
  • applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.cpp

    r1180 r1182  
    4646}; 
    4747 
    48 void UDprt(int *U, int *D) { 
    49     return; 
    50     for (int i=0;i<5;i++) { 
    51         for (int j=0;j<5;j++) { 
    52             printf("%d,",U[i*5+j]); 
    53         } 
    54         printf("\n"); 
    55     } 
    56     for (int i=0;i<5;i++) { 
    57         printf("%d,",D[i]); 
    58     } 
     48bool DBG=true; 
     49 
     50void show(const char name[10], int *I, int n) { 
     51        if (!DBG) return; 
     52         
     53        printf("%s: ",name); 
     54    for (int i=0;i<n;i++) { 
     55                printf("%d ",*(I+i)); 
     56        } 
    5957    printf("\n"); 
    6058} 
     
    8280    // eye created 
    8381 
    84     long sigma; // in q15 
    85     for (i=rows-1; i>=0;i--) { // check i==0 at the END! 
     82    long sigma; // in q30!!!!!! 
     83    for (i=rows-1; true;i--) { // check i==0 at the END! 
    8684        sigma = 0; 
    8785                 
    8886        for (j=0;j<rows; j++) { 
    89             sigma += (((long)PSIU[i*rows+j]*PSIU[i*rows+j])>>15)*(Dold[i]); 
     87                        //long s1=(((long)PSIU[i+j*rows]*PSIU[i+j*rows])>>15)*(Dold[i]); 
     88                        long s2=(((long)PSIU[i*rows+j]*PSIU[i*rows+j])>>15)*(Dold[j]); 
     89//                      printf("%d - %d\n",s1,s2); 
     90                        sigma += s2; 
    9091                } 
    91                 sigma += Q[i*rows+i]; 
     92                sigma += Q[i*rows+i]<<15; 
    9293        for (j=i+1;j<rows; j++) { 
    9394            sigma += (((long)G[i*rows+j]*G[i*rows+j])>>13)*Q[j*rows+j]; 
     95//                      sigma += (((long)G[i+j*rows]*G[i+j*rows])>>13)*Q[j+j*rows]; 
    9496                } 
    9597                 
    9698        *(D+i)=sigma>>15; 
    9799        if (D[i]==0) D[i]=1; 
    98  
    99         /*              printf("d=sig\n"); 
    100                         UDprt(U,D); 
    101                         UDprt(G,Dold);*/ 
     100//show("D",D,5); 
    102101 
    103102        for (j=0;j<i;j++) { 
     
    116115            U[j*rows+i] = (int)z; 
    117116 
    118             /*                  printf("U=sig/D\n"); 
    119                                 UDprt(U,D); 
    120                                 UDprt(G,Dold);*/ 
    121117 
    122118            for (k=0;k<rows;k++) { 
     
    128124            } 
    129125                         
    130             /*                  printf("end\n"); 
    131                                 UDprt(U,D); 
    132                                 UDprt(G,Dold); 
    133                                 printf("\n");   */ 
    134         } 
    135         if (i==0) return; 
     126        } 
     127        //show("U",U,25); 
     128                //show("G",G,25); 
     129                if (i==0) return; 
    136130    } 
    137131}