00001 #ifndef PMSM_H
00002 #define PMSM_H
00003
00004 #include <stat/libFN.h>
00005
00010 using namespace bdm;
00011
00012
00013 RV rx ( "{ia ib om th }");
00014 RV ru ( "{ua ub }");
00015 RV ry ( "{oia oib }");
00016
00017
00018
00019
00020
00022 class IMpmsm : public diffbifn {
00023 protected:
00024 double Rs, Ls, dt, Ypm, kp, p, J, Mz;
00025
00026 public:
00027 IMpmsm() :diffbifn ( ) {dimy=4; dimx = 4; dimu=2;};
00029 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;}
00030
00031 void modelpwm(const vec &x0, const vec u0, double &ua, double &ub){
00032
00033
00034
00035 double sq3=sqrt ( 3.0 );
00036 double i1=x0(0);
00037 double i2=0.5* ( -i1+sq3*x0[1] );
00038 double i3=0.5* ( -i1-sq3*x0[1] );
00039 double u1=u0(0);
00040 double u2=0.5* ( -u1+sq3*u0(1) );
00041 double u3=0.5* ( -u1-sq3*u0(1) );
00042
00043 double du1=1.4* ( double ( i1>0.3 ) - double ( i1<-0.3 ) ) +0.2*i1;
00044 double du2=1.4* ( double ( i2>0.3 ) - double ( i2<-0.3 ) ) +0.2*i2;
00045 double du3=1.4* ( double ( i3>0.3 ) - double ( i3<-0.3 ) ) +0.2*i3;
00046 ua = ( 2.0* ( u1-du1 )- ( u2-du2 )- ( u3-du3 ) ) /3.0;
00047 ub = ( ( u2-du2 )- ( u3-du3 ) ) /sq3;
00048 }
00049
00050 vec eval ( const vec &x0, const vec &u0 ) {
00051
00052 const double &iam = x0 ( 0 );
00053 const double &ibm = x0 ( 1 );
00054 const double &omm = x0 ( 2 );
00055 const double &thm = x0 ( 3 );
00056 double uam;
00057 double ubm;
00058
00059 modelpwm(x0,u0,uam,ubm);
00060
00061 vec xk( 4 );
00062
00063 xk ( 0 ) = ( 1.0- Rs/Ls*dt ) * iam + Ypm/Ls*dt*omm * sin ( thm ) + uam*dt/Ls;
00064
00065 xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls;
00066
00067 xk ( 2 ) = omm + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz;
00068
00069 xk ( 3 ) = thm + omm*dt;
00070 if ( xk ( 3 ) >pi ) xk ( 3 )-=2*pi;
00071 if ( xk ( 3 ) <-pi ) xk ( 3 ) +=2*pi;
00072 return xk;
00073 }
00074
00075 void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
00076 const double &iam = x0 ( 0 );
00077 const double &ibm = x0 ( 1 );
00078 const double &omm = x0 ( 2 );
00079 const double &thm = x0 ( 3 );
00080
00081 A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0;
00082 A ( 0,2 ) = Ypm/Ls*dt* sin ( thm ); A ( 0,3 ) = Ypm/Ls*dt*omm * ( cos ( thm ) );
00083
00084 A ( 1,0 ) = 0.0 ; A ( 1,1 ) = ( 1.0- Rs/Ls*dt );
00085 A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) );
00086
00087 A ( 2,0 ) = kp*p*p * Ypm/J*dt* ( - sin ( thm ) );
00088 A ( 2,1 ) = kp*p*p * Ypm/J*dt* ( cos ( thm ) );
00089 A ( 2,2 ) = 1.0;
00090 A ( 2,3 ) = kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) );
00091
00092 A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0;
00093 }
00094
00095 void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );};
00096 };
00097
00098
00100 class IMpmsm2o : public IMpmsm {
00101 protected:
00102
00104 double dia, dib, dom, dth;
00106 double d2t, cth, sth;
00107 double iam, ibm, omm, thm, uam, ubm;
00108 public:
00109 IMpmsm2o() :IMpmsm () {};
00111 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;}
00112
00113 vec eval ( const vec &x0, const vec &u0 ) {
00114
00115 iam = x0 ( 0 );
00116 ibm = x0 ( 1 );
00117 omm = x0 ( 2 );
00118 thm = x0 ( 3 );
00119 uam = u0 ( 0 );
00120 ubm = u0 ( 1 );
00121
00122 cth = cos(thm);
00123 sth = sin(thm);
00124
00125 dia = (- Rs/Ls*iam + Ypm/Ls*omm * sth + uam/Ls);
00126 dib = (- Rs/Ls*ibm - Ypm/Ls*omm * cth + ubm/Ls);
00127 dom = kp*p*p * Ypm/J *( ibm * cth-iam * sth ) - p/J*Mz;
00128 dth = omm;
00129
00130 vec xk=zeros ( 4 );
00131 xk ( 0 ) = iam + dt*dia;
00132 xk ( 1 ) = ibm + dt*dib;
00133 xk ( 2 ) = omm +dt*dom;
00134 xk ( 3 ) = thm + dt*dth;
00135
00136 if ( xk ( 3 ) >pi ) xk ( 3 )-=2*pi;
00137 if ( xk ( 3 ) <-pi ) xk ( 3 ) +=2*pi;
00138 return xk;
00139 }
00140
00142 vec eval2o(const vec &du){
00143 double dua = du ( 0 )/dt;
00144 double dub = du ( 1 )/dt;
00145
00146 vec xth2o(4);
00147 xth2o(0) = (- Rs/Ls*dia + Ypm/Ls*(dom * sth + omm*cth) + dua/Ls);
00148 xth2o(1) = (- Rs/Ls*dib - Ypm/Ls*(dom * cth - omm*sth) + dub/Ls);
00149 xth2o(2) = kp*p*p * Ypm/J *( dib * cth-ibm*sth - (dia * sth + iam *cth));
00150 xth2o(3) = dom;
00151
00152 xth2o*=d2t/2;
00153 return xth2o;
00154 }
00155 void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
00156 iam = x0 ( 0 );
00157 ibm = x0 ( 1 );
00158 omm = x0 ( 2 );
00159 thm = x0 ( 3 );
00160
00161 A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0;
00162 A ( 0,2 ) = Ypm/Ls*dt* sin ( thm ); A ( 0,3 ) = Ypm/Ls*dt*omm * ( cos ( thm ) );
00163
00164 A ( 1,0 ) = 0.0 ; A ( 1,1 ) = ( 1.0- Rs/Ls*dt );
00165 A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) );
00166
00167 A ( 2,0 ) = kp*p*p * Ypm/J*dt* ( - sin ( thm ) );
00168 A ( 2,1 ) = kp*p*p * Ypm/J*dt* ( cos ( thm ) );
00169 A ( 2,2 ) = 1.0;
00170 A ( 2,3 ) = kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) );
00171
00172 A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0;
00173
00174
00175
00176
00177
00178 }
00179
00180 void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );};
00181
00182 };
00183
00185 class IMpmsmStat : public IMpmsm {
00186 public:
00187 IMpmsmStat() :IMpmsm() {};
00189 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;}
00190
00191 vec eval ( const vec &x0, const vec &u0 ) {
00192
00193 double iam = x0 ( 0 );
00194 double ibm = x0 ( 1 );
00195 double omm = x0 ( 2 );
00196 double thm = x0 ( 3 );
00197 double uam = u0 ( 0 );
00198 double ubm = u0 ( 1 );
00199
00200 vec xk=zeros ( 4 );
00201
00202 xk ( 0 ) = ( 1.0- Rs/Ls*dt ) * iam + Ypm/Ls*dt*omm * sin ( thm ) + uam*dt/Ls;
00203
00204 xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls;
00205
00206 xk ( 2 ) = omm - p/J*dt*Mz;
00207
00208 xk ( 3 ) = rem(thm + omm*dt,2*pi);
00209 return xk;
00210 }
00211
00212 void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
00213
00214
00215 double omm = x0 ( 2 );
00216 double thm = x0 ( 3 );
00217
00218 A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0;
00219 A ( 0,2 ) = Ypm/Ls*dt* sin ( thm ); A ( 0,3 ) = Ypm/Ls*dt*omm * ( cos ( thm ) );
00220
00221 A ( 1,0 ) = 0.0 ; A ( 1,1 ) = ( 1.0- Rs/Ls*dt );
00222 A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) );
00223
00224 A ( 2,0 ) = 0.0;
00225 A ( 2,1 ) = 0.0;
00226 A ( 2,2 ) = 1.0;
00227 A ( 2,3 ) = 0.0;
00228
00229 A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0;
00230 }
00231
00232 void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );};
00233
00234 };
00235
00237 class IMpmsmMz: public IMpmsm{
00238 public:
00239 IMpmsmMz() {dimy=5; dimx = 5; dimu=2;};
00241 vec eval ( const vec &x0, const vec &u0 ) {
00242 vec x(4);
00243 Mz = x0(4);
00244
00245
00246 x=IMpmsm::eval(x0,u0);
00247 return concat(x,Mz);
00248 }
00249 void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
00250
00251 if (full) A.clear();
00252 IMpmsm::dfdx_cond(x0,u0,A,full);
00253 A(2,4)=- p/J*dt;
00254 A(4,4)=1.0;
00255 }
00256 };
00257
00259 class IMpmsmStatMz: public IMpmsmStat{
00260 public:
00261 IMpmsmStatMz() {dimy=5; dimx = 5; dimu=2;};
00263 vec eval ( const vec &x0, const vec &u0 ) {
00264 vec x(4);
00265 Mz = x0(4);
00266
00267
00268 x=IMpmsmStat::eval(x0,u0);
00269 return concat(x,Mz);
00270 }
00271 void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
00272
00273 if (full) A.clear();
00274 IMpmsmStat::dfdx_cond(x0,u0,A,full);
00275 A(2,4)=- p/J*dt;
00276 A(4,4)=1.0;
00277 }
00278 };
00279
00280
00282 class OMpmsm: public diffbifn {
00283 public:
00284 OMpmsm() :diffbifn () {dimy=2;dimx=4;dimu=2;};
00285
00286 vec eval ( const vec &x0, const vec &u0 ) {
00287 vec y ( 2 );
00288 y ( 0 ) = x0 ( 0 );
00289 y ( 1 ) = x0 ( 1 );
00290 return y;
00291 }
00292
00293 void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
00294 A.clear();
00295 A ( 0,0 ) = 1.0;
00296 A ( 1,1 ) = 1.0;
00297 }
00298 };
00299
00301 class OMpmsm4: public diffbifn {
00302 public:
00303 OMpmsm4() :diffbifn () {dimy=4;dimx=4;dimu=2;};
00304
00305 vec eval ( const vec &x0, const vec &u0 ) {
00306 vec y ( 4 );
00307 y = x0 ;
00308 return y;
00309 }
00310
00311 void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
00312 if (full) A=eye(4);
00313 }
00314 };
00315
00317 #endif //PMSM_H