Show
Ignore:
Timestamp:
09/02/10 23:21:43 (14 years ago)
Author:
smidl
Message:

fast versions of thorton and bierman

Files:
1 modified

Legend:

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

    r1174 r1179  
    443443        UI::get(log_level, set, "log_level", UI::optional); 
    444444} 
     445 
     446 
     447void EKFfixedUD::bayes(const itpp::vec& yt, const itpp::vec& ut) 
     448{ 
     449ekf(ut[0],ut[1],yt[0],yt[1]); 
     450} 
     451 
     452 
     453void EKFfixedUD::ekf(double ux, double uy, double isxd, double isyd) 
     454{ 
     455        // vypocet napeti v systemu (x,y) 
     456        int uf[2]; 
     457        uf[0]=prevod(ux/Uref,Qm); 
     458        uf[1]=prevod(uy/Uref,Qm); 
     459         
     460        int Y_mes[2]; 
     461        // zadani mereni 
     462        Y_mes[0]=prevod(isxd/Iref,Qm); 
     463        Y_mes[1]=prevod(isyd/Iref,Qm); 
     464         
     465        ////// vlastni rutina EKF -- ///////////////////////// 
     466        int t_sin,t_cos, tmp; 
     467         
     468        // implementace v PC 
     469        t_sin=prevod(sin(Thetaref*x_est[3]/32768.),15); 
     470        t_cos=prevod(cos(Thetaref*x_est[3]/32768.),15); 
     471         
     472        tmp=((long)cB*x_est[2])>>15; 
     473        x_est[0]=((long)cA*x_est[0]+(long)tmp*t_sin+(long)cC*uf[0])>>15; 
     474        x_est[1]=((long)cA*x_est[1]-(long)tmp*t_cos+(long)cC*uf[1])>>15; 
     475        x_est[2]=x_est[2]; 
     476        x_est[3]=(((long)x_est[3]<<15)+(long)cG*x_est[2])>>15; 
     477         
     478        //void EKFfixed::update_psi(void) 
     479        {                
     480                PSI[2]=((long)cB*t_sin)>>15; 
     481                tmp=((long)cH*x_est[2])>>15; 
     482                PSI[3]=((long)tmp*t_cos)>>15; 
     483                PSI[6]=-((long)cB*t_cos)>>15; 
     484                PSI[7]=((long)tmp*t_sin)>>15; 
     485        } 
     486         
     487        ///////// end of copy /////////////// 
     488        mmultAU(PSI,Uf,PSIU,4,4); 
     489        //thorton(int *U, int *D, int *PSIU, int *Q, int *G, int *Dold, unsigned int dimx); 
     490        thorton(Uf,Df,PSIU,Q,G,Dfold,4); 
     491         
     492        int difz[2]; 
     493        difz[0]=Y_mes[0]-x_est[0]; 
     494        difz[1]=Y_mes[1]-x_est[1]; 
     495        //bierman(int *difz, int *xp, int *U, int *D, int *R, unsigned int dimy, unsigned int dimx ); 
     496        int dR[2];dR[0]=R[0];dR[1]=R[3]; 
     497        bierman_fast(difz,x_est,Uf,Df,dR,2,4); 
     498         
     499        // navrat estimovanych hodnot regulatoru 
     500        vec& mu = E._mu(); 
     501        (mu)(0)=zprevod(x_est[0],Qm)*Iref; 
     502        (mu)(1)=zprevod(x_est[1],Qm)*Iref; 
     503        (mu)(2)=zprevod(x_est[2],Qm)*Wref; 
     504        (mu)(3)=zprevod(x_est[3],15)*Thetaref; 
     505         
     506//      mat T=diag(concat(vec_2(Iref,Iref), vec_2(Wref,Thetaref))); 
     507} 
     508 
     509void EKFfixedUD::init_ekf(double Tv) 
     510{ 
     511        // Tuning of matrix Q 
     512        Q[0]=prevod(.01,15);       // 0.05 
     513        Q[5]=Q[0]; 
     514        Q[10]=prevod(0.0001,15);      // 1e-3 
     515        Q[15]=prevod(0.0001,15);      // 1e-3 
     516 
     517        Uf[0]=0x7FFF;       // 0.05 
     518        Uf[5]=0x7FFF; 
     519        Uf[10]=0x7FFF;      // 1e-3 
     520        Uf[15]=0x7FFF;      // 1e-3 
     521         
     522        Df[0]=0x7FFF; 
     523        Df[1]=0x7FFF; 
     524        Df[2]=0x7FFF; 
     525        Df[3]=0x7FFF; 
     526         
     527        // Tuning of matrix R 
     528        R[0]=prevod(0.05,15);         // 0.05 
     529        R[3]=R[0]; 
     530         
     531        // Motor model parameters  
     532        cA=prevod(1-Tv*Rs/Ls,15); 
     533        cB=prevod(Tv*Wref*Fmag/Iref/Ls,15); 
     534        cC=prevod(Tv/Ls/Iref*Uref,15); 
     535        //  cD=prevod(1-Tv*Bf/J,15); 
     536        //  cE=prevod(kp*p*p*Tv*Fmag*Iref/J/Wref,15); 
     537        //  cF=prevod(p*Tv*Mref/J/Wref,15); 
     538        cG=prevod(Tv*Wref*4/Thetaref,15); 
     539        cH=prevod(Tv*Wref*Fmag/Iref/Ls*Thetaref,15); 
     540        //  cI=prevod(kp*p*p*Tv*Fmag*Iref/J/Wref*Thetaref); 
     541         
     542        /* Init matrix PSI with permanently constant terms */ 
     543        PSI[0]=cA; 
     544        PSI[5]=PSI[0]; 
     545        PSI[10]=0x7FFF; 
     546        PSI[14]=cG; 
     547        PSI[15]=0x7FFF; 
     548         
     549        //////////////////////// ================= 
     550        ///// TEST thorton vs. thorton_fast 
     551         
     552        int Ut[16]={0x7FFF, 100, 200, 300, 0, 0x7FFF, 500, 600, 0,0,0x7FFF, 800, 0,0,0, 0x7FFF}; 
     553        int Dt[4]={100,200,300,400}; 
     554        int PSIu[16] = {100, 200,300, 400 , 500, 600,700,800, 900,1000,1100,1200, 1300,1400,1500,1600}; 
     555        int Dold[4]; 
     556         
     557        thorton(Ut,Dt,PSIu,Q,G,Dold,4); 
     558        int Ut2[16]={0x7FFF, 100, 200, 300, 0, 0x7FFF, 500, 600, 0,0,0x7FFF, 800, 0,0,0, 0x7FFF}; 
     559        int Dt2[4]={100,200,300,400}; 
     560        int PSIu2[16] = {100, 200,300, 400 , 500, 600,700,800, 900,1000,1100,1200, 1300,1400,1500,1600}; 
     561        thorton_fast(Ut2,Dt2,PSIu2,Q,G,Dold,4); 
     562        cout<< Q<<endl; 
     563} 
     564