Legend:
- Unmodified
- Added
- Removed
-
pmsm/pmsmDS.h
r258 r260 12 12 13 13 #include <stat/loggers.h> 14 14 #include "simulator.h" 15 15 #include "pmsm.h" 16 #include "simulator.h"17 #include <uibuilder.h>18 16 19 17 //! Simulator of PMSM machine with predefined profile on omega … … 22 20 protected: 23 21 //! indeces of logged variables 24 int L_x, L_ou, L_oy, L_iu ;22 int L_x, L_ou, L_oy, L_iu, L_optu; 25 23 //! Setpoints of omega in timespans given by dt_prof 26 24 vec profileWw; … … 29 27 //! Number of miliseconds per discrete time step 30 28 int Dt; 29 //! options for logging, string in which each character has a meaning: 30 //! \c u - log predictions of 'true' voltage 31 string opt; 31 32 public: 32 pmsmDS ( int Dt0 ) : Dt ( Dt0 ) {} 33 //! Constructor with fixed sampling period 34 pmsmDS (string opt0="" ) : Dt ( 125 ), opt(opt0) {} 33 35 void set_parameters ( double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0 ) { 34 36 pmsmsim_set_parameters ( Rs0, Ls0, Fmag0, Bf0, p0, kp0, J0, Uc0, DT0, dt0 ); … … 42 44 static double Ww; // W 43 45 if ( t>=dt_prof*ind ) { 46 ind++; 44 47 if ( ind<profileWw.length() ) { 45 ind++;46 48 //linear increase 47 dW = profileWw ( ind )-profileWw ( ind-1 ); 49 if ( profileWw.length() ==1 ) { 50 Ww=profileWw ( 0 ); dW=0.0;} 51 else { 52 dW = profileWw ( ind )-profileWw ( ind-1 ); 53 dW *=125e-6/dt_prof; 54 } 48 55 } 49 56 else { … … 58 65 void log_add ( logger &L ) { 59 66 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" ); 67 L_oy = L.add ( ry, "obs" ); 68 L_ou = L.add ( ru, "obs" ); 69 L_iu = L.add ( ru, "true" ); 70 // log differences 71 if (opt.find("u")==string::npos){ 72 L_optu = L.add(ru, "model"); 73 } 63 74 } 64 75 … … 68 79 L.logit ( L_ou, vec_2 ( KalmanObs[0],KalmanObs[1] ) ); 69 80 L.logit ( L_iu, vec_2 ( KalmanObs[4],KalmanObs[5] ) ); 70 } 81 if (opt.find("u")==string::npos){ 82 double sq3=sqrt(3.0); 83 double ua,ub; 84 double i1=x[0]; 85 double i2=0.5*(-i1+sq3*x[1]); 86 double i3=0.5*(-i1-sq3*x[1]); 87 double u1=KalmanObs[0]; 88 double u2=0.5*(-u1+sq3*KalmanObs[1]); 89 double u3=0.5*(-u1-sq3*KalmanObs[1]); 90 91 double du1=0.7*(double(i1>0.1) - double(i1<-0.1))+0.05*i1; 92 double du2=0.7*(double(i2>0.1) - double(i2<-0.1))+0.05*i2; 93 double du3=0.7*(double(i3>0.1) - double(i3<-0.1))+0.05*i3; 94 ua = (2.0*(u1-du1)-(u2-du2)-(u3-du3))/3.0; 95 ub = ((u2-du2)-(u3-du3))/sq3; 96 L.logit( L_optu , vec_2 (ua,ub)); 97 } 98 } 71 99 72 100 void set_profile ( double dt, const vec &Ww ) {dt_prof=dt; profileWw=Ww;} 73 101 }; 74 75 class UIpmsm: public UIbuilder {76 public:77 UIpmsm() :UIbuilder ( "pmsm" ) {}78 //Non-standard BUILD!! Does not create79 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 Settings94 UIcall<pmsmDS*> ( S["params"], &tmp_set , tmp );95 };96 97 };98 UIREGISTER(UIpmsmDS); -
pmsm/sim.cpp
r257 r260 11 11 */ 12 12 13 #include <uibuilder.h> 14 #include <stat/libDS.h> 15 #include "pmsmDS.h" 16 13 #include "pmsm_ui.h" 17 14 #include <stat/loggers_ui.h> 18 15 … … 35 32 DS->step(); 36 33 DS->logit(*L); 34 L->step(); 37 35 } 38 36