Changeset 1464 for applications

Show
Ignore:
Timestamp:
07/23/12 11:03:24 (12 years ago)
Author:
smidl
Message:

upravy choleskiho + nove qmath

Location:
applications/pmsm/simulator_zdenek/ekf_example
Files:
5 added
5 modified

Legend:

Unmodified
Added
Removed
  • applications/pmsm/simulator_zdenek/ekf_example/CMakeLists.txt

    r1440 r1464  
    66 
    77include_directories(../../bdm) 
    8 add_library (ekf_obj ekf_obj.cpp fixed.cpp matrix.cpp matrix_vs.cpp mpf_double.cpp) 
     8add_library (ekf_obj ekf_obj.cpp fixed.cpp matrix.cpp matrix_vs.cpp mpf_double.cpp ekf_mm.cpp qmath.cpp) 
  • applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.cpp

    r1439 r1464  
    10761076        int16 dR[2];dR[0]=R[0];dR[1]=R[3]; 
    10771077        //int16 xb[4]; xb[0]=x_est[0]<<2; xb[1]=x_est[1]<<2;  xb[2]=x_est[2]<<2;  xb[3]=x_est[3];   
    1078         carlson_fastC(difz,x_est,Chf,C,dR,2,2); 
     1078        int16 detS, rem; 
     1079        detS = 32767; rem=0; 
     1080        carlson_fastC(difz,x_est,Chf,C,dR,2,2, &detS, &rem); 
    10791081        //x_est[0] = xb[0]>>2; x_est[1]=xb[1]>>2; x_est[2]=xb[2]>>2; x_est[3]=xb[3]; 
    10801082         
     1083        log_level.store(logDet,vec_1((double)detS)); 
     1084        log_level.store(logRem,vec_1((double)rem)); 
     1085 
    10811086        // navrat estimovanych hodnot regulatoru 
    10821087        vec& mu = E._mu(); 
  • applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.h

    r1463 r1464  
    2323#include "mpf_double.h" 
    2424#include "fast_exp.h" 
     25#include "ekf_mm.h" 
     26#include "qmath.h" 
    2527 
    2628using namespace bdm; 
     
    413415class EKFfixedCh2 : public BM { 
    414416public: 
    415         LOG_LEVEL(EKFfixedCh2,logCh, logA, logC, logP); 
     417        LOG_LEVEL(EKFfixedCh2,logCh, logA, logC, logP, logDet, logRem); 
    416418         
    417419        void init_ekf2(double Tv); 
     
    470472                L.add_vector ( log_level, logC, RV ("C2", 4 ), prefix ); 
    471473                L.add_vector ( log_level, logP, RV ("P2", 4 ), prefix ); 
    472                  
    473         }; 
    474         //void from_setting(); 
     474                L.add_vector ( log_level, logDet, RV ("Det", 1 ), prefix ); 
     475                L.add_vector ( log_level, logRem, RV ("Rem", 1 ), prefix ); 
     476                 
     477        }; 
     478        void from_setting ( const Setting &set ){ 
     479                BM::from_setting(set); 
     480                vec dQ,dR; 
     481                UI::get ( dQ, set, "dQ", UI::optional ); 
     482                UI::get ( dQ, set, "dR", UI::optional ); 
     483                if (dQ.length()==2){ 
     484                        Q[0]=prevod(dQ[0],15);      // 1e-3 
     485                        Q[3]=prevod(dQ[1],15);      // 1e-3 
     486                } 
     487                if (dR.length()==2){ 
     488                        R[0]=prevod(dR[0],15);      // 1e-3 
     489                        R[3]=prevod(dR[1],15);      // 1e-3 
     490                } 
     491        } 
    475492}; 
    476493 
     
    711728 
    712729 
     730class ekfChfix: public BM{ 
     731         
     732        ekf_data E; 
     733public: 
     734        ekfChfix(){ 
     735                init_ekfCh2(&E,0.000125);set_dim(2);    dimc = 2; 
     736                dimy = 2; 
     737        }  
     738        void bayes ( const vec &val, const vec &cond ) { 
     739                int16 ux,uy; 
     740                ux=prevod(cond[0]/Uref,15); 
     741                uy=prevod(cond[1]/Uref,15); 
     742                 
     743                int16 yx,yy; 
     744                // zadani mereni 
     745                yx=prevod(val[0]/Iref,15); 
     746                yy=prevod(val[1]/Iref,15); 
     747                 
     748                int16 detS, rem; 
     749                ekfCh2(&E, ux,uy,yx,yy, &detS, &rem); 
     750                 
     751                Est._mu()=vec_2(E.x_est[0]*Uref/32768., E.x_est[1]*Uref/32768.); 
     752                 
     753                ll = -0.5*qlog(detS)-0.5*rem; 
     754        } 
     755        const epdf& posterior() const {return Est;}; 
     756        void from_setting ( const Setting &set ){ 
     757                BM::from_setting(set); 
     758                vec dQ,dR; 
     759                UI::get ( dQ, set, "dQ", UI::optional ); 
     760                UI::get ( dQ, set, "dR", UI::optional ); 
     761                if (dQ.length()==2){ 
     762                        E.Q[0]=prevod(dQ[0],15);      // 1e-3 
     763                        E.Q[3]=prevod(dQ[1],15);      // 1e-3 
     764                } 
     765                if (dR.length()==2){ 
     766                        E.dR[0]=prevod(dR[0],15);      // 1e-3 
     767                        E.dR[1]=prevod(dR[1],15);      // 1e-3 
     768                } 
     769        } 
     770         
     771        enorm<fsqmat> Est; 
     772        mat Ry; 
     773}; 
     774UIREGISTER(ekfChfix); 
     775 
    713776#endif // KF_H 
    714777 
  • applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.cpp

    r1340 r1464  
    663663} 
    664664 
    665 void carlson_fastC(int16 *difz, int16 *xp, int16 *Ch, int16 *C, int16 *R, unsigned int16 dimy, unsigned int16 dimx ) { 
     665void carlson_fastC(int16 *difz, int16 *xp, int16 *Ch, int16 *C, int16 *R, unsigned int16 dimy, unsigned int16 dimx, int16 *detS, int16 *rem ) { 
    666666        int16 alpha,beta,gamma; 
    667667        int16 delta, eta,epsilon,zeta,sigma,tau; 
     
    672672        int16 *Ch_ij, *w_i, *x_i, *C_yi; 
    673673         
    674          
     674        *detS = 32767; 
    675675        for (iy=0; iy<dimy; iy++) 
    676676        { 
     
    695695                        alpha=(tmp_long+(1<<14))>>15;                           // vyssi presnost 
    696696                                         
    697                         //            gamma= qsqrt(((long)alpha*beta));                          // verze pro DSP 
     697                        //gamma= qsqrt(((long)alpha*beta));                          // verze pro DSP 
    698698                        gamma= (int16)(sqrt((double)((int32)alpha*beta)));              // verze pro PC 
    699699                               // in q15 
     
    734734                        w_i++; 
    735735                } 
    736         } 
    737 } 
    738  
     736                 
     737                *detS = ((int32)*detS*alpha+(1<<14))>>8; 
     738                *rem += ((int32)delta*delta)/alpha; 
     739        } 
     740} 
     741 
  • applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.h

    r1340 r1464  
    5252extern void carlson(int16 *difz, int16 *xp, int16 *Ch, int16 *R, unsigned int16 dimy, unsigned int16 dimx ); 
    5353 
    54 /* perform Givens update of Ch matrix using PSI*Ch , Q, */ 
     54/* perform Givens update of Ch matrix using PSI*Ch and Q, */ 
    5555extern void givens_fast(int16 *Ch /*= int16 *PSICh*/, int16 *Q, unsigned int16 dimx); 
    5656 
    57 /* perform Carlson update of Ch matrix using difz, R and xp, for size dimx*/ 
     57/* perform Carlson update of Ch matrix using difz, R and xp, for size dimx, asuming identity matrix C*/ 
    5858extern void carlson_fast(int16 *difz, int16 *xp, int16 *Ch, int16 *R, unsigned int16 dimy, unsigned int16 dimx ); 
    5959 
    6060/* perform Carlson update of Ch matrix using difz, R and xp, for size dimx*/ 
    61 extern void carlson_fastC(int16 *difz, int16 *xp, int16 *Ch, int16 *C, int16 *R, unsigned int16 dimy, unsigned int16 dimx ); 
     61extern void carlson_fastC(int16* difz, int16* xp, int16* Ch, int16* C, int16* R, unsigned int16 dimy, unsigned int16 dimx, int16* detS, int16* rem );