| | 225 | |
| | 226 | //! Evolution model of \f$ \omega, \vartheta\f$ for a PMSM drive and its derivative with respect to \f$x\f$ -- Scaled to [-1,1] |
| | 227 | class IMpmsmOTsc : public diffbifn { |
| | 228 | protected: |
| | 229 | double Rs, Ls, dt, Ypm, kp, p, J, Mz; |
| | 230 | |
| | 231 | bool cutoff; |
| | 232 | public: |
| | 233 | IMpmsmOTsc() :diffbifn ( ) {dimy=2; dimx = 2; dimu=4; dimc=6;cutoff=true;}; |
| | 234 | //! Set mechanical and electrical variables |
| | 235 | 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;} |
| | 236 | |
| | 237 | |
| | 238 | vec eval ( const vec &x0, const vec &u0 ) { |
| | 239 | // last state |
| | 240 | const double &omm = x0 ( 0 ); |
| | 241 | const double &thm = x0 ( 1 ); |
| | 242 | double uam; |
| | 243 | double ubm; |
| | 244 | |
| | 245 | uam = u0(0); |
| | 246 | ubm = u0(1); |
| | 247 | |
| | 248 | const double &iam = u0 ( 2 ); |
| | 249 | const double &ibm = u0 ( 3 ); |
| | 250 | |
| | 251 | vec xk( 2 ); |
| | 252 | //ia |
| | 253 | //om |
| | 254 | xk ( 0 ) = omm + kp*p*p * Ypm/J*dt *Iref/Wref* ( ibm * cos ( thm*Thetaref/(1<<15) )-iam * sin ( thm*Thetaref/(1<<15) ) ); |
| | 255 | //th |
| | 256 | xk ( 1 ) = thm + omm*Wref/Thetaref*dt; // <0..2pi> |
| | 257 | if (cutoff) { |
| | 258 | if ( xk ( 1 ) >(1<<15) ) xk ( 1 )=-(1<<15); |
| | 259 | if ( xk ( 1 ) <-(1<<15) ) xk ( 1 ) =(1<<15); |
| | 260 | } |
| | 261 | return xk; |
| | 262 | } |
| | 263 | |
| | 264 | void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { |
| | 265 | const double &omm = x0 ( 0 ); |
| | 266 | const double &thm = x0 ( 1 ); |
| | 267 | |
| | 268 | const double &iam = u0 ( 2 ); |
| | 269 | const double &ibm = u0 ( 3 ); |
| | 270 | |
| | 271 | // d ia |
| | 272 | // d om |
| | 273 | A ( 0,0 ) = 1.0; |
| | 274 | A ( 0,1 ) = 0.0;//kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) ); |
| | 275 | // d th |
| | 276 | A ( 1,0 ) = dt*Wref/Thetaref; |
| | 277 | A ( 1,1 ) = 1.0; |
| | 278 | } |
| | 279 | |
| | 280 | void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );}; |
| | 281 | |
| | 282 | void from_setting( const Setting &root ) |
| | 283 | { |
| | 284 | |
| | 285 | const SettingResolver& params_b=root["params"]; |
| | 286 | const Setting& params=params_b.result; |
| | 287 | |
| | 288 | set_parameters ( params["Rs"], params["Ls"], 125e-6, params["Fmag"], \ |
| | 289 | params["kp"], params["p"], params["J"], 0.0); |
| | 290 | int cuto=0; |
| | 291 | if (UI::get(cuto,root,"cutoff",UI::optional)){cutoff=(cuto==1);} |
| | 292 | }; |
| | 293 | |
| | 294 | // TODO dodelat void to_setting( Setting &root ) const; |
| | 295 | }; |
| | 296 | |
| | 297 | UIREGISTER ( IMpmsmOTsc ); |
| | 768 | //! Observation model for PMSM drive in reduced form coordinates -- scaled to [-1,1] |
| | 769 | class OMpmsmOTsc: public diffbifn { |
| | 770 | public: |
| | 771 | double Rs, Ls, dt, Ypm, kp, p, J, Mz; |
| | 772 | |
| | 773 | 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;} |
| | 774 | |
| | 775 | OMpmsmOTsc() :diffbifn () {dimy=2;dimx=2;dimu=4;}; |
| | 776 | |
| | 777 | vec eval ( const vec &x0, const vec &u0 ) { |
| | 778 | vec y ( 2 ); |
| | 779 | const double &omm = x0(0); |
| | 780 | const double &thm = x0(1); |
| | 781 | |
| | 782 | const double &uam = u0 ( 0 ); |
| | 783 | const double &ubm = u0 ( 1 ); |
| | 784 | const double &iam = u0 ( 2 ); |
| | 785 | const double &ibm = u0 ( 3 ); |
| | 786 | |
| | 787 | y ( 0 ) = ( 1.0- Rs/Ls*dt ) * iam + Ypm/Ls*dt*omm *Wref/Iref* sin ( thm*Thetaref/(1<<15) ) + (1<<15)*uam*dt/Ls /Iref; |
| | 788 | //ib |
| | 789 | y ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm *Wref/Iref* cos ( thm*Thetaref/(1<<15) ) + (1<<15)*ubm*dt/Ls /Iref; |
| | 790 | |
| | 791 | return y; |
| | 792 | } |
| | 793 | |
| | 794 | void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { |
| | 795 | const double &omm = x0(0); |
| | 796 | const double &thm = x0(1); |
| | 797 | |
| | 798 | A ( 0,0 ) = Ypm/Ls*dt* Wref/Iref*sin ( thm*Thetaref/(1<<15) ); |
| | 799 | A ( 0,1 ) = Ypm/Ls*dt*omm *Wref/Iref*Thetaref/(1<<15)* ( cos ( thm*Thetaref/(1<<15) ) ); |
| | 800 | // d ib |
| | 801 | A ( 1,0 ) = -Ypm/Ls*dt* Wref/Iref*cos ( thm*Thetaref/(1<<15) ); |
| | 802 | A ( 1,1 ) = Ypm/Ls*dt*omm *Wref/Iref*Thetaref/(1<<15)* ( sin ( thm*Thetaref/(1<<15) ) ); |
| | 803 | |
| | 804 | |
| | 805 | } |
| | 806 | |
| | 807 | void from_setting( const Setting &root ) |
| | 808 | { |
| | 809 | |
| | 810 | const SettingResolver& params_b=root["params"]; |
| | 811 | const Setting& params=params_b.result; |
| | 812 | |
| | 813 | set_parameters ( params["Rs"], params["Ls"], 125e-6, params["Fmag"], \ |
| | 814 | params["kp"], params["p"], params["J"], 0.0); |
| | 815 | }; |
| | 816 | |
| | 817 | }; |
| | 818 | |
| | 819 | UIREGISTER ( OMpmsmOTsc ); |
| | 820 | |