1 | #ifndef PMSM_H |
---|
2 | #define PMSM_H |
---|
3 | |
---|
4 | #include <stat/libFN.h> |
---|
5 | |
---|
6 | //TODO hardcoded RVs!!! |
---|
7 | RV rx ( "1 2 3 4", "{ia ib om th }", ones_i ( 4 ), zeros_i ( 4 )); |
---|
8 | RV ru ( "5 6", "{ua ub }", ones_i ( 2 ) ,zeros_i ( 2 )); |
---|
9 | RV ry ( "7 8", "{oia oib }", ones_i ( 2 ) ,zeros_i ( 2 )); |
---|
10 | |
---|
11 | // class uipmsm : public uibase{ |
---|
12 | // double Rs, Ls, dt, Ypm, kp, p, J, Mz; |
---|
13 | // }; |
---|
14 | |
---|
15 | //! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$$ |
---|
16 | class IMpmsm : public diffbifn { |
---|
17 | protected: |
---|
18 | double Rs, Ls, dt, Ypm, kp, p, J, Mz; |
---|
19 | |
---|
20 | public: |
---|
21 | IMpmsm() :diffbifn (rx.count(), rx, ru ) {}; |
---|
22 | //! Set mechanical and electrical variables |
---|
23 | 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;} |
---|
24 | |
---|
25 | vec eval ( const vec &x0, const vec &u0 ) { |
---|
26 | // last state |
---|
27 | double iam = x0 ( 0 ); |
---|
28 | double ibm = x0 ( 1 ); |
---|
29 | double omm = x0 ( 2 ); |
---|
30 | double thm = x0 ( 3 ); |
---|
31 | double uam = u0 ( 0 ); |
---|
32 | double ubm = u0 ( 1 ); |
---|
33 | |
---|
34 | vec xk=zeros ( 4 ); |
---|
35 | //ia |
---|
36 | xk ( 0 ) = ( 1.0- Rs/Ls*dt ) * iam + Ypm/Ls*dt*omm * sin ( thm ) + uam*dt/Ls; |
---|
37 | //ib |
---|
38 | xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls; |
---|
39 | //om |
---|
40 | xk ( 2 ) = omm + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz; |
---|
41 | //th |
---|
42 | xk ( 3 ) = thm + omm*dt; // <0..2pi> |
---|
43 | if ( xk ( 3 ) >pi ) xk ( 3 )-=2*pi; |
---|
44 | if ( xk ( 3 ) <-pi ) xk ( 3 ) +=2*pi; |
---|
45 | return xk; |
---|
46 | } |
---|
47 | |
---|
48 | void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { |
---|
49 | double iam = x0 ( 0 ); |
---|
50 | double ibm = x0 ( 1 ); |
---|
51 | double omm = x0 ( 2 ); |
---|
52 | double thm = x0 ( 3 ); |
---|
53 | // d ia |
---|
54 | A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0; |
---|
55 | A ( 0,2 ) = Ypm/Ls*dt* sin ( thm ); A ( 0,3 ) = Ypm/Ls*dt*omm * ( cos ( thm ) ); |
---|
56 | // d ib |
---|
57 | A ( 1,0 ) = 0.0 ; A ( 1,1 ) = ( 1.0- Rs/Ls*dt ); |
---|
58 | A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) ); |
---|
59 | // d om |
---|
60 | A ( 2,0 ) = kp*p*p * Ypm/J*dt* ( - sin ( thm ) ); |
---|
61 | A ( 2,1 ) = kp*p*p * Ypm/J*dt* ( cos ( thm ) ); |
---|
62 | A ( 2,2 ) = 1.0; |
---|
63 | A ( 2,3 ) = kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) ); |
---|
64 | // d th |
---|
65 | A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0; |
---|
66 | } |
---|
67 | |
---|
68 | void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );}; |
---|
69 | |
---|
70 | }; |
---|
71 | |
---|
72 | //! State evolution model for a PMSM drive and its derivative with respect to \f$x\f$, equation for \f$\omega\f$ is omitted.$ |
---|
73 | class IMpmsmStat : public IMpmsm { |
---|
74 | IMpmsmStat() :IMpmsm() {}; |
---|
75 | //! Set mechanical and electrical variables |
---|
76 | 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;} |
---|
77 | |
---|
78 | vec eval ( const vec &x0, const vec &u0 ) { |
---|
79 | // last state |
---|
80 | double iam = x0 ( 0 ); |
---|
81 | double ibm = x0 ( 1 ); |
---|
82 | double omm = x0 ( 2 ); |
---|
83 | double thm = x0 ( 3 ); |
---|
84 | double uam = u0 ( 0 ); |
---|
85 | double ubm = u0 ( 1 ); |
---|
86 | |
---|
87 | vec xk=zeros ( 4 ); |
---|
88 | //ia |
---|
89 | xk ( 0 ) = ( 1.0- Rs/Ls*dt ) * iam + Ypm/Ls*dt*omm * sin ( thm ) + uam*dt/Ls; |
---|
90 | //ib |
---|
91 | xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls; |
---|
92 | //om |
---|
93 | xk ( 2 ) = omm;// + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz; |
---|
94 | //th |
---|
95 | xk ( 3 ) = rem(thm + omm*dt,2*pi); // <0..2pi> |
---|
96 | return xk; |
---|
97 | } |
---|
98 | |
---|
99 | void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { |
---|
100 | // double iam = x0 ( 0 ); |
---|
101 | // double ibm = x0 ( 1 ); |
---|
102 | double omm = x0 ( 2 ); |
---|
103 | double thm = x0 ( 3 ); |
---|
104 | // d ia |
---|
105 | A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0; |
---|
106 | A ( 0,2 ) = Ypm/Ls*dt* sin ( thm ); A ( 0,3 ) = Ypm/Ls*dt*omm * ( cos ( thm ) ); |
---|
107 | // d ib |
---|
108 | A ( 1,0 ) = 0.0 ; A ( 1,1 ) = ( 1.0- Rs/Ls*dt ); |
---|
109 | A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) ); |
---|
110 | // d om |
---|
111 | A ( 2,0 ) = 0.0;//kp*p*p * Ypm/J*dt* ( - sin ( thm ) ); |
---|
112 | A ( 2,1 ) = 0.0;//kp*p*p * Ypm/J*dt* ( cos ( thm ) ); |
---|
113 | A ( 2,2 ) = 1.0; |
---|
114 | A ( 2,3 ) = 0.0;//kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) ); |
---|
115 | // d th |
---|
116 | A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0; |
---|
117 | } |
---|
118 | |
---|
119 | void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );}; |
---|
120 | |
---|
121 | }; |
---|
122 | |
---|
123 | //! Observation model for PMSM drive and its derivative with respect to \f$x\f$ |
---|
124 | class OMpmsm: public diffbifn { |
---|
125 | public: |
---|
126 | OMpmsm() :diffbifn (2, rx,ru ) {}; |
---|
127 | |
---|
128 | vec eval ( const vec &x0, const vec &u0 ) { |
---|
129 | vec y ( 2 ); |
---|
130 | y ( 0 ) = x0 ( 0 ); |
---|
131 | y ( 1 ) = x0 ( 1 ); |
---|
132 | return y; |
---|
133 | } |
---|
134 | |
---|
135 | void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) { |
---|
136 | A.clear(); |
---|
137 | A ( 0,0 ) = 1.0; |
---|
138 | A ( 1,1 ) = 1.0; |
---|
139 | } |
---|
140 | }; |
---|
141 | |
---|
142 | #endif //PMSM_H |
---|