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