| 126 | |
| 127 | |
| 128 | //! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$ |
| 129 | class IMpmsmDQ : public diffbifn { |
| 130 | protected: |
| 131 | double Rs, Ld, Lq, dt, Ypm, kp, p, J, Mz; |
| 132 | |
| 133 | bool compensate; |
| 134 | bool cutoff; |
| 135 | public: |
| 136 | IMpmsmDQ() :diffbifn ( ) {dimy=4; dimx = 4; dimu=2; dimc=6;compensate=true;cutoff=true;}; |
| 137 | //! Set mechanical and electrical variables |
| 138 | virtual void set_parameters ( double Rs0, double Ld0, double Lq0, double dt0, double Ypm0, double kp0, double p0, double J0, double Mz0 ) {Rs=Rs0; Ld=Ld0; Lq=Lq0; dt=dt0; Ypm=Ypm0; kp=kp0; p=p0; J=J0; Mz=Mz0;} |
| 139 | |
| 140 | void modelpwm(const vec &x0, const vec u0, double &ua, double &ub){ |
| 141 | /* ua=u0[0]; |
| 142 | * ub=u0[1]; |
| 143 | * return;*/ |
| 144 | double sq3=sqrt ( 3.0 ); |
| 145 | double i1=x0(0); |
| 146 | double i2=0.5* ( -i1+sq3*x0[1] ); |
| 147 | double i3=0.5* ( -i1-sq3*x0[1] ); |
| 148 | double u1=u0(0); |
| 149 | double u2=0.5* ( -u1+sq3*u0(1) ); |
| 150 | double u3=0.5* ( -u1-sq3*u0(1) ); |
| 151 | |
| 152 | double du1=1.4* ( double ( i1>0.3 ) - double ( i1<-0.3 ) ) +0.2*i1; |
| 153 | double du2=1.4* ( double ( i2>0.3 ) - double ( i2<-0.3 ) ) +0.2*i2; |
| 154 | double du3=1.4* ( double ( i3>0.3 ) - double ( i3<-0.3 ) ) +0.2*i3; |
| 155 | ua = ( 2.0* ( u1-du1 )- ( u2-du2 )- ( u3-du3 ) ) /3.0; |
| 156 | ub = ( ( u2-du2 )- ( u3-du3 ) ) /sq3; |
| 157 | } |
| 158 | |
| 159 | vec eval ( const vec &x0, const vec &u0 ) { |
| 160 | // last state |
| 161 | const double &idm = x0 ( 0 ); |
| 162 | const double &iqm = x0 ( 1 ); |
| 163 | const double &omm = x0 ( 2 ); |
| 164 | const double &thm = x0 ( 3 ); |
| 165 | double uam; |
| 166 | double ubm; |
| 167 | |
| 168 | if (compensate){ |
| 169 | modelpwm(x0,u0,uam,ubm); |
| 170 | } else { |
| 171 | uam = u0(0); |
| 172 | ubm = u0(1); |
| 173 | } |
| 174 | |
| 175 | vec xk( 4 ); |
| 176 | //id |
| 177 | xk ( 0 ) = ( 1.0- Rs/Ld*dt ) * idm + Lq/Ld*iqm*dt*omm + dt/Ld*(cos(thm)*uam+sin(thm)*ubm); |
| 178 | //iq |
| 179 | xk ( 1 ) = ( 1.0- Rs/Lq*dt ) * iqm - Ypm/Lq*dt*omm - Ld/Lq*dt*idm*omm + dt/Lq*(-sin(thm)*uam+cos(thm)*ubm); |
| 180 | //om |
| 181 | xk ( 2 ) = omm + kp*p*p /J*dt* ( (Ld-Lq)*idm+ Ypm)*iqm - p/J*dt*Mz; |
| 182 | //th |
| 183 | xk ( 3 ) = thm + omm*dt; // <0..2pi> |
| 184 | if (cutoff) { |
| 185 | if ( xk ( 3 ) >pi ) xk ( 3 )-=2*pi; |
| 186 | if ( xk ( 3 ) <-pi ) xk ( 3 ) +=2*pi; |
| 187 | } |
| 188 | return xk; |
| 189 | } |
| 190 | |
| 191 | void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { |
| 192 | const double &idm = x0 ( 0 ); |
| 193 | const double &iqm = x0 ( 1 ); |
| 194 | const double &omm = x0 ( 2 ); |
| 195 | const double &thm = x0 ( 3 ); |
| 196 | |
| 197 | double uam; |
| 198 | double ubm; |
| 199 | if (compensate){ |
| 200 | modelpwm(x0,u0,uam,ubm); |
| 201 | } else { |
| 202 | uam = u0(0); |
| 203 | ubm = u0(1); |
| 204 | } |
| 205 | // d id |
| 206 | A ( 0,0 ) = ( 1.0- Rs/Ld*dt ); A ( 0,1 ) = Lq/Ld*dt*omm; |
| 207 | A ( 0,2 ) = Lq/Ld*iqm*dt; A ( 0,3 ) = dt/Ld*(-sin(thm)*uam+cos(thm)*ubm); |
| 208 | // d iq |
| 209 | A ( 1,0 ) = -Ld/Lq*omm*dt ; A ( 1,1 ) = ( 1.0- Rs/Lq*dt ); |
| 210 | A ( 1,2 ) = -Ypm/Lq*dt- Ld/Lq*dt*idm; A ( 1,3 ) = dt/Lq*(-cos(thm)*uam-sin(thm)*ubm); |
| 211 | // d om |
| 212 | A ( 2,0 ) = kp*p*p /J*dt* ( Ld-Lq)*iqm; |
| 213 | A ( 2,1 ) = kp*p*p /J*dt* ((Ld-Lq)*idm+Ypm); |
| 214 | A ( 2,2 ) = 1.0; |
| 215 | A ( 2,3 ) = 0; |
| 216 | // d th |
| 217 | A ( 3,0 ) = 0.0; |
| 218 | A ( 3,1 ) = 0.0; |
| 219 | A ( 3,2 ) = dt; A ( 3,3 ) = 1.0; |
| 220 | } |
| 221 | |
| 222 | void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );}; |
| 223 | |
| 224 | void from_setting( const Setting &root ) |
| 225 | { |
| 226 | |
| 227 | const SettingResolver& params_b=root["params"]; |
| 228 | const Setting& params=params_b.result; |
| 229 | |
| 230 | set_parameters ( params["Rs"], params["Ld"],params["Lq"], 125e-6, params["Fmag"], \ |
| 231 | params["kp"], params["p"], params["J"], 0.0); |
| 232 | int comp=0; |
| 233 | if (UI::get(comp,root,"compensate",UI::optional)){compensate=(comp==1);} |
| 234 | int cuto=0; |
| 235 | if (UI::get(cuto,root,"cutoff",UI::optional)){cutoff=(cuto==1);} |
| 236 | }; |
| 237 | |
| 238 | // TODO dodelat void to_setting( Setting &root ) const; |
| 239 | }; |
| 240 | |
| 241 | UIREGISTER ( IMpmsmDQ ); |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |