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 | |
---|
15 | #include "pmsm.h" |
---|
16 | #include "simulator.h" |
---|
17 | #include <uibuilder.h> |
---|
18 | |
---|
19 | //! Simulator of PMSM machine with predefined profile on omega |
---|
20 | class pmsmDS : public DS { |
---|
21 | |
---|
22 | protected: |
---|
23 | //! indeces of logged variables |
---|
24 | int L_x, L_ou, L_oy, L_iu; |
---|
25 | //! Setpoints of omega in timespans given by dt_prof |
---|
26 | vec profileWw; |
---|
27 | //! time-step for profiles |
---|
28 | double dt_prof; |
---|
29 | //! Number of miliseconds per discrete time step |
---|
30 | int Dt; |
---|
31 | public: |
---|
32 | pmsmDS ( int Dt0 ) : Dt ( Dt0 ) {} |
---|
33 | void set_parameters ( double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0 ) { |
---|
34 | pmsmsim_set_parameters ( Rs0, Ls0, Fmag0, Bf0, p0, kp0, J0, Uc0, DT0, dt0 ); |
---|
35 | } |
---|
36 | void getdata ( vec &dt ) {dt=vec ( KalmanObs,6 );} |
---|
37 | void write ( vec &ut ) {} |
---|
38 | |
---|
39 | void step() { |
---|
40 | static int ind=0; |
---|
41 | static double dW; // increase of W |
---|
42 | static double Ww; // W |
---|
43 | if ( t>=dt_prof*ind ) { |
---|
44 | if ( ind<profileWw.length() ) { |
---|
45 | ind++; |
---|
46 | //linear increase |
---|
47 | dW = profileWw ( ind )-profileWw ( ind-1 ); |
---|
48 | } |
---|
49 | else { |
---|
50 | dW = 0; |
---|
51 | } |
---|
52 | } |
---|
53 | Ww += dW; |
---|
54 | //Simulate Dt seconds! |
---|
55 | for ( int i=0;i<Dt;i++ ) { pmsmsim_step ( Ww );} |
---|
56 | }; |
---|
57 | |
---|
58 | void log_add ( logger &L ) { |
---|
59 | L_x = L.add ( rx, "x" ); |
---|
60 | L_oy = L.add ( ry, "oi" ); |
---|
61 | L_ou = L.add ( ru, "ou" ); |
---|
62 | L_iu = L.add ( ru, "iu" ); |
---|
63 | } |
---|
64 | |
---|
65 | void logit ( logger &L ) { |
---|
66 | L.logit ( L_x, vec ( x,4 ) ); |
---|
67 | L.logit ( L_oy, vec_2 ( KalmanObs[2],KalmanObs[3] ) ); |
---|
68 | L.logit ( L_ou, vec_2 ( KalmanObs[0],KalmanObs[1] ) ); |
---|
69 | L.logit ( L_iu, vec_2 ( KalmanObs[4],KalmanObs[5] ) ); |
---|
70 | } |
---|
71 | |
---|
72 | void set_profile ( double dt, const vec &Ww ) {dt_prof=dt; profileWw=Ww;} |
---|
73 | }; |
---|
74 | |
---|
75 | class UIpmsm: public UIbuilder { |
---|
76 | public: |
---|
77 | UIpmsm() :UIbuilder ( "pmsm" ) {} |
---|
78 | //Non-standard BUILD!! Does not create |
---|
79 | void build ( Setting &S, void** result ) const { |
---|
80 | |
---|
81 | }; |
---|
82 | }; |
---|
83 | |
---|
84 | class UIpmsmDS: public UIbuilder { |
---|
85 | static void tmp_set ( Setting &S, pmsmDS* tmp ) { |
---|
86 | tmp->set_parameters ( S["Rs"], S["Ls"], S["Fmag"], S["Bf"], S["p"], S["kp"], \ |
---|
87 | S["J"], S["Uc"], S["DT"], 1.0e-6 ); |
---|
88 | }; |
---|
89 | public: |
---|
90 | UIpmsmDS() :UIbuilder ( "pmsmDS" ) {}; |
---|
91 | bdmroot* build ( Setting &S ) const { |
---|
92 | pmsmDS* tmp = new pmsmDS ( S["DT"] ); |
---|
93 | //allowing recursive Settings |
---|
94 | UIcall<pmsmDS*> ( S["params"], &tmp_set , tmp ); |
---|
95 | }; |
---|
96 | |
---|
97 | }; |
---|
98 | UIREGISTER(UIpmsmDS); |
---|