Changeset 1381 for applications/pmsm
- Timestamp:
- 08/02/11 16:02:37 (13 years ago)
- 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 1 1 add_executable (simulace fixed.cpp matrix.cpp pmsm_mod.cpp pwm.cpp regulace.cpp ekf.cpp simul.cpp ) 2 add_executable (simulmpf pmsm_mod.cpp pwm.cpp regulace.cpp mpf_double.cpp simulmpf.cpp ) 2 3 3 4 include_directories(../../bdm) -
applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.h
r1380 r1381 566 566 567 567 class MPF_pmsm_red:public BM{ 568 double qom, qth, r; 568 569 569 570 … … 572 573 dimy=2; 573 574 dimc=2; 574 mpf_init(1e-1, 1e-6, 1e-1); 575 qom=1e-1; 576 qth=1e-6; 577 r=1e-1; 575 578 }; 576 579 void bayes ( const vec &val, const vec &cond ) { … … 584 587 class mp:public epdf{ 585 588 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);} 588 591 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);} 591 594 }; 592 595 593 596 mp mypdf; 594 597 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 } 595 609 }; 596 610 UIREGISTER(MPF_pmsm_red); -
applications/pmsm/simulator_zdenek/ekf_example/mpf_double.cpp
r1380 r1381 213 213 214 214 } 215 void mpf_mean ( double Ecosth, double Esinth, doubleEome ) {216 int i; 217 Ecosth=0.0;218 Esinth=0.0;219 Eome=0.0;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; 220 220 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])); 224 224 } 225 225 -
applications/pmsm/simulator_zdenek/ekf_example/mpf_double.h
r1380 r1381 19 19 void mpf_bayes ( const double &isa, const double &isb , const double &usa, const double &usb ); 20 20 void mpf_init(double qom0, double qth0, double r0); 21 void mpf_mean(double Ecosth, double Esinth, doubleEome);21 void mpf_mean(double *Ecosth, double *Esinth, double *Eome); 22 22 void mpf_th(double th1[N]); -
applications/pmsm/simulator_zdenek/ekf_example/simul.cpp
r326 r1381 243 243 244 244 if (t>=t_sense) 245 if (print_counter>1 99)245 if (print_counter>125) 246 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 247 // 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 17 17 #include "pwm.h" 18 18 #include "regulace.h" 19 #include " ekf.h"19 #include "mpf_double.h" 20 20 21 21 #define Qm 13 … … 56 56 57 57 static double Isx, Isy; 58 static double Usx, Usy, ua, ub, Umk; 58 59 static double theta; 59 60 static double Uc_mer; … … 64 65 65 66 // EKF - vysledek estimace 66 static double ekf_estim[2]={0.,0.}; // w_est, theta_est 67 static double mpf_estim[2]={0.,0.}; // w_est, theta_est 68 static double Esinth, Ecosth; 67 69 68 70 FILE *fw; … … 113 115 init_pmsm(param, REL1); 114 116 init_regulace(param,h_reg); 115 init_ekf(h_reg,param);116 117 fw=fopen("data/graf 1.txt","w");117 mpf_init(1e0, 1e-5, 1e0);//VS: 118 119 fw=fopen("data/graf2.txt","w"); 118 120 119 121 Idwf=0.; … … 215 217 if (x[2]>1615) {x[2]=1615; if (k_rampa_tmp<24000) k_rampa_tmp++; else {k_rampa=-1;k_rampa_tmp=0;}} 216 218 if (x[2]<-1615) x[2]=-1615; /**/ 217 219 218 220 // 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); 220 230 221 231 // vystup z EKF zaveden do regulatoru … … 243 253 244 254 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, 248 257 // Fs_model, M_model, zatezny uhel (beta), zatezny uhel vypocteny z napeti (zbeta), Uc 249 258 print_counter=0;