root/pmsm/pmsmDS.h @ 282

Revision 280, 3.0 kB (checked in by smidl, 15 years ago)

progress...

  • Property svn:eol-style set to native
Line 
1/*!
2  \file
3  \brief DataSource for experiments with realistic simulator of the PMSM model
4  \author Vaclav Smidl.
5
6  -----------------------------------
7  BDM++ - C++ library for Bayesian Decision Making under Uncertainty
8
9  Using IT++ for numerical operations
10  -----------------------------------
11*/
12
13#include <stat/loggers.h>
14#include "simulator.h"
15#include "pmsm.h"
16
17//! Simulator of PMSM machine with predefined profile on omega
18class pmsmDS : public DS {
19
20protected:
21        //! indeces of logged variables
22        int L_x, L_ou, L_oy, L_iu, L_optu;
23        //! Setpoints of omega in timespans given by dt_prof
24        vec profileWw;
25        //! time-step for profiles
26        double dt_prof;
27        //! Number of miliseconds per discrete time step
28        int Dt;
29        //! options for logging, - log predictions of 'true' voltage
30        bool opt_modu;
31public:
32        //! Constructor with fixed sampling period
33        pmsmDS ()   {Dt=125; Drv=RV ( "{o_ua o_ub o_ia o_ib t_ua t_ub }" );}
34        void set_parameters ( double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0 ) {
35                pmsmsim_set_parameters ( Rs0, Ls0, Fmag0, Bf0, p0, kp0, J0, Uc0, DT0, dt0 );
36        }
37        //! parse options: "modelu" => opt_modu=true;
38        void set_options ( string &opt ) {
39                opt_modu = ( opt.find ( "modelu" ) ==string::npos );
40        }
41        void getdata ( vec &dt ) {dt=vec ( KalmanObs,6 );}
42        void write ( vec &ut ) {}
43
44        void step() {
45                static int ind=0;
46                static double dW; // increase of W
47                static double Ww; // W
48                if ( t>=dt_prof*ind ) {
49                        ind++;
50                        if ( ind<profileWw.length() ) {
51                                //linear increase
52                                if ( profileWw.length() ==1 ) {
53                                        Ww=profileWw ( 0 ); dW=0.0;
54                                }
55                                else {
56                                        dW = profileWw ( ind )-profileWw ( ind-1 );
57                                        dW *=125e-6/dt_prof;
58                                }
59                        }
60                        else {
61                                dW = 0;
62                        }
63                }
64                Ww += dW;
65                //Simulate Dt seconds!
66                for ( int i=0;i<Dt;i++ ) {      pmsmsim_step ( Ww );}
67        };
68
69        void log_add ( logger &L ) {
70                L_x = L.add ( rx, "x" );
71                L_oy = L.add ( ry, "o" );
72                L_ou = L.add ( ru, "o" );
73                L_iu = L.add ( ru, "t" );
74                // log differences
75                if ( opt_modu ) {
76                        L_optu = L.add ( ru, "model" );
77                }
78        }
79
80        void logit ( logger &L ) {
81                L.logit ( L_x, vec ( x,4 )      );
82                L.logit ( L_oy, vec_2 ( KalmanObs[2],KalmanObs[3] ) );
83                L.logit ( L_ou, vec_2 ( KalmanObs[0],KalmanObs[1] ) );
84                L.logit ( L_iu, vec_2 ( KalmanObs[4],KalmanObs[5] ) );
85                if ( opt_modu ) {
86                        double sq3=sqrt ( 3.0 );
87                        double ua,ub;
88                        double i1=x[0];
89                        double i2=0.5* ( -i1+sq3*x[1] );
90                        double i3=0.5* ( -i1-sq3*x[1] );
91                        double u1=KalmanObs[0];
92                        double u2=0.5* ( -u1+sq3*KalmanObs[1] );
93                        double u3=0.5* ( -u1-sq3*KalmanObs[1] );
94
95                        double du1=0.7* ( double ( i1>0.1 ) - double ( i1<-0.1 ) ) +0.05*i1;
96                        double du2=0.7* ( double ( i2>0.1 ) - double ( i2<-0.1 ) ) +0.05*i2;
97                        double du3=0.7* ( double ( i3>0.1 ) - double ( i3<-0.1 ) ) +0.05*i3;
98                        ua = ( 2.0* ( u1-du1 )- ( u2-du2 )- ( u3-du3 ) ) /3.0;
99                        ub = ( ( u2-du2 )- ( u3-du3 ) ) /sq3;
100                        L.logit ( L_optu , vec_2 ( ua,ub ) );
101                }
102        }
103
104        void set_profile ( double dt, const vec &Ww ) {dt_prof=dt; profileWw=Ww;}
105};
Note: See TracBrowser for help on using the browser.