root/tests/pmsm.h @ 62

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

nova simulace s EKFfixed a novy EKF na plnych maticich

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