- Timestamp:
- 12/18/08 20:36:13 (16 years ago)
- Location:
- pmsm
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pmsm/pmsm_sim.cpp
r215 r218 18 18 #include "pmsm.h" 19 19 #include "simulator.h" 20 #include "sim_profiles.h" 20 21 21 22 using namespace itpp; … … 35 36 int main() { 36 37 // Kalman filter 37 int Ndat = 30000;38 int Ndat = 9000; 38 39 double h = 1e-6; 39 40 int Nsimstep = 125; 40 int Npart = 1;41 int Npart = 200; 41 42 42 43 // internal model 43 44 IMpmsm fxu; 44 // Rs Ls dt Fmag(Ypm) kp p J Bf(Mz)45 fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989, 45 // Rs Ls dt Fmag(Ypm) kp p J Bf(Mz) 46 fxu.set_parameters ( 0.28, 0.003465, Nsimstep*h, 0.1989, 1.5 ,4.0, 0.04, 0.0 ); 46 47 // observation model 47 48 OMpmsm hxu; 48 49 49 50 vec mu0= "0.0 0.0 0.0 0.0"; 50 vec Qdiag ( "0.0 1 0.01 0.00001 0.00001" ); //zdenek: 0.01 0.01 0.0001 0.000151 vec Rdiag ( " 0.0005 0.0005" ); //var(diff(xth)) = "0.034 0.034"51 vec Qdiag ( "0.001 0.001 1e-6 1e-10" ); //zdenek: 0.01 0.01 0.0001 0.0001 52 vec Rdiag ( "1e-10 1e-10" ); //var(diff(xth)) = "0.034 0.034" 52 53 chmat Q ( Qdiag ); 53 54 chmat R ( Rdiag ); … … 59 60 EKF_unQ KFEp ( rx,ry,ru,rQ ); 60 61 KFEp.set_parameters ( &fxu,&hxu,Q,R ); 61 KFEp.set_est ( mu0, chmat ( 1*ones ( 4 ) ) );62 KFEp.set_est ( mu0, chmat ( zeros ( 4 ) ) ); 62 63 63 64 mgamma evolQ ( rQ,rQ ); 64 65 MPF<EKF_unQ> M ( rx,rQ,evolQ,evolQ,Npart,KFEp ); 65 66 // initialize 66 evolQ.set_parameters ( 10 0.0 ); //sigma = 1/10 mu67 evolQ.set_parameters ( 10.0 ); //sigma = 1/10 mu 67 68 evolQ.condition ( "0.01 0.01" ); //Zdenek default 68 69 epdf& pfinit=evolQ._epdf(); 69 70 M.set_est ( pfinit ); 70 evolQ.set_parameters ( 10 00.0 );71 evolQ.set_parameters ( 10.0 ); 71 72 72 73 // … … 78 79 mat Dt=zeros ( Ndat,4+2 ); //observation 79 80 mat XtE=zeros ( Ndat, 4 ); 80 mat XtM=zeros ( Ndat, 6); //Q + x81 mat XtM=zeros ( Ndat,2+4 ); //Q + x 81 82 82 83 // SET SIMULATOR … … 87 88 vec dt ( 2 ); 88 89 vec ut ( 2 ); 90 vec vecW="0.1 0.2 0.4 0.9 0.4 0.2 0.0 -0.4 -0.9 -1.6 -0.4 0.0 0.0"; 89 91 90 92 for ( int tK=1;tK<Ndat;tK++ ) { … … 92 94 for ( int ii=0; ii<Nsimstep;ii++ ) { 93 95 //simulator 94 Ww+=k_rampa*2.*M_PI*2e-4; //1000Hz/s 95 if ( Ww>2.*M_PI*150. ) { 96 Ww=2.*M_PI*150.; 97 if ( k_rampa_tmp<500000 ) k_rampa_tmp++; 98 else {k_rampa=-1;k_rampa_tmp=0;} 99 }; 100 if ( Ww<-2.*M_PI*150. ) Ww=-2.*M_PI*150.; /* */ 101 96 sim_profile_vec01t(Ww,vecW); 102 97 pmsmsim_step ( Ww ); 103 98 }; 104 99 // collect data 105 ut ( 0 ) = KalmanObs[0];106 ut ( 1 ) = KalmanObs[1];100 ut ( 0 ) = 0.0;//KalmanObs[0]; 101 ut ( 1 ) = 0.0;//KalmanObs[1]; 107 102 dt ( 0 ) = KalmanObs[2]; 108 103 dt ( 1 ) = KalmanObs[3]; -
pmsm/sim.cpp
r217 r218 28 28 double h = 1e-6; 29 29 int Nsimstep = 125; 30 int Npart = 50;31 30 32 dirfilelog L("exp/ pmsm_sim2",Ndat);31 dirfilelog L("exp/sim",Ndat); 33 32 34 33 // internal model … … 55 54 int U_log = L.add(ru,"U"); 56 55 int U2_log = L.add(ru,"U2"); 57 int R_log = L.add(RV("{_ }","4"),"R"); 56 int R_log = L.add(RV("{_ }","16"),"R"); 57 int Ww_log = L.add(RV("{_ }","1"),"W"); 58 int R2_log = L.add(RV("{_ }","16"),"R2"); 58 59 // int O_log = L.add(RV("{_ }","16"),"O"); 59 60 L.init(); … … 61 62 // SET SIMULATOR 62 63 //pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 3e-6, h ); 63 pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 0.0*3e-6, h );64 pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 6e-6, h ); 64 65 double Ww=0.0; 65 66 vec dt ( 2 ); … … 72 73 vec u=zeros(2); 73 74 vec u2=zeros(2); 74 ldmat R(eye(4),0.001*ones(4)); 75 mat Ch=zeros(4,4); 76 fsqmat eCh(4); 75 ldmat R0(eye(4),1e-6*ones(4)); 76 ldmat R(R0); 77 ldmat R2(R0); 78 79 double frg=0.9; 80 vec vecW="0. 0. 0.2 0.4 0.4 0.2 0.0 -0.4 -0.6 -0.6 -0.4 0.0 0.0"; 77 81 for ( int tK=1;tK<Ndat;tK++ ) { 78 82 //Number of steps of a simulator for one step of Kalman … … 80 84 //simulator 81 85 //sim_profile_steps1(Ww); 82 sim_profile_ 2slowrevs(Ww);86 sim_profile_vec01t(Ww,vecW); 83 87 pmsmsim_step ( Ww ); 84 88 }; … … 92 96 // Try what our model would predict! 93 97 xp=fxu.eval(xm,u); 94 xp2=fxu.eval(xm, u2);95 xp3=fxu.eval(xm,u2);98 xp2=fxu.eval(xm,zeros(2)); //ZERO input!!!!!!!! 99 // xp3=fxu.eval(xm,u2); 96 100 97 101 // KFE.bayes(concat(dt,u)); … … 99 103 xt=vec(x,4); //vec from C-array 100 104 //Covariance 101 R*=0.7; 102 R.opupdt(xt-xp2,1.0); 103 Ch = diag(sqrt(R._D()))*R._L(); 104 //eCh = KFE._e()->_R(); 105 eCh = KFE._R(); 105 R*=frg; 106 R.add(R0,1-frg); 107 R.opupdt(xt-xp,1.0); 108 R2*=frg; 109 R2.add(R0,1-frg); 110 R2.opupdt(xt-xp2,1.0); 106 111 xm = xt; 107 112 L.logit(X_log, xt ); … … 110 115 L.logit(U_log, u ); 111 116 L.logit(U2_log, u2 ); 112 L.logit(R_log, diag(Ch.T()*Ch) ); //3.33=1/(1-0.7) 113 L.logit(V_log, diag(eCh.to_mat()) ); //3.33=1/(1-0.7) 117 L.logit(Ww_log, vec_1(Ww)); 118 L.logit(R_log, vec(R.to_mat()._data(), 16 )); //3.33=1/(1-0.7) 119 L.logit(R2_log, vec(R2.to_mat()._data(), 16 )); 114 120 // L.logit(E_log, KFE._e()->mean() ); 115 121 // L.logit(O_log, vec(iCh._data(),16)); //3.33=1/(1-0.7) … … 121 127 122 128 L.finalize(); 123 L.itsave(" xxx.it");129 L.itsave("sim.it"); 124 130 return 0; 125 131 } -
pmsm/sim_profiles.h
r217 r218 65 65 66 66 void sim_profile_2slowrevs(double &Ww,bool load=false) { 67 static int k_rampa=1 0;67 static int k_rampa=1; 68 68 69 69 if ((t>0.2)&&(t<0.8)) { … … 76 76 if (!load) x[8]=0.0; 77 77 } 78 79 void sim_profile_vec01t(double &Ww, vec &vecWw){ 80 static int ind=0; 81 static double dW; 82 double tn=t; 83 if (t>0.1*ind) { 84 ind++; 85 dW = vecWw(ind)-vecWw(ind-1); 86 } 87 Ww=vecWw(ind-1)+(t-0.1*(ind-1))*dW/0.1; 88 } -
pmsm/simulator_zdenek/simulator.cpp
r216 r218 113 113 // === init of particular modules of simulator === 114 114 // PWM init 115 smer=1; smer2=1; 115 smer=-1; smer2=-1; 116 citac=0; 117 citac2=abs(0-(int)(DT/h)); //VS: oprava, je to spravne? 116 118 citac_PR=h_reg_counter_mez; 117 citac=citac_PR; 118 citac2=abs(citac_PR-(int)(DT/h)); //VS: oprava, je to spravne? 119 119 120 120 // first interrupt occur after first period match => add 1 to both counter registers 121 //citac++;smer=1;122 //citac2--;121 citac++;smer=1; 122 citac2--; 123 123 124 124 modulace=1; // THIPWM … … 173 173 174 174 for (i=0;i<3;i++) 175 { dtr[i]=ubytek(fabs(iabc[i]) *0.); //VS175 { dtr[i]=ubytek(fabs(iabc[i])); 176 176 dd[i]=dtr[i]*.73; 177 177 }