00001 #ifndef PMSM_H
00002 #define PMSM_H
00003 
00004 #include <stat/libFN.h>
00005 
00010 
00011 RV rx ( "{ia ib om th }");
00012 RV ru ( "{ua ub }");
00013 RV ry ( "{oia oib }");
00014 
00015 
00016 
00017 
00018 
00020 class IMpmsm : public diffbifn {
00021 protected:
00022         double Rs, Ls, dt, Ypm, kp, p,  J, Mz;
00023 
00024 public:
00025         IMpmsm() :diffbifn (rx.count(), rx, ru ) {};
00027         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;}
00028 
00029         vec eval ( const vec &x0, const vec &u0 ) {
00030                 
00031                 double iam = x0 ( 0 );
00032                 double ibm = x0 ( 1 );
00033                 double omm = x0 ( 2 );
00034                 double thm = x0 ( 3 );
00035                 double uam = u0 ( 0 );
00036                 double ubm = u0 ( 1 );
00037 
00038                 vec xk=zeros ( 4 );
00039                 
00040                 xk ( 0 ) = ( 1.0- Rs/Ls*dt ) * iam + Ypm/Ls*dt*omm * sin ( thm ) + uam*dt/Ls;
00041                 
00042                 xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls;
00043                 
00044                 xk ( 2 ) = omm + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz;
00045                 
00046                 xk ( 3 ) = thm + omm*dt; 
00047                 if ( xk ( 3 ) >pi ) xk ( 3 )-=2*pi;
00048                 if ( xk ( 3 ) <-pi ) xk ( 3 ) +=2*pi;
00049                 return xk;
00050         }
00051 
00052         void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
00053                 double iam = x0 ( 0 );
00054                 double ibm = x0 ( 1 );
00055                 double omm = x0 ( 2 );
00056                 double thm = x0 ( 3 );
00057                 
00058                 A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0;
00059                 A ( 0,2 ) = Ypm/Ls*dt* sin ( thm ); A ( 0,3 ) = Ypm/Ls*dt*omm * ( cos ( thm ) );
00060                 
00061                 A ( 1,0 ) = 0.0 ; A ( 1,1 ) = ( 1.0- Rs/Ls*dt );
00062                 A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) );
00063                 
00064                 A ( 2,0 ) = kp*p*p * Ypm/J*dt* ( - sin ( thm ) );
00065                 A ( 2,1 ) = kp*p*p * Ypm/J*dt* ( cos ( thm ) );
00066                 A ( 2,2 ) = 1.0;
00067                 A ( 2,3 ) = kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) );
00068                 
00069                 A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0;
00070         }
00071 
00072         void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );};
00073 
00074 };
00075 
00077 class IMpmsmStat : public IMpmsm {
00078         IMpmsmStat() :IMpmsm() {};
00080         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;}
00081 
00082         vec eval ( const vec &x0, const vec &u0 ) {
00083                 
00084                 double iam = x0 ( 0 );
00085                 double ibm = x0 ( 1 );
00086                 double omm = x0 ( 2 );
00087                 double thm = x0 ( 3 );
00088                 double uam = u0 ( 0 );
00089                 double ubm = u0 ( 1 );
00090 
00091                 vec xk=zeros ( 4 );
00092                 
00093                 xk ( 0 ) = ( 1.0- Rs/Ls*dt ) * iam + Ypm/Ls*dt*omm * sin ( thm ) + uam*dt/Ls;
00094                 
00095                 xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls;
00096                 
00097                 xk ( 2 ) = omm;
00098                 
00099                 xk ( 3 ) = rem(thm + omm*dt,2*pi); 
00100                 return xk;
00101         }
00102 
00103         void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
00104 
00105 
00106                 double omm = x0 ( 2 );
00107                 double thm = x0 ( 3 );
00108                 
00109                 A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0;
00110                 A ( 0,2 ) = Ypm/Ls*dt* sin ( thm ); A ( 0,3 ) = Ypm/Ls*dt*omm * ( cos ( thm ) );
00111                 
00112                 A ( 1,0 ) = 0.0 ; A ( 1,1 ) = ( 1.0- Rs/Ls*dt );
00113                 A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) );
00114                 
00115                 A ( 2,0 ) = 0.0;
00116                 A ( 2,1 ) = 0.0;
00117                 A ( 2,2 ) = 1.0;
00118                 A ( 2,3 ) = 0.0;
00119                 
00120                 A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0;
00121         }
00122 
00123         void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );};
00124 
00125 };
00126 
00128 class OMpmsm: public diffbifn {
00129 public:
00130         OMpmsm() :diffbifn (2, rx,ru ) {};
00131 
00132         vec eval ( const vec &x0, const vec &u0 ) {
00133                 vec y ( 2 );
00134                 y ( 0 ) = x0 ( 0 );
00135                 y ( 1 ) = x0 ( 1 );
00136                 return y;
00137         }
00138 
00139         void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
00140                 A.clear();
00141                 A ( 0,0 ) = 1.0;
00142                 A ( 1,1 ) = 1.0;
00143         }
00144 };
00145 
00147 #endif //PMSM_H