Changeset 240
- Timestamp:
- 01/22/09 19:43:11 (16 years ago)
- Location:
- pmsm
- Files:
-
- 4 modified
Legend:
- Unmodified
- Added
- Removed
-
pmsm/mpf_u_delta.cpp
r232 r240 63 63 xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ( ubm+ud ( 1 ) ) *dt/Ls; 64 64 //om 65 xk ( 2 ) = omm + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz;65 xk ( 2 ) = omm;// + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz; 66 66 //th 67 67 xk ( 3 ) = thm + omm*dt; // <0..2pi> … … 93 93 94 94 vec mu0= "0.0 0.0 0.0 0.0"; 95 vec Qdiag ( "0.4 0.4 0. 001 0.000001" ); //zdenek: 0.01 0.01 0.0001 0.000195 vec Qdiag ( "0.4 0.4 0.1 0.000001" ); //zdenek: 0.01 0.01 0.0001 0.0001 96 96 vec Rdiag ( "0.1 0.1" ); //var(diff(xth)) = "0.034 0.034" 97 97 chmat Q ( Qdiag ); 98 98 mat Q2o=diag(Qdiag); 99 99 chmat R ( Rdiag ); 100 EKFCh KFE ( rx,ry,r U);100 EKFCh KFE ( rx,ry,ru ); 101 101 KFE.set_parameters ( &fxu0,&hxu,Q,R ); 102 102 KFE.set_est ( mu0, chmat ( ones ( 4 ) ) ); … … 111 111 MPF<EKFCh_du_kQ> M ( rx,rUd,evolUd,evolUd,Npart,KFEp ); 112 112 // initialize 113 vec Ud0="0 0 1 00.0";114 evolUd.set_parameters ( eye ( 3 ), zeros(3), ldmat ( vec( "1 1 10" )));113 vec Ud0="0 0 1.0"; 114 evolUd.set_parameters ( eye ( 3 ), zeros(3), ldmat ( vec( "1e-4 1e-4 10e-4" ))); 115 115 evolUd.condition ( Ud0 ); 116 116 epdf& pfinit=evolUd._epdf(); 117 117 M.set_est ( pfinit ); 118 evolUd.set_parameters ( eye ( 3 ), zeros(3), ldmat ( vec(" 9e-8 9e-8 9e-7" )));118 evolUd.set_parameters ( eye ( 3 ), zeros(3), ldmat ( vec(" 5e-4 5e-4 1e-8" ))); 119 119 120 120 mat Xt=zeros ( Ndat ,4 ); //true state from simulator … … 128 128 pmsmsim_set_parameters ( 0.28,0.003465,0.1989,0.0,4,1.5,0.04, 200., 3e-6, h ); 129 129 vec dt ( 2 ); 130 vec ut ( 4);131 vec utm ( 4);130 vec ut ( 2 ); 131 vec utm ( 2 ); 132 132 vec xt ( 4 ); 133 133 vec xtm=zeros ( 4 ); … … 145 145 ut ( 0 ) = KalmanObs[0]; 146 146 ut ( 1 ) = KalmanObs[1]; 147 ut ( 2 ) = utm(0)-ut(0);148 ut ( 3 ) = utm(1)-ut(1);149 147 dt ( 0 ) = KalmanObs[2]+0.3*Rnoise ( 0,t ); 150 148 dt ( 1 ) = KalmanObs[3]+0.3*Rnoise ( 1,t ); 151 149 xt = vec ( x,4 ); 152 150 151 vec x2o = fxu0.eval2o(utm-ut); 153 152 utm =ut; 154 153 155 Q2o*=0.9 ;156 Q2o+=outer_product(x2o _dbg,x2o_dbg);154 Q2o*=0.99; 155 Q2o+=outer_product(x2o,x2o); 157 156 //estimator 158 157 KFE.bayes ( concat ( dt,ut ) ); 159 for (int ii=0; ii<Npart; ii++){dynamic_cast<EKFCh_du_kQ*>(M._BM(ii))->set_ref(chmat( Q2o));}158 for (int ii=0; ii<Npart; ii++){dynamic_cast<EKFCh_du_kQ*>(M._BM(ii))->set_ref(chmat(elem_mult(Qdiag,Qdiag)));} 160 159 M.bayes ( concat ( dt,ut ) ); 161 160 -
pmsm/pmsm.h
r232 r240 12 12 RV ru ( "{ua ub }"); 13 13 RV ry ( "{oia oib }"); 14 RV rU = concat(ru, RV("{dua dub }"));15 14 16 15 // class uipmsm : public uibase{ 17 16 // double Rs, Ls, dt, Ypm, kp, p, J, Mz; 18 17 // }; 19 20 vec x2o_dbg(4);21 18 22 19 //! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$ … … 81 78 protected: 82 79 double Rs, Ls, dt, Ypm, kp, p, J, Mz; 83 80 //! store first derivatives for the use in second derivatives 81 double dia, dib, dom, dth; 82 //! d2t = dt^2/2, cth = cos(th), sth=sin(th) 83 double d2t, cth, sth; 84 double iam, ibm, omm, thm, uam, ubm; 84 85 public: 85 IMpmsm2o() :diffbifn (rx.count(), rx, r U) {};86 IMpmsm2o() :diffbifn (rx.count(), rx, ru ) {}; 86 87 //! Set mechanical and electrical variables 87 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; }88 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;} 88 89 89 90 vec eval ( const vec &x0, const vec &u0 ) { 90 91 // last state 91 double iam = x0 ( 0 ); 92 double ibm = x0 ( 1 ); 93 double omm = x0 ( 2 ); 94 double thm = x0 ( 3 ); 95 double uam = u0 ( 0 ); 96 double ubm = u0 ( 1 ); 97 double dua = u0 ( 2 )/dt; 98 double dub = u0 ( 3 )/dt; 99 100 double cth = cos(thm); 101 double sth = sin(thm); 102 double d2t = dt*dt/2; 92 iam = x0 ( 0 ); 93 ibm = x0 ( 1 ); 94 omm = x0 ( 2 ); 95 thm = x0 ( 3 ); 96 uam = u0 ( 0 ); 97 ubm = u0 ( 1 ); 98 99 cth = cos(thm); 100 sth = sin(thm); 103 101 104 double dia = (- Rs/Ls*iam + Ypm/Ls*omm * sth + uam/Ls); 105 double dib = (- Rs/Ls*ibm - Ypm/Ls*omm * cth + ubm/Ls); 106 double dom = kp*p*p * Ypm/J *( ibm * cth-iam * sth ) - p/J*Mz; 107 double dth = omm; 108 109 double d2ia = (- Rs/Ls*dia + Ypm/Ls*(dom * sth + omm*cth) + dua/Ls); 110 double d2ib = (- Rs/Ls*dib - Ypm/Ls*(dom * cth - omm*sth) + dub/Ls); 111 double d2om = kp*p*p * Ypm/J *( dib * cth-ibm*sth - (dia * sth + iam *cth)); 112 double d2th = dom; 113 102 dia = (- Rs/Ls*iam + Ypm/Ls*omm * sth + uam/Ls); 103 dib = (- Rs/Ls*ibm - Ypm/Ls*omm * cth + ubm/Ls); 104 dom = kp*p*p * Ypm/J *( ibm * cth-iam * sth ) - p/J*Mz; 105 dth = omm; 106 114 107 vec xk=zeros ( 4 ); 115 108 xk ( 0 ) = iam + dt*dia;// +d2t*d2ia; … … 118 111 xk ( 3 ) = thm + dt*dth;// +d2t*d2th; // <0..2pi> 119 112 120 x2o_dbg(0)=d2t*d2ia;121 x2o_dbg(1)=d2t*d2ib;122 x2o_dbg(2)=d2t*d2om;123 x2o_dbg(3)=d2t*d2th;124 125 113 if ( xk ( 3 ) >pi ) xk ( 3 )-=2*pi; 126 114 if ( xk ( 3 ) <-pi ) xk ( 3 ) +=2*pi; … … 128 116 } 129 117 118 //! eval 2nd order Taylor expansion, MUST be used only as a follow up AFTER eval()!! 119 vec eval2o(const vec &du){ 120 double dua = du ( 0 )/dt; 121 double dub = du ( 1 )/dt; 122 123 vec xth2o(4); 124 xth2o(0) = (- Rs/Ls*dia + Ypm/Ls*(dom * sth + omm*cth) + dua/Ls); 125 xth2o(1) = (- Rs/Ls*dib - Ypm/Ls*(dom * cth - omm*sth) + dub/Ls); 126 xth2o(2) = kp*p*p * Ypm/J *( dib * cth-ibm*sth - (dia * sth + iam *cth)); 127 xth2o(3) = dom; 128 return xth2o; 129 } 130 130 void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { 131 doubleiam = x0 ( 0 );132 doubleibm = x0 ( 1 );133 doubleomm = x0 ( 2 );134 doublethm = x0 ( 3 );131 iam = x0 ( 0 ); 132 ibm = x0 ( 1 ); 133 omm = x0 ( 2 ); 134 thm = x0 ( 3 ); 135 135 // d ia 136 136 A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0; … … 154 154 //! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$, equation for \f$\omega\f$ is omitted.$ 155 155 class IMpmsmStat : public IMpmsm { 156 public: 156 157 IMpmsmStat() :IMpmsm() {}; 157 158 //! Set mechanical and electrical variables -
pmsm/sim_var.cpp
r232 r240 40 40 double Ww = 0.0; 41 41 vec dt ( 2 ); 42 vec ut ( 4);43 vec utm ( 4);42 vec ut ( 2 ); 43 vec utm ( 2 ); 44 44 vec dut ( 2 ); 45 45 vec dit (2); 46 vec x2o(2); 46 47 vec xtm=zeros ( 4 ); 47 48 vec xte=zeros ( 4 ); … … 62 63 mat Q =diag( Qdiag ); 63 64 mat R =diag ( Rdiag ); 64 EKFfull Efix ( rx,ry,r U);65 EKFfull Efix ( rx,ry,ru ); 65 66 Efix.set_est ( mu0, 1*eye ( 4 ) ); 66 67 Efix.set_parameters ( &fxu,&hxu,Q,R); 67 68 68 EKFfull Eop ( rx,ry,r U);69 EKFfull Eop ( rx,ry,ru ); 69 70 Eop.set_est ( mu0, 1*eye ( 4 ) ); 70 71 Eop.set_parameters ( &fxu,&hxu,Q,R); 71 72 72 EKFfull Edi ( rx,ry,r U);73 EKFfull Edi ( rx,ry,ru ); 73 74 Edi.set_est ( mu0, 1*eye ( 4 ) ); 74 75 Edi.set_parameters ( &fxu,&hxu,Q,R); … … 106 107 ut ( 0 ) = KalmanObs[4]; 107 108 ut ( 1 ) = KalmanObs[5]; 108 ut ( 2 ) = utm(0)-ut(0);109 ut ( 3 ) = utm(1)-ut(1);110 109 110 x2o = fxu.eval2o(utm-ut); 111 111 utm = ut; 112 112 … … 156 156 //LOG 157 157 L.logit(X_log, vec(x,4)); //vec from C-array 158 L.logit(X2o_log, x2o _dbg);158 L.logit(X2o_log, x2o); 159 159 L.logit(Xdf_log, xdif); 160 160 L.logit(Efix_log, Efix_ep.mean() ); -
pmsm/simulator_zdenek/simulator.cpp
r239 r240 394 394 395 395 // uprava velikosti vzhledem k Uc!=Ucn 396 /*kor_Uc=Ucn/230.;396 kor_Uc=Ucn/230.; 397 397 *u*=kor_Uc; /**/ 398 398 399 399 pwm(modulace); 400 400 401 *us=*u*cos(*(u+1));402 *(us+1)=*u*sin(*(u+1));;401 // *us=*u*cos(*(u+1)); 402 // *(us+1)=*u*sin(*(u+1));; 403 403 404 404 pmsm_model(5);