[33] | 1 | #ifndef PMSM_H |
---|
| 2 | #define PMSM_H |
---|
| 3 | |
---|
[54] | 4 | #include <stat/libFN.h> |
---|
| 5 | |
---|
[224] | 6 | /*! \defgroup PMSM |
---|
| 7 | @{ |
---|
| 8 | */ |
---|
| 9 | |
---|
[254] | 10 | using namespace bdm; |
---|
| 11 | |
---|
[48] | 12 | //TODO hardcoded RVs!!! |
---|
[162] | 13 | RV rx ( "{ia ib om th }"); |
---|
| 14 | RV ru ( "{ua ub }"); |
---|
| 15 | RV ry ( "{oia oib }"); |
---|
[33] | 16 | |
---|
[128] | 17 | // class uipmsm : public uibase{ |
---|
| 18 | // double Rs, Ls, dt, Ypm, kp, p, J, Mz; |
---|
| 19 | // }; |
---|
[81] | 20 | |
---|
[223] | 21 | //! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$ |
---|
[33] | 22 | class IMpmsm : public diffbifn { |
---|
[63] | 23 | protected: |
---|
[33] | 24 | double Rs, Ls, dt, Ypm, kp, p, J, Mz; |
---|
| 25 | |
---|
| 26 | public: |
---|
[279] | 27 | IMpmsm() :diffbifn ( ) {dimy=4; dimx = 4; dimu=2;}; |
---|
[33] | 28 | //! Set mechanical and electrical variables |
---|
| 29 | 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;} |
---|
| 30 | |
---|
| 31 | vec eval ( const vec &x0, const vec &u0 ) { |
---|
| 32 | // last state |
---|
[283] | 33 | const double &iam = x0 ( 0 ); |
---|
| 34 | const double &ibm = x0 ( 1 ); |
---|
| 35 | const double &omm = x0 ( 2 ); |
---|
| 36 | const double &thm = x0 ( 3 ); |
---|
| 37 | const double &uam = u0 ( 0 ); |
---|
| 38 | const double &ubm = u0 ( 1 ); |
---|
[33] | 39 | |
---|
[280] | 40 | vec xk( 4 ); |
---|
[33] | 41 | //ia |
---|
| 42 | xk ( 0 ) = ( 1.0- Rs/Ls*dt ) * iam + Ypm/Ls*dt*omm * sin ( thm ) + uam*dt/Ls; |
---|
| 43 | //ib |
---|
| 44 | xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls; |
---|
| 45 | //om |
---|
[63] | 46 | xk ( 2 ) = omm + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz; |
---|
| 47 | //th |
---|
[81] | 48 | xk ( 3 ) = thm + omm*dt; // <0..2pi> |
---|
| 49 | if ( xk ( 3 ) >pi ) xk ( 3 )-=2*pi; |
---|
| 50 | if ( xk ( 3 ) <-pi ) xk ( 3 ) +=2*pi; |
---|
[63] | 51 | return xk; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { |
---|
[283] | 55 | const double &iam = x0 ( 0 ); |
---|
| 56 | const double &ibm = x0 ( 1 ); |
---|
| 57 | const double &omm = x0 ( 2 ); |
---|
| 58 | const double &thm = x0 ( 3 ); |
---|
[63] | 59 | // d ia |
---|
| 60 | A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0; |
---|
| 61 | A ( 0,2 ) = Ypm/Ls*dt* sin ( thm ); A ( 0,3 ) = Ypm/Ls*dt*omm * ( cos ( thm ) ); |
---|
| 62 | // d ib |
---|
| 63 | A ( 1,0 ) = 0.0 ; A ( 1,1 ) = ( 1.0- Rs/Ls*dt ); |
---|
| 64 | A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) ); |
---|
| 65 | // d om |
---|
| 66 | A ( 2,0 ) = kp*p*p * Ypm/J*dt* ( - sin ( thm ) ); |
---|
| 67 | A ( 2,1 ) = kp*p*p * Ypm/J*dt* ( cos ( thm ) ); |
---|
| 68 | A ( 2,2 ) = 1.0; |
---|
| 69 | A ( 2,3 ) = kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) ); |
---|
| 70 | // d th |
---|
| 71 | A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );}; |
---|
| 75 | |
---|
| 76 | }; |
---|
| 77 | |
---|
[232] | 78 | //! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$ |
---|
| 79 | class IMpmsm2o : public diffbifn { |
---|
| 80 | protected: |
---|
| 81 | double Rs, Ls, dt, Ypm, kp, p, J, Mz; |
---|
[240] | 82 | //! store first derivatives for the use in second derivatives |
---|
| 83 | double dia, dib, dom, dth; |
---|
| 84 | //! d2t = dt^2/2, cth = cos(th), sth=sin(th) |
---|
| 85 | double d2t, cth, sth; |
---|
| 86 | double iam, ibm, omm, thm, uam, ubm; |
---|
[232] | 87 | public: |
---|
[279] | 88 | IMpmsm2o() :diffbifn () {dimy=4;dimx=4;dimu=2;}; |
---|
[232] | 89 | //! Set mechanical and electrical variables |
---|
[240] | 90 | 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; d2t=dt*dt/2;} |
---|
[232] | 91 | |
---|
| 92 | vec eval ( const vec &x0, const vec &u0 ) { |
---|
| 93 | // last state |
---|
[240] | 94 | iam = x0 ( 0 ); |
---|
| 95 | ibm = x0 ( 1 ); |
---|
| 96 | omm = x0 ( 2 ); |
---|
| 97 | thm = x0 ( 3 ); |
---|
| 98 | uam = u0 ( 0 ); |
---|
| 99 | ubm = u0 ( 1 ); |
---|
[232] | 100 | |
---|
[240] | 101 | cth = cos(thm); |
---|
| 102 | sth = sin(thm); |
---|
[232] | 103 | |
---|
[240] | 104 | dia = (- Rs/Ls*iam + Ypm/Ls*omm * sth + uam/Ls); |
---|
| 105 | dib = (- Rs/Ls*ibm - Ypm/Ls*omm * cth + ubm/Ls); |
---|
| 106 | dom = kp*p*p * Ypm/J *( ibm * cth-iam * sth ) - p/J*Mz; |
---|
| 107 | dth = omm; |
---|
| 108 | |
---|
[232] | 109 | vec xk=zeros ( 4 ); |
---|
| 110 | xk ( 0 ) = iam + dt*dia;// +d2t*d2ia; |
---|
| 111 | xk ( 1 ) = ibm + dt*dib;// +d2t*d2ib; |
---|
| 112 | xk ( 2 ) = omm +dt*dom;// +d2t*d2om; |
---|
| 113 | xk ( 3 ) = thm + dt*dth;// +d2t*d2th; // <0..2pi> |
---|
| 114 | |
---|
| 115 | if ( xk ( 3 ) >pi ) xk ( 3 )-=2*pi; |
---|
| 116 | if ( xk ( 3 ) <-pi ) xk ( 3 ) +=2*pi; |
---|
| 117 | return xk; |
---|
| 118 | } |
---|
| 119 | |
---|
[240] | 120 | //! eval 2nd order Taylor expansion, MUST be used only as a follow up AFTER eval()!! |
---|
| 121 | vec eval2o(const vec &du){ |
---|
| 122 | double dua = du ( 0 )/dt; |
---|
| 123 | double dub = du ( 1 )/dt; |
---|
| 124 | |
---|
| 125 | vec xth2o(4); |
---|
| 126 | xth2o(0) = (- Rs/Ls*dia + Ypm/Ls*(dom * sth + omm*cth) + dua/Ls); |
---|
| 127 | xth2o(1) = (- Rs/Ls*dib - Ypm/Ls*(dom * cth - omm*sth) + dub/Ls); |
---|
| 128 | xth2o(2) = kp*p*p * Ypm/J *( dib * cth-ibm*sth - (dia * sth + iam *cth)); |
---|
| 129 | xth2o(3) = dom; |
---|
| 130 | return xth2o; |
---|
| 131 | } |
---|
[232] | 132 | void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { |
---|
[240] | 133 | iam = x0 ( 0 ); |
---|
| 134 | ibm = x0 ( 1 ); |
---|
| 135 | omm = x0 ( 2 ); |
---|
| 136 | thm = x0 ( 3 ); |
---|
[232] | 137 | // d ia |
---|
| 138 | A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0; |
---|
| 139 | A ( 0,2 ) = Ypm/Ls*dt* sin ( thm ); A ( 0,3 ) = Ypm/Ls*dt*omm * ( cos ( thm ) ); |
---|
| 140 | // d ib |
---|
| 141 | A ( 1,0 ) = 0.0 ; A ( 1,1 ) = ( 1.0- Rs/Ls*dt ); |
---|
| 142 | A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) ); |
---|
| 143 | // d om |
---|
| 144 | A ( 2,0 ) = kp*p*p * Ypm/J*dt* ( - sin ( thm ) ); |
---|
| 145 | A ( 2,1 ) = kp*p*p * Ypm/J*dt* ( cos ( thm ) ); |
---|
| 146 | A ( 2,2 ) = 1.0; |
---|
| 147 | A ( 2,3 ) = kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) ); |
---|
| 148 | // d th |
---|
| 149 | A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );}; |
---|
| 153 | |
---|
| 154 | }; |
---|
| 155 | |
---|
[145] | 156 | //! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$, equation for \f$\omega\f$ is omitted.$ |
---|
[63] | 157 | class IMpmsmStat : public IMpmsm { |
---|
[240] | 158 | public: |
---|
[63] | 159 | IMpmsmStat() :IMpmsm() {}; |
---|
| 160 | //! Set mechanical and electrical variables |
---|
| 161 | 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;} |
---|
| 162 | |
---|
| 163 | vec eval ( const vec &x0, const vec &u0 ) { |
---|
| 164 | // last state |
---|
| 165 | double iam = x0 ( 0 ); |
---|
| 166 | double ibm = x0 ( 1 ); |
---|
| 167 | double omm = x0 ( 2 ); |
---|
| 168 | double thm = x0 ( 3 ); |
---|
| 169 | double uam = u0 ( 0 ); |
---|
| 170 | double ubm = u0 ( 1 ); |
---|
| 171 | |
---|
| 172 | vec xk=zeros ( 4 ); |
---|
| 173 | //ia |
---|
| 174 | xk ( 0 ) = ( 1.0- Rs/Ls*dt ) * iam + Ypm/Ls*dt*omm * sin ( thm ) + uam*dt/Ls; |
---|
| 175 | //ib |
---|
| 176 | xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls; |
---|
| 177 | //om |
---|
[62] | 178 | xk ( 2 ) = omm;// + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz; |
---|
[33] | 179 | //th |
---|
[48] | 180 | xk ( 3 ) = rem(thm + omm*dt,2*pi); // <0..2pi> |
---|
[33] | 181 | return xk; |
---|
| 182 | } |
---|
| 183 | |
---|
| 184 | void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { |
---|
[91] | 185 | // double iam = x0 ( 0 ); |
---|
| 186 | // double ibm = x0 ( 1 ); |
---|
[33] | 187 | double omm = x0 ( 2 ); |
---|
| 188 | double thm = x0 ( 3 ); |
---|
| 189 | // d ia |
---|
| 190 | A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0; |
---|
| 191 | A ( 0,2 ) = Ypm/Ls*dt* sin ( thm ); A ( 0,3 ) = Ypm/Ls*dt*omm * ( cos ( thm ) ); |
---|
| 192 | // d ib |
---|
| 193 | A ( 1,0 ) = 0.0 ; A ( 1,1 ) = ( 1.0- Rs/Ls*dt ); |
---|
| 194 | A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) ); |
---|
| 195 | // d om |
---|
[62] | 196 | A ( 2,0 ) = 0.0;//kp*p*p * Ypm/J*dt* ( - sin ( thm ) ); |
---|
| 197 | A ( 2,1 ) = 0.0;//kp*p*p * Ypm/J*dt* ( cos ( thm ) ); |
---|
[33] | 198 | A ( 2,2 ) = 1.0; |
---|
[62] | 199 | A ( 2,3 ) = 0.0;//kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) ); |
---|
[33] | 200 | // d th |
---|
| 201 | A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );}; |
---|
| 205 | |
---|
| 206 | }; |
---|
| 207 | |
---|
[145] | 208 | //! Observation model for PMSM drive and its derivative with respect to \f$x\f$ |
---|
[33] | 209 | class OMpmsm: public diffbifn { |
---|
| 210 | public: |
---|
[279] | 211 | OMpmsm() :diffbifn () {dimy=2;dimx=4;dimu=2;}; |
---|
[33] | 212 | |
---|
| 213 | vec eval ( const vec &x0, const vec &u0 ) { |
---|
| 214 | vec y ( 2 ); |
---|
| 215 | y ( 0 ) = x0 ( 0 ); |
---|
| 216 | y ( 1 ) = x0 ( 1 ); |
---|
| 217 | return y; |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { |
---|
| 221 | A.clear(); |
---|
| 222 | A ( 0,0 ) = 1.0; |
---|
| 223 | A ( 1,1 ) = 1.0; |
---|
| 224 | } |
---|
| 225 | }; |
---|
| 226 | |
---|
[224] | 227 | /*!@}*/ |
---|
[33] | 228 | #endif //PMSM_H |
---|