root/pmsm/pmsm.h @ 240

Revision 240, 7.1 kB (checked in by smidl, 15 years ago)

mpf_u_delta with Q proportional to x2o2

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