Changeset 332 for applications/pmsm/pmsm.h
- Timestamp:
- 04/29/09 20:14:56 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/pmsm/pmsm.h
r325 r332 28 28 //! Set mechanical and electrical variables 29 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 31 void modelpwm(const vec &x0, const vec u0, double &ua, double &ub){ 32 double sq3=sqrt ( 3.0 ); 33 double i1=x0(0); 34 double i2=0.5* ( -i1+sq3*x0[1] ); 35 double i3=0.5* ( -i1-sq3*x0[1] ); 36 double u1=u0(0); 37 double u2=0.5* ( -u1+sq3*u0(1) ); 38 double u3=0.5* ( -u1-sq3*u0(1) ); 39 40 double du1=1.4* ( double ( i1>0.3 ) - double ( i1<-0.3 ) ) +0.2*i1; 41 double du2=1.4* ( double ( i2>0.3 ) - double ( i2<-0.3 ) ) +0.2*i2; 42 double du3=1.4* ( double ( i3>0.3 ) - double ( i3<-0.3 ) ) +0.2*i3; 43 ua = ( 2.0* ( u1-du1 )- ( u2-du2 )- ( u3-du3 ) ) /3.0; 44 ub = ( ( u2-du2 )- ( u3-du3 ) ) /sq3; 45 } 30 46 31 47 vec eval ( const vec &x0, const vec &u0 ) { … … 35 51 const double &omm = x0 ( 2 ); 36 52 const double &thm = x0 ( 3 ); 37 const double &uam = u0 ( 0 ); 38 const double &ubm = u0 ( 1 ); 39 53 double uam; 54 double ubm; 55 56 modelpwm(x0,u0,uam,ubm); 57 40 58 vec xk( 4 ); 41 59 //ia … … 73 91 74 92 void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );}; 75 76 }; 93 }; 94 77 95 78 96 //! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$ … … 183 201 xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls; 184 202 //om 185 xk ( 2 ) = omm ;// + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz;203 xk ( 2 ) = omm - p/J*dt*Mz;// + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ); 186 204 //th 187 205 xk ( 3 ) = rem(thm + omm*dt,2*pi); // <0..2pi> … … 213 231 }; 214 232 233 //! State for PMSM with unknown Mz 234 class IMpmsmMz: public IMpmsm{ 235 public: 236 IMpmsmMz() {dimy=5; dimx = 5; dimu=2;}; 237 //! extend eval by Mz 238 vec eval ( const vec &x0, const vec &u0 ) { 239 vec x(4); 240 Mz = x0(4); //last of the state is Mz 241 242 //teh first 4 states are same as before (given that Mz is set) 243 x=IMpmsm::eval(x0,u0); // including model of drops! 244 return concat(x,Mz); 245 } 246 void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { 247 //call initial 248 if (full) A.clear(); 249 IMpmsm::dfdx_cond(x0,u0,A,full); 250 A(2,4)=- p/J*dt; 251 A(4,4)=1.0; 252 } 253 }; 254 255 //! State for PMSM with unknown Mz 256 class IMpmsmStatMz: public IMpmsmStat{ 257 public: 258 IMpmsmStatMz() {dimy=5; dimx = 5; dimu=2;}; 259 //! extend eval by Mz 260 vec eval ( const vec &x0, const vec &u0 ) { 261 vec x(4); 262 Mz = x0(4); //last of the state is Mz 263 264 //teh first 4 states are same as before (given that Mz is set) 265 x=IMpmsmStat::eval(x0,u0); // including model of drops! 266 return concat(x,Mz); 267 } 268 void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { 269 //call initial 270 if (full) A.clear(); 271 IMpmsmStat::dfdx_cond(x0,u0,A,full); 272 A(2,4)=- p/J*dt; 273 A(4,4)=1.0; 274 } 275 }; 276 277 215 278 //! Observation model for PMSM drive and its derivative with respect to \f$x\f$ 216 279 class OMpmsm: public diffbifn { … … 232 295 }; 233 296 297 //! Observation model for PMSM drive and its derivative with respect to \f$x\f$ for full vector of observations 298 class OMpmsm4: public diffbifn { 299 public: 300 OMpmsm4() :diffbifn () {dimy=4;dimx=4;dimu=2;}; 301 302 vec eval ( const vec &x0, const vec &u0 ) { 303 vec y ( 4 ); 304 y = x0 ; 305 return y; 306 } 307 308 void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { 309 if (full) A=eye(4); 310 } 311 }; 312 234 313 /*!@}*/ 235 314 #endif //PMSM_H