Show
Ignore:
Timestamp:
04/25/09 22:22:00 (15 years ago)
Author:
smidl
Message:

pmsm + UI for EKF

Location:
applications/pmsm/simulator_zdenek
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • applications/pmsm/simulator_zdenek/ekf_example/simul.cpp

    r278 r326  
    2222#define CHYBA_POLOHY    (0./180.*M_PI)  // chyba +/-8 stupnu elektrickych pro senzorovany loziskovy stit 
    2323 
    24 #define MODULACE        1       // 0...sinusova PWM, 1...PWM se 3.harmonickou 
     24#define MODULACE        0       // 0...sinusova PWM, 1...PWM se 3.harmonickou 
    2525#define REZIM_REGULACE  1       // 0...reg. momentu, 1...reg.rychlosti, 2... Isqw=sqrt(Imax^2-Id^2) - max. moment 
    2626 
  • applications/pmsm/simulator_zdenek/simulator.cpp

    r318 r326  
    77   Z. Peroutka 
    88 
    9 Rev. 16.3.2008 
     9Rev. 25.4.2009 
    1010 
    1111*/ 
     
    1313#define _USE_MATH_DEFINES 
    1414 
     15#include <stdio.h> 
    1516#include <math.h> 
    1617#include <stdlib.h> //na linuxu je abs v stdlib 
     
    7778static double ualfa=0., ubeta=0.; 
    7879 
     80// PWM - improvement of dead-time effect emulation 
     81static unsigned int start_pwm=1; 
     82static int uact[3]={1,1,1}; 
     83static int ureq[3]={1,1,1}; 
     84static unsigned int DT_counter[3]={0,0,0}; 
     85static unsigned int DT_counter_mez; 
     86 
     87// debug 
     88static double debug_pwm; 
     89FILE *fdebug; 
    7990 
    8091/////////////////// POMOCNE FUNKCE ////////////////////////////////// 
     
    137148  citac2=abs(0-(int)(DT/h)); //VS: oprava, je to spravne? 
    138149  citac_PR=h_reg_counter_mez; 
     150  DT_counter_mez = (int)(DT/h); 
    139151 
    140152  // first interrupt occur after first period match => add 1 to both counter registers 
     
    142154  citac2--; 
    143155 
    144   modulace=1;           // THIPWM 
     156  modulace=0;           // THIPWM 
    145157  if (modulace==1) 
    146158    U_modulace=Ucn/sqrt(3.); 
     
    154166 
    155167  init_regulace(Ls,Fmag,kp,p,h_reg_real); 
     168   
     169  // !!d!! 
     170//  fdebug=fopen("data_debug.txt","w"); 
    156171} 
    157172 
     
    172187  // emulation of carrier - timer 
    173188  up=((double)citac/citac_PR-0.5)*Ucn; 
    174   up2=((double)citac2/citac_PR-0.5)*Ucn; 
    175  
     189     
    176190  iabc[0]=*x; 
    177191  iabc[1]=(-*x+sqrt(3.)**(x+1))/2.; 
     
    196210    dd[i]=dtr[i]*.73; 
    197211  } 
    198  
    199   // implementation of voltage drops and dead-times 
     212   
     213  // mitigation of the voltage drops 
     214/* for (i=0;i<3;i++) 
     215 { 
     216   dtr[i]=0.; 
     217   dd[i]=0.; 
     218 } 
     219/**/  
     220  
     221 // PWM compare emulation 
    200222  for (i=0;i<3;i++) 
    201     if (iabc[i]>=0) 
    202       if ((ur[i]>up) && (ur[i]>up2)) 
    203         ustr[i]=Uc/2-dtr[i]; 
     223          if (ur[i]>up) 
     224                  ureq[i]=1; 
    204225      else 
    205         ustr[i]=-(Uc/2+dd[i]); 
     226                  ureq[i]=-1; 
     227 
     228  // First entrace into PWM - actual switching combination is initiated with required switching state 
     229  if (start_pwm == 1) 
     230  {        
     231          for (i=0;i<3;i++) 
     232                  uact[i]=ureq[i]; 
     233          start_pwm=0; 
     234  } 
     235   
     236  // Dead-time effect has no impact on switching combination, when switching from transistor to diode 
     237  for (i=0;i<3;i++) 
     238  { 
     239          if ((iabc[i]>0.5) && (uact[i]==1)) 
     240            uact[i]=ureq[i]; 
     241                   
     242          if ((iabc[i]<-0.5) && (uact[i]==-1)) 
     243            uact[i]=ureq[i]; 
     244  } 
     245/**/ 
     246     
     247/*  for (i=0;i<3;i++) 
     248          uact[i]=ureq[i];*/ 
     249   
     250  // Dead-time effect emulation 
     251  for (i=0;i<3;i++) 
     252    if ((uact[i]!=ureq[i]) && (DT_counter[i]<DT_counter_mez)) 
     253      DT_counter[i]++; 
    206254    else 
    207       if ((ur[i]<up) && (ur[i]<up2)) 
    208         ustr[i]=-(Uc/2-dtr[i]); 
    209       else 
    210         ustr[i]=Uc/2+dd[i]; 
    211  
    212 // phase voltages 
     255        { 
     256          uact[i]=ureq[i]; 
     257          DT_counter[i]=0; 
     258        } 
     259         
     260        // inverter phase voltage computation 
     261        for (i=0;i<3;i++) 
     262                ustr[i]=uact[i]*Uc/2.; 
     263         
     264        // implementation of voltage drops 
     265        for (i=0;i<3;i++) 
     266          if (iabc[i]>0) 
     267                if (uact[i]==1) 
     268                  ustr[i]-=dtr[i]; 
     269            else 
     270                  ustr[i]-=dd[i]; 
     271          else 
     272                if (uact[i]==-1) 
     273                  ustr[i]+=dtr[i]; 
     274            else 
     275                  ustr[i]+=dd[i]; 
     276/**/   
     277  // phase voltages 
    213278  ua=(2.*ustr[0]-ustr[1]-ustr[2])/3.; 
    214279  ub=(2.*ustr[1]-ustr[0]-ustr[2])/3.; 
     
    218283  *us=(2.*ua-ub-uc)/3.; 
    219284  *(us+1)=(ub-uc)/sqrt(3.); 
     285   
     286  // sinusoidal inverter!!!! 
     287//  *us=ur[0]; 
     288//  *(us+1)=(ur[1]-ur[2])/sqrt(3.); 
    220289 
    221290  // emulation of DSP timers 
     
    253322  sum_isx_av+=*x; 
    254323  sum_isy_av+=*(x+1); 
     324   
     325  debug_pwm = ur[0]; // !!!! 
     326  // !!d!! 
     327//  fprintf(fdebug,"%f %f %f \n",ustr[0],*us,x[0]); 
    255328} 
    256329 
     
    349422//       ualfa=Umk*cos(*(u+1)); 
    350423//       ub=Umk*cos(*(u+1)-2./3.*M_PI); 
    351       KalmanObs[0]=ualfa;                     // usx 
     424      KalmanObs[0]=ualfa; //debug_pwm;                     // usx 
    352425      //KalmanObs[1]=(ualfa+2.*ub)/sqrt(3.);    // usy 
    353426      KalmanObs[1]=ubeta;    // usy 
     
    368441      KalmanObs[9]=isy_av;       
    369442 
    370       vektor_regulace(0,0,Urm_max,Ww,u,Isx,Isy,theta,speed,U_modulace,Uc,Ucn,REZIM_REGULACE);   // rezim=1 ... reg. rychlosti, rezim=0 ... reg. momentu 
     443       vektor_regulace(0,0,Urm_max,Ww,u,Isx,Isy,theta,speed,U_modulace,Uc,Ucn,REZIM_REGULACE);  // rezim=1 ... reg. rychlosti, rezim=0 ... reg. momentu 
    371444                                                                                                                // rezim=2 ... Iqw=sqrt(Imax^2-Idw^2) 
    372       // emulation of the real sampling of A/D converter 
     445       
     446/*        *u=2*15.0; 
     447          *(u+1)+=2*0.00157;*/ 
     448// emulation of the real sampling of A/D converter 
    373449      Isx=x[0];Isy=x[1];speed=x[2];theta=x[3]; 
    374450 
    375451      // include ideal commanded stator voltage  
    376       Umk=*u*Uc/Ucn; 
     452      Umk=*u*Uc/Ucn;// !!!! 
    377453      ualfa=Umk*cos(*(u+1));               // usx = usa 
    378454      ub=Umk*cos(*(u+1)-2./3.*M_PI); 
     
    393469  double kor_Uc; 
    394470 
    395   *u=sqrt(ua*ua+ub*ub); 
    396   *(u+1)=uhel(ua,ub); 
    397  
     471   *u=sqrt(ua*ua+ub*ub); 
     472   *(u+1)=uhel(ua,ub); 
     473   
     474/*  *u=5.0; 
     475  *(u+1)+=0.00157;*/ 
    398476  // uprava velikosti vzhledem k Uc!=Ucn 
    399477  kor_Uc=Ucn/230.;