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