Show
Ignore:
Timestamp:
03/16/12 16:46:40 (12 years ago)
Author:
smidl
Message:

Funkcni 1D Kalman

Files:
1 modified

Legend:

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

    r1437 r1439  
    6565 
    6666// EKF - vysledek estimace 
    67 static double mpf_estim[2]={0.,0.};     // w_est, theta_est 
    68 static double Esinth, Ecosth; 
     67static floatx mpf_estim[2]={0.,0.};     // w_est, theta_est 
     68static floatx Esinth, Ecosth; 
    6969 
    7070FILE *fw; 
     
    115115  init_pmsm(param, REL1); 
    116116  init_regulace(param,h_reg); 
    117   mpf_init(1e0, 1e-5, 1e0);//VS: 
     117  mpf_init(1e0, 1e-3, 1e0);//VS: 
    118118 
    119119  fw=fopen("data/graf2.txt","w"); 
     
    161161 
    162162        if (t>0.7) Ww=2.*M_PI*10.; 
    163         if (t>1.0) x[8]=1.2;    // 1A 
    164         if (t>1.2) x[8]=10.8;   // 9A 
    165         if (t>1.4) x[8]=25.2;  // 21A 
     163//         if (t>1.0) x[8]=1.2;    // 1A 
     164//         if (t>1.2) x[8]=10.8;   // 9A 
     165//         if (t>1.4) x[8]=25.2;  // 21A 
    166166 
    167167        if (t>1.6) Ww=2.*M_PI*50.; 
    168         if (t>1.9) x[8]=1.2;    // 1A 
    169         if (t>2.1) x[8]=10.8;   // 9A 
    170         if (t>2.3) x[8]=25.2;  // 21A 
     168//         if (t>1.9) x[8]=1.2;    // 1A 
     169//         if (t>2.1) x[8]=10.8;   // 9A 
     170//         if (t>2.3) x[8]=25.2;  // 21A 
    171171 
    172172        if (t>2.5) Ww=2.*M_PI*100; 
    173         if (t>2.8) x[8]=1.2;    // 1A 
    174         if (t>3.0) x[8]=10.8;   // 9A 
    175         if (t>3.2) x[8]=25.2;  // 21A 
     173//         if (t>2.8) x[8]=1.2;    // 1A 
     174//         if (t>3.0) x[8]=10.8;   // 9A 
     175//         if (t>3.2) x[8]=25.2;  // 21A 
    176176 
    177177        if (t>3.4) Ww=2.*M_PI*150; 
    178         if (t>3.7) x[8]=1.2;    // 1A 
    179         if (t>3.9) x[8]=10.8;   // 9A 
    180         if (t>4.1) x[8]=25.2;  // 21A 
     178//         if (t>3.7) x[8]=1.2;    // 1A 
     179//         if (t>3.9) x[8]=10.8;   // 9A 
     180//         if (t>4.1) x[8]=25.2;  // 21A 
    181181 
    182182        if (t>4.3) Ww=2.*M_PI*0; 
    183         if (t>4.8) x[8]=-1.2;    // 1A 
    184         if (t>5.0) x[8]=-10.8;   // 9A 
    185         if (t>5.2) x[8]=-25.2;  // 21A 
     183//         if (t>4.8) x[8]=-1.2;    // 1A 
     184//         if (t>5.0) x[8]=-10.8;   // 9A 
     185//         if (t>5.2) x[8]=-25.2;  // 21A 
    186186 
    187187        if (t>5.4) Ww=2.*M_PI*(-10.); 
    188         if (t>5.7) x[8]=-1.2;    // 1A 
    189         if (t>5.9) x[8]=-10.8;   // 9A 
    190         if (t>6.1) x[8]=-25.2;  // 21A 
     188//         if (t>5.7) x[8]=-1.2;    // 1A 
     189//         if (t>5.9) x[8]=-10.8;   // 9A 
     190//         if (t>6.1) x[8]=-25.2;  // 21A 
    191191 
    192192        if (t>6.3) Ww=2.*M_PI*(-50.); 
    193         if (t>6.7) x[8]=-1.2;    // 1A 
    194         if (t>6.9) x[8]=-10.8;   // 9A 
    195         if (t>7.1) x[8]=-25.2;  // 21A 
     193//         if (t>6.7) x[8]=-1.2;    // 1A 
     194//         if (t>6.9) x[8]=-10.8;   // 9A 
     195//         if (t>7.1) x[8]=-25.2;  // 21A 
    196196 
    197197        if (t>7.3) Ww=2.*M_PI*(-100.); 
    198         if (t>7.7) x[8]=-1.2;    // 1A 
    199         if (t>7.9) x[8]=-10.8;   // 9A 
    200         if (t>8.1) x[8]=-25.2;  // 21A 
    201         if (t>8.3) x[8]=10.8;   // 9A 
    202         if (t>8.5) x[8]=25.2;  // 21A 
     198//         if (t>7.7) x[8]=-1.2;    // 1A 
     199//         if (t>7.9) x[8]=-10.8;   // 9A 
     200//         if (t>8.1) x[8]=-25.2;  // 21A 
     201//         if (t>8.3) x[8]=10.8;   // 9A 
     202//         if (t>8.5) x[8]=25.2;  // 21A 
    203203 
    204204 
     
    218218                if (x[2]<-1615) x[2]=-1615;  /**/ 
    219219                         
    220                 // KALMAN 
    221                Umk=*u*Uc/Ucn; 
     220        
     221      // KALMAN (pouzij stara Usx, Usy!! 
     222          if (0){ 
     223                mpf_bayes((floatx)Isx,(floatx)Isy,(floatx)Usx,(floatx)Usy); 
     224                mpf_mean(&Esinth,&Ecosth,&mpf_estim[0]); 
     225                mpf_estim[1]=atan2((floatx)Esinth,(floatx)Ecosth); 
     226          } else { 
     227                  mpf_estim[0]=kalman_om((floatx)Isx,(floatx)Isy,(floatx)Usx,(floatx)Usy,(floatx)x[3]); 
     228          } 
     229 
     230      Umk=*u*Uc/Ucn; 
    222231      ua=Umk*cos(*(u+1)); 
    223232      ub=Umk*cos(*(u+1)-2./3.*M_PI); 
    224233      Usx=ua;                     // usx 
    225234      Usy=(ua+2.*ub)/sqrt(3.);    // usy 
    226         
    227                 mpf_bayes(Isx,Isy,Usx,Usy); 
    228                 mpf_mean(&Esinth,&Ecosth,&mpf_estim[0]); 
    229                 mpf_estim[1]=atan2(Esinth,Ecosth); 
    230  
    231235                // vystup z EKF zaveden do regulatoru 
    232236                // rychlost=ekf_estim[0]; theta=ekf_estim[1]; //VS