- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

# pmsmDS.h

Go to the documentation of this file.

    00001
    00013 #include <stat/loggers.h>
    00014 #include "simulator.h"
    00015 #include "pmsm.h"
    00016
    00018 class pmsmDS : public DS {
    00019
    00020 protected:
    00022         int L_x, L_ou, L_oy, L_iu, L_optu;
    00024         vec profileWw;
    00026         double dt_prof;
    00028         int Dt;
    00030         bool opt_modu;
    00031 public:
    00033         pmsmDS ()   {Dt=125; Drv=RV ( "{o_ua o_ub o_ia o_ib t_ua t_ub }" );}
    00034         void set_parameters ( double Rs0, double Ls0, double Fmag0, double Bf0, double p0, double kp0, double J0, double Uc0, double DT0, double dt0 ) {
    00035                 pmsmsim_set_parameters ( Rs0, Ls0, Fmag0, Bf0, p0, kp0, J0, Uc0, DT0, dt0 );
    00036         }
    00038         void set_options ( string &opt ) {
    00039                 opt_modu = ( opt.find ( "modelu" ) ==string::npos );
    00040         }
    00041         void getdata ( vec &dt ) {dt=vec ( KalmanObs,6 );}
    00042         void write ( vec &ut ) {}
    00043
    00044         void step() {
    00045                 static int ind=0;
    00046                 static double dW; // increase of W
    00047                 static double Ww; // W
    00048                 if ( t>=dt_prof*ind ) {
    00049                         ind++;
    00050                         if ( ind<profileWw.length() ) {
    00051                                 //linear increase
    00052                                 if ( profileWw.length() ==1 ) {
    00053                                         Ww=profileWw ( 0 ); dW=0.0;
    00054                                 }
    00055                                 else {
    00056                                         dW = profileWw ( ind )-profileWw ( ind-1 );
    00057                                         dW *=125e-6/dt_prof;
    00058                                 }
    00059                         }
    00060                         else {
    00061                                 dW = 0;
    00062                         }
    00063                 }
    00064                 Ww += dW;
    00065                 //Simulate Dt seconds!
    00066                 for ( int i=0;i<Dt;i++ ) {      pmsmsim_step ( Ww );}
    00067         };
    00068
    00069         void log_add ( logger &L ) {
    00070                 L_x = L.add ( rx, "x" );
    00071                 L_oy = L.add ( ry, "o" );
    00072                 L_ou = L.add ( ru, "o" );
    00073                 L_iu = L.add ( ru, "t" );
    00074                 // log differences
    00075                 if ( opt_modu ) {
    00076                         L_optu = L.add ( ru, "model" );
    00077                 }
    00078         }
    00079
    00080         void logit ( logger &L ) {
    00081                 L.logit ( L_x, vec ( x,4 )      );
    00082                 L.logit ( L_oy, vec_2 ( KalmanObs[2],KalmanObs[3] ) );
    00083                 L.logit ( L_ou, vec_2 ( KalmanObs[0],KalmanObs[1] ) );
    00084                 L.logit ( L_iu, vec_2 ( KalmanObs[4],KalmanObs[5] ) );
    00085                 if ( opt_modu ) {
    00086                         double sq3=sqrt ( 3.0 );
    00087                         double ua,ub;
    00088                         double i1=x[0];
    00089                         double i2=0.5* ( -i1+sq3*x[1] );
    00090                         double i3=0.5* ( -i1-sq3*x[1] );
    00091                         double u1=KalmanObs[0];
    00092                         double u2=0.5* ( -u1+sq3*KalmanObs[1] );
    00093                         double u3=0.5* ( -u1-sq3*KalmanObs[1] );
    00094
    00095                         double du1=0.7* ( double ( i1>0.1 ) - double ( i1<-0.1 ) ) +0.05*i1;
    00096                         double du2=0.7* ( double ( i2>0.1 ) - double ( i2<-0.1 ) ) +0.05*i2;
    00097                         double du3=0.7* ( double ( i3>0.1 ) - double ( i3<-0.1 ) ) +0.05*i3;
    00098                         ua = ( 2.0* ( u1-du1 )- ( u2-du2 )- ( u3-du3 ) ) /3.0;
    00099                         ub = ( ( u2-du2 )- ( u3-du3 ) ) /sq3;
    00100                         L.logit ( L_optu , vec_2 ( ua,ub ) );
    00101                 }
    00102         }
    00103
    00104         void set_profile ( double dt, const vec &Ww ) {dt_prof=dt; profileWw=Ww;}
    00105 };