- Timestamp:
- 04/23/09 13:19:04 (16 years ago)
- Location:
- pmsm
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
pmsm/pmsm.h
r283 r318 27 27 IMpmsm() :diffbifn ( ) {dimy=4; dimx = 4; dimu=2;}; 28 28 //! Set mechanical and electrical variables 29 v oid set_parameters ( double Rs0, double Ls0, double dt0, double Ypm0, double kp0, double p0, double J0, double Mz0 ) {Rs=Rs0; Ls=Ls0; dt=dt0; Ypm=Ypm0; kp=kp0; p=p0; J=J0; Mz=Mz0;}29 virtual void set_parameters ( double Rs0, double Ls0, double dt0, double Ypm0, double kp0, double p0, double J0, double Mz0 ) {Rs=Rs0; Ls=Ls0; dt=dt0; Ypm=Ypm0; kp=kp0; p=p0; J=J0; Mz=Mz0;} 30 30 31 31 vec eval ( const vec &x0, const vec &u0 ) { … … 77 77 78 78 //! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$ 79 class IMpmsm2o : public diffbifn{79 class IMpmsm2o : public IMpmsm { 80 80 protected: 81 double Rs, Ls, dt, Ypm, kp, p, J, Mz;81 // double Rs, Ls, dt, Ypm, kp, p, J, Mz; 82 82 //! store first derivatives for the use in second derivatives 83 83 double dia, dib, dom, dth; … … 86 86 double iam, ibm, omm, thm, uam, ubm; 87 87 public: 88 IMpmsm2o() : diffbifn () {dimy=4;dimx=4;dimu=2;};88 IMpmsm2o() :IMpmsm () {}; 89 89 //! Set mechanical and electrical variables 90 90 void set_parameters ( double Rs0, double Ls0, double dt0, double Ypm0, double kp0, double p0, double J0, double Mz0 ) {Rs=Rs0; Ls=Ls0; dt=dt0; Ypm=Ypm0; kp=kp0; p=p0; J=J0; Mz=Mz0; d2t=dt*dt/2;} … … 111 111 xk ( 1 ) = ibm + dt*dib;// +d2t*d2ib; 112 112 xk ( 2 ) = omm +dt*dom;// +d2t*d2om; 113 xk ( 3 ) = thm + dt*dth;// +d2t*d 2th; // <0..2pi>113 xk ( 3 ) = thm + dt*dth;// +d2t*dom; // <0..2pi> 114 114 115 115 if ( xk ( 3 ) >pi ) xk ( 3 )-=2*pi; … … 148 148 // d th 149 149 A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0; 150 // FOR d2t*dom!!!!!!!!! 151 /* A ( 3,0 ) = dt* kp*p*p * Ypm/J*dt* ( - sin ( thm ) ); 152 A ( 3,1 ) = dt* kp*p*p * Ypm/J*dt* ( cos ( thm ) ); 153 A ( 3,2 ) = dt; 154 A ( 3,3 ) = 1.0 + dt* kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) );*/ 150 155 } 151 156 -
pmsm/pmsmDS.h
r280 r318 12 12 13 13 #include <stat/loggers.h> 14 #include <estim/libKF.h> 14 15 #include "simulator.h" 15 16 #include "pmsm.h" … … 23 24 //! Setpoints of omega in timespans given by dt_prof 24 25 vec profileWw; 26 //! Setpoints of Mz in timespans given by dt_prof 27 vec profileMz; 25 28 //! time-step for profiles 26 29 double dt_prof; … … 29 32 //! options for logging, - log predictions of 'true' voltage 30 33 bool opt_modu; 34 //! options for logging, - 31 35 public: 32 36 //! Constructor with fixed sampling period … … 46 50 static double dW; // increase of W 47 51 static double Ww; // W 52 static double Mz; // W 48 53 if ( t>=dt_prof*ind ) { 49 54 ind++; 55 // check omega profile and set dW 50 56 if ( ind<profileWw.length() ) { 51 57 //linear increase … … 61 67 dW = 0; 62 68 } 69 // Check Mz profile and set Mz 70 if ( ind<profileMz.length() ) { 71 //sudden increase 72 Mz = profileMz(ind); 73 } 74 else { 75 Mz = 0; 76 } 63 77 } 64 78 Ww += dW; 65 79 //Simulate Dt seconds! 66 for ( int i=0;i<Dt;i++ ) { pmsmsim_step ( Ww );}80 for ( int i=0;i<Dt;i++ ) { pmsmsim_step ( Ww , Mz);} 67 81 }; 68 82 … … 100 114 L.logit ( L_optu , vec_2 ( ua,ub ) ); 101 115 } 116 102 117 } 103 118 104 void set_profile ( double dt, const vec &Ww ) {dt_prof=dt; profileWw=Ww;}119 void set_profile ( double dt, const vec &Ww, const vec &Mz ) {dt_prof=dt; profileWw=Ww; profileMz=Mz;} 105 120 }; 121 122 //! This class behaves like BM but it is evaluating EKF 123 class pmsmCRB : public EKFCh{ 124 protected: 125 vec interr; 126 vec old_true; 127 vec secder; 128 int L_CRB; 129 int L_err; 130 int L_sec; 131 public: 132 //! constructor 133 pmsmCRB():EKFCh(){old_true=zeros(6);} 134 135 void bayes(const vec &dt){ 136 //assume we know state exactly: 137 vec true_state=vec(x,4); // read from pmsm 138 est.set_mu(true_state); 139 140 //integration error 141 old_true(4)=KalmanObs[4]; 142 old_true(5)=KalmanObs[5];// add U 143 interr = (true_state - pfxu->eval(old_true)); 144 145 //second derivative 146 IMpmsm2o* pf = dynamic_cast<IMpmsm2o*>(pfxu); 147 if (pf) {secder=pf->eval2o(vec_2(KalmanObs[4],KalmanObs[5]));} 148 149 EKFCh::bayes(dt); 150 old_true.set_subvector(0,true_state); 151 } 152 153 void log_add(logger &L, const string &name="" ){ 154 L_CRB=L.add(rx,"crb"); 155 L_err=L.add(rx,"err"); 156 L_sec=L.add(rx,"d2"); 157 } 158 void logit(logger &L){ 159 L.logit(L_err, interr); 160 L.logit(L_CRB,diag(est._R().to_mat())); 161 L.logit(L_sec,secder); 162 } 163 }; -
pmsm/pmsm_estim.cpp
r281 r318 38 38 39 39 DS->log_add ( *L ); 40 ivec L_est(nE);40 string nic=""; 41 41 for (int i=0; i<nE; i++){ 42 L_est(i)= L->add ( Es(i)->posterior()._rv(), ""); // estimate42 Es(i)->log_add(*L,nic); // estimate 43 43 } 44 44 L->init(); … … 61 61 Es(i)->bayes ( Dls(i)->pushdown ( dt ) ); // update estimates 62 62 63 L->logit ( L_est(i), Es(i)->posterior().mean());63 Es(i)->logit (*L); 64 64 } 65 65 // Regulators -
pmsm/pmsm_ui.h
r280 r318 29 29 string var=S["variant"]; 30 30 if (var=="Stat"){tmp=new IMpmsmStat;} 31 if (var==" Mf"){tmp=new IMpmsmStat;}31 if (var=="2o"){tmp=new IMpmsm2o;} 32 32 } else { 33 33 tmp= new IMpmsm; … … 65 65 //Calling function tmp->tmp_set 66 66 UIcall<pmsmDS*> ( S["params"], &tmp_set , tmp ); 67 // 68 if ( S.exists ( "profile" ) ) { 69 tmp->set_profile ( S["tstep"],getvec ( S["profile"] ) ); 70 } 71 else { 72 tmp->set_profile ( 1.0, vec ( "1" ) ); 73 } 67 68 // Default values of profiles for omega and Mz 69 vec profW=vec("1.0"); 70 vec profM=vec("0.0"); 71 double tstep=1.0; 72 73 if ( S.exists ( "tstep" ) ) {tstep=S["tstep"];} 74 if ( S.exists ( "profileW" ) ) {profW=getvec ( S["profileW"] ) ;} 75 if ( S.exists ( "profileM" ) ) {profM=getvec ( S["profileM"] ) ;} 76 77 tmp->set_profile (tstep , profW, profM); 78 79 string opts=""; 80 if ( S.exists ( "options" ) ) {opts=(const char*)S["options"];} 81 tmp->set_options(opts); 82 74 83 return tmp; 75 84 }; … … 77 86 }; 78 87 UIREGISTER ( UIpmsmDS ); 88 89 class UIpmsmCRB: public UIbuilder { 90 public: 91 UIpmsmCRB():UIbuilder("pmsmCRB"){}; 92 bdmroot* build ( Setting &S ) const { 93 diffbifn* IM; UIbuild(S["IM"],IM); 94 diffbifn* OM; UIbuild(S["OM"],OM); 95 96 //parameters 97 pmsmCRB* E; E=new pmsmCRB; 98 E->set_parameters(IM, OM, diag(getvec(S["dQ"])), diag(getvec(S["dR"]))); 99 100 //statistics 101 int dim=IM->dimension(); 102 vec mu0; 103 mat P0; 104 if (S.exists("mu0")){mu0=getvec(S["mu0"]);}else{mu0=zeros(dim);}; 105 if (S.exists("P0")){mu0=getmat(S["P0"],dim);}else{P0=eye(dim);}; 106 E->set_statistics(mu0,P0); 107 108 //connect 109 RV* drv; UIbuild(S["drv"],drv); 110 E->set_drv(*drv); 111 RV* rv; UIbuild(S["rv"],rv); 112 E->set_rv(*rv); 113 return E; 114 } 115 }; 116 UIREGISTER ( UIpmsmCRB ); -
pmsm/simulator_zdenek/simulator.cpp
r278 r318 329 329 330 330 ////////////////////////////////////////////////////////////////////////////////////////////////////// 331 void pmsmsim_step(double Ww ) // you must link array KalmanObs[] to EKF modul331 void pmsmsim_step(double Ww, double Mz) // you must link array KalmanObs[] to EKF modul 332 332 { 333 333 double Umk, ub, uc; … … 338 338 // *us=KalmanObs[0]; *(us+1)=KalmanObs[1]; 339 339 // *us=ualfa; *(us+1)=ubeta; 340 //Mz 341 x[8]= Mz; 342 340 343 pmsm_model(5); 341 344 -
pmsm/simulator_zdenek/simulator.h
r278 r318 18 18 19 19 extern void pmsmsim_set_parameters(double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0); 20 extern void pmsmsim_step(double Ww );20 extern void pmsmsim_step(double Ww, double Mz=0.0); 21 21 extern void pmsmsim_noreg_step(double ua, double ub); 22 22