root/tests/pmsm.h @ 33

Revision 33, 2.5 kB (checked in by smidl, 16 years ago)

Oprava PF a MPF + jejich implementace pro pmsm system

  • Property svn:eol-style set to native
Line 
1#ifndef PMSM_H
2#define PMSM_H
3
4RV rx ( "1 2 3 4", "{ia, ib, om, th}", ones_i ( 4 ), zeros_i ( 4 ));
5RV ru ( "5 6", "{ua, ub}", ones_i ( 2 ) ,zeros_i ( 2 ));
6RV ry ( "7 8", "{oia, oib}", ones_i ( 2 ) ,zeros_i ( 2 ));
7
8//! State evolution model for a PMSM drive and its derivative with respect to $x$
9class IMpmsm : public diffbifn {
10        double Rs, Ls, dt, Ypm, kp, p,  J, Mz;
11
12//TODO hardcoded RVs!!!
13public:
14        IMpmsm() :diffbifn ( rx, ru ) {};
15        //! Set mechanical and electrical variables
16        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;}
17
18        vec eval ( const vec &x0, const vec &u0 ) {
19                // last state
20                double iam = x0 ( 0 );
21                double ibm = x0 ( 1 );
22                double omm = x0 ( 2 );
23                double thm = x0 ( 3 );
24                double uam = u0 ( 0 );
25                double ubm = u0 ( 1 );
26
27                vec xk=zeros ( 4 );
28                //ia
29                xk ( 0 ) = ( 1.0- Rs/Ls*dt ) * iam + Ypm/Ls*dt*omm * sin ( thm ) + uam*dt/Ls;
30                //ib
31                xk ( 1 ) = ( 1.0- Rs/Ls*dt ) * ibm - Ypm/Ls*dt*omm * cos ( thm ) + ubm*dt/Ls;
32                //om
33                xk ( 2 ) = omm + kp*p*p * Ypm/J*dt* ( ibm * cos ( thm )-iam * sin ( thm ) ) - p/J*dt*Mz;
34                //th
35                xk ( 3 ) = rem(thm + omm*dt,2*pi);
36                return xk;
37        }
38
39        void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
40                double iam = x0 ( 0 );
41                double ibm = x0 ( 1 );
42                double omm = x0 ( 2 );
43                double thm = x0 ( 3 );
44                // d ia
45                A ( 0,0 ) = ( 1.0- Rs/Ls*dt ); A ( 0,1 ) = 0.0;
46                A ( 0,2 ) = Ypm/Ls*dt* sin ( thm ); A ( 0,3 ) = Ypm/Ls*dt*omm * ( cos ( thm ) );
47                // d ib
48                A ( 1,0 ) = 0.0 ; A ( 1,1 ) = ( 1.0- Rs/Ls*dt );
49                A ( 1,2 ) = -Ypm/Ls*dt* cos ( thm ); A ( 1,3 ) = Ypm/Ls*dt*omm * ( sin ( thm ) );
50                // d om
51                A ( 2,0 ) = kp*p*p * Ypm/J*dt* ( - sin ( thm ) );
52                A ( 2,1 ) = kp*p*p * Ypm/J*dt* ( cos ( thm ) );
53                A ( 2,2 ) = 1.0;
54                A ( 2,3 ) = kp*p*p * Ypm/J*dt* ( -ibm * sin ( thm )-iam * cos ( thm ) );
55                // d th
56                A ( 3,0 ) = 0.0; A ( 3,1 ) = 0.0; A ( 3,2 ) = dt; A ( 3,3 ) = 1.0;
57        }
58
59        void dfdu_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {it_error ( "not needed" );};
60
61};
62
63//! Observation model for PMSM drive and its derivative with respect to $x$
64class OMpmsm: public diffbifn {
65public:
66        OMpmsm() :diffbifn ( rx,ru ) {};
67
68        vec eval ( const vec &x0, const vec &u0 ) {
69                vec y ( 2 );
70                y ( 0 ) = x0 ( 0 );
71                y ( 1 ) = x0 ( 1 );
72                return y;
73        }
74
75        void dfdx_cond ( const vec &x0, const vec &u0, mat &A, bool full=true ) {
76                A.clear();
77                A ( 0,0 ) = 1.0;
78                A ( 1,1 ) = 1.0;
79        }
80};
81
82#endif //PMSM_H
Note: See TracBrowser for help on using the browser.