Changeset 1381 for applications

Show
Ignore:
Timestamp:
08/02/11 16:02:37 (13 years ago)
Author:
smidl
Message:

simulator

Location:
applications/pmsm/simulator_zdenek/ekf_example
Files:
5 modified
1 copied

Legend:

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

    r1380 r1381  
    11add_executable (simulace fixed.cpp matrix.cpp pmsm_mod.cpp pwm.cpp regulace.cpp ekf.cpp simul.cpp ) 
     2add_executable (simulmpf pmsm_mod.cpp pwm.cpp regulace.cpp mpf_double.cpp simulmpf.cpp ) 
    23 
    34include_directories(../../bdm) 
  • applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.h

    r1380 r1381  
    566566 
    567567class MPF_pmsm_red:public BM{ 
     568                double qom, qth, r; 
    568569 
    569570 
     
    572573                        dimy=2; 
    573574                        dimc=2; 
    574                         mpf_init(1e-1, 1e-6, 1e-1); 
     575                        qom=1e-1; 
     576                        qth=1e-6; 
     577                        r=1e-1; 
    575578                }; 
    576579        void bayes ( const vec &val, const vec &cond ) { 
     
    584587        class mp:public epdf{ 
    585588        public: 
    586                 mp():epdf(){set_dim(N);} 
    587                 vec sample() const {return zeros(N);} 
     589                mp():epdf(){set_dim(3);} 
     590                vec sample() const {return zeros(3);} 
    588591                double evallog(const vec &v) const {return 0.0;} 
    589                 vec mean() const {vec tmp(N); mpf_th(tmp._data()); return tmp;} 
    590                 vec variance() const {return zeros(N);} 
     592                vec mean() const {vec tmp(3); mpf_mean(tmp._data(), tmp._data()+1, tmp._data()+2); return tmp;} 
     593                vec variance() const {return zeros(3);} 
    591594        }; 
    592595         
    593596        mp mypdf; 
    594597        const mp& posterior() const {return mypdf;} 
     598         
     599        void from_setting(const Setting &set){ 
     600                BM::from_setting(set); 
     601                UI::get(qom,set,"qom",UI::optional); 
     602                UI::get(qth,set,"qth",UI::optional); 
     603                UI::get(r,set,"r",UI::optional); 
     604        } 
     605        void validate(){ 
     606                mpf_init(qom,qth,r); 
     607                 
     608        } 
    595609}; 
    596610UIREGISTER(MPF_pmsm_red); 
  • applications/pmsm/simulator_zdenek/ekf_example/mpf_double.cpp

    r1380 r1381  
    213213 
    214214} 
    215 void mpf_mean ( double Ecosth, double Esinth, double Eome ) { 
    216         int i; 
    217         Ecosth=0.0; 
    218         Esinth=0.0; 
    219         Eome=0.0; 
     215void mpf_mean ( double *Ecosth, double *Esinth, double *Eome ) { 
     216        int i; 
     217        *Ecosth=0.0; 
     218        *Esinth=0.0; 
     219        *Eome=0.0; 
    220220        for ( i=0;i<N;i++ ) { 
    221                 Ecosth+=w[i]*cth[i]; 
    222                 Esinth+=w[i]*sth[i]; 
    223                 Eome+=w[i]*om[i]; 
     221                *Ecosth+=(w[i]*(cth[i])); 
     222                *Esinth+=(w[i]*(sth[i])); 
     223                *Eome+=(w[i]*(om[i])); 
    224224        } 
    225225 
  • applications/pmsm/simulator_zdenek/ekf_example/mpf_double.h

    r1380 r1381  
    1919void mpf_bayes ( const double &isa, const double &isb , const double &usa, const double &usb ); 
    2020void mpf_init(double qom0, double qth0, double r0); 
    21 void mpf_mean(double Ecosth, double Esinth, double Eome); 
     21void mpf_mean(double *Ecosth, double *Esinth, double *Eome); 
    2222void mpf_th(double th1[N]); 
  • applications/pmsm/simulator_zdenek/ekf_example/simul.cpp

    r326 r1381  
    243243 
    244244    if (t>=t_sense) 
    245       if (print_counter>199) 
     245      if (print_counter>125) 
    246246      { fprintf(fw,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \n",t,x[0],x[1],x[6],*ladeni_regulace,x[7],*(ladeni_regulace+2),x[4],x[5],x[3],x[2],Ww,*(ladeni_regulace+1),Urm_max,*(ladeni_regulace+4),*(ladeni_regulace+5),x[10],*(ladeni_regulace+6),Uc, *(ladeni_regulace+7),ladeni_pila,ladeni_ur,*(ladeni_regulace+8),*(ladeni_regulace+9),ekf_estim[0],ekf_estim[1]); 
    247247      // t, Isx, Isy, Isd, Isdw, Isq, Isqw, M, Fs, poloha, rychlost, rychlost_w, Urm, Urm_max, 
  • applications/pmsm/simulator_zdenek/ekf_example/simulmpf.cpp

    r326 r1381  
    1717#include "pwm.h" 
    1818#include "regulace.h" 
    19 #include "ekf.h" 
     19#include "mpf_double.h" 
    2020 
    2121#define Qm      13 
     
    5656 
    5757static double Isx, Isy; 
     58static double Usx, Usy, ua, ub, Umk; 
    5859static double theta; 
    5960static double Uc_mer; 
     
    6465 
    6566// EKF - vysledek estimace 
    66 static double ekf_estim[2]={0.,0.};     // w_est, theta_est 
     67static double mpf_estim[2]={0.,0.};     // w_est, theta_est 
     68static double Esinth, Ecosth; 
    6769 
    6870FILE *fw; 
     
    113115  init_pmsm(param, REL1); 
    114116  init_regulace(param,h_reg); 
    115   init_ekf(h_reg,param); 
    116  
    117   fw=fopen("data/graf1.txt","w"); 
     117  mpf_init(1e0, 1e-5, 1e0);//VS: 
     118 
     119  fw=fopen("data/graf2.txt","w"); 
    118120 
    119121  Idwf=0.; 
     
    215217                if (x[2]>1615) {x[2]=1615; if (k_rampa_tmp<24000) k_rampa_tmp++; else {k_rampa=-1;k_rampa_tmp=0;}} 
    216218                if (x[2]<-1615) x[2]=-1615;  /**/ 
    217  
     219                         
    218220                // KALMAN 
    219                 ekf(ekf_estim,*u,*(u+1),Ucn,Uc_mer,Isx,Isy); 
     221               Umk=*u*Uc/Ucn; 
     222      ua=Umk*cos(*(u+1)); 
     223      ub=Umk*cos(*(u+1)-2./3.*M_PI); 
     224      Usx=ua;                     // usx 
     225      Usy=(ua+2.*ub)/sqrt(3.);    // usy 
     226        
     227                mpf_bayes(Isx,Isy,Usx,Usy); 
     228                mpf_mean(&Esinth,&Ecosth,&mpf_estim[0]); 
     229                mpf_estim[1]=atan(Esinth/Ecosth); 
    220230 
    221231                // vystup z EKF zaveden do regulatoru 
     
    243253 
    244254    if (t>=t_sense) 
    245       if (print_counter>199) 
    246       { fprintf(fw,"%f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f \n",t,x[0],x[1],x[6],*ladeni_regulace,x[7],*(ladeni_regulace+2),x[4],x[5],x[3],x[2],Ww,*(ladeni_regulace+1),Urm_max,*(ladeni_regulace+4),*(ladeni_regulace+5),x[10],*(ladeni_regulace+6),Uc, *(ladeni_regulace+7),ladeni_pila,ladeni_ur,*(ladeni_regulace+8),*(ladeni_regulace+9),ekf_estim[0],ekf_estim[1]); 
    247       // t, Isx, Isy, Isd, Isdw, Isq, Isqw, M, Fs, poloha, rychlost, rychlost_w, Urm, Urm_max, 
     255      if (print_counter>125)//sampling period 
     256      { fprintf(fw,"%f %f %f %f %f %f %f \n", t,x[0],x[1],Usx,Usy,mpf_estim[0],mpf_estim[1]); // t, Isx, Isy, Isd, Isdw, Isq, Isqw, M, Fs, poloha, rychlost, rychlost_w, Urm, Urm_max, 
    248257      // Fs_model, M_model, zatezny uhel (beta), zatezny uhel vypocteny z napeti (zbeta), Uc 
    249258        print_counter=0;