Changeset 260 for pmsm

Show
Ignore:
Timestamp:
02/02/09 14:47:34 (15 years ago)
Author:
smidl
Message:

working UI example

Location:
pmsm
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • pmsm/pmsmDS.h

    r258 r260  
    1212 
    1313#include <stat/loggers.h> 
    14  
     14#include "simulator.h" 
    1515#include "pmsm.h" 
    16 #include "simulator.h" 
    17 #include <uibuilder.h> 
    1816 
    1917//! Simulator of PMSM machine with predefined profile on omega 
     
    2220protected: 
    2321        //! 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; 
    2523        //! Setpoints of omega in timespans given by dt_prof 
    2624        vec profileWw; 
     
    2927        //! Number of miliseconds per discrete time step 
    3028        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; 
    3132public: 
    32         pmsmDS ( int Dt0 ) : Dt ( Dt0 ) {} 
     33        //! Constructor with fixed sampling period 
     34        pmsmDS (string opt0="" ) : Dt ( 125 ), opt(opt0) {} 
    3335        void set_parameters ( double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0 ) { 
    3436                pmsmsim_set_parameters ( Rs0, Ls0, Fmag0, Bf0, p0, kp0, J0, Uc0, DT0, dt0 ); 
     
    4244                static double Ww; // W 
    4345                if ( t>=dt_prof*ind ) { 
     46                        ind++; 
    4447                        if ( ind<profileWw.length() ) { 
    45                                 ind++; 
    4648                                //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                                } 
    4855                        } 
    4956                        else { 
     
    5865        void log_add ( logger &L ) { 
    5966                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                } 
    6374        } 
    6475 
     
    6879                L.logit ( L_ou, vec_2 ( KalmanObs[0],KalmanObs[1] ) ); 
    6980                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                } 
    7199 
    72100        void set_profile ( double dt, const vec &Ww ) {dt_prof=dt; profileWw=Ww;} 
    73101}; 
    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); 
  • pmsm/sim.cpp

    r257 r260  
    1111*/ 
    1212 
    13 #include <uibuilder.h> 
    14 #include <stat/libDS.h> 
    15 #include "pmsmDS.h" 
    16  
     13#include "pmsm_ui.h" 
    1714#include <stat/loggers_ui.h> 
    1815 
     
    3532                DS->step(); 
    3633                DS->logit(*L); 
     34                L->step(); 
    3735        } 
    3836