Changeset 1439 for applications

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

Funkcni 1D Kalman

Location:
applications/pmsm/simulator_zdenek/ekf_example
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • applications/pmsm/simulator_zdenek/ekf_example/data/kresli_odhad.m

    r1382 r1439  
    1 load graf1.txt -ascii 
     1%load graf1.txt -ascii 
    22load graf2.txt -ascii 
    33 
  • applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.cpp

    r1380 r1439  
    11211121        PSI[3]=0x7FFF; 
    11221122} 
     1123 
  • applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.h

    r1381 r1439  
    578578                }; 
    579579        void bayes ( const vec &val, const vec &cond ) { 
    580                 const double &isa = val(0); 
     580/*              const double &isa = val(0); 
    581581                const double &isb = val(1); 
    582582                const double &usa = cond(0); 
    583                 const double &usb = cond(1); 
    584                 mpf_bayes(isa,isb,usa,usb); 
     583                const double &usb = cond(1);*/ 
     584                mpf_bayes((floatx)val(0),(floatx)val(1),(floatx)cond(0), (floatx)cond(1));//isa,isb,usa,usb); 
    585585        } 
    586586         
    587587        class mp:public epdf{ 
     588                LOG_LEVEL(mp,logth); 
    588589        public: 
    589                 mp():epdf(){set_dim(3);} 
     590                mp():epdf(){set_dim(3);         log_level[logth]=true; 
     591} 
    590592                vec sample() const {return zeros(3);} 
    591593                double evallog(const vec &v) const {return 0.0;} 
    592                 vec mean() const {vec tmp(3); mpf_mean(tmp._data(), tmp._data()+1, tmp._data()+2); return tmp;} 
     594                vec mean() const {vec tmp(3);  
     595                        floatx es,ec,eo; 
     596                        mpf_mean(&es, &ec, &eo);  
     597                        tmp(0)=es;tmp(1)=ec;tmp(2)=eo; 
     598                        return tmp; 
     599                } 
    593600                vec variance() const {return zeros(3);} 
     601                void log_register ( bdm::logger& L, const string& prefix ) { 
     602                        epdf::log_register ( L, prefix ); 
     603                        if ( log_level[logth] ) { 
     604                                int th_dim = N; // dimension - dimension of cov 
     605                                L.add_vector( log_level, logth, RV ( th_dim ), prefix ); 
     606                        } 
     607                } 
     608                void log_write() const { 
     609                        epdf::log_write(); 
     610                        if ( log_level[logth] ) { 
     611                                floatx Th[N]; 
     612                                mpf_th(Th); 
     613                                vec th(N);  
     614                                for(int i=0;i<N;i++){th(i)=Th[i];} 
     615                                log_level.store( logth, th ); 
     616                        } 
     617                } 
    594618        }; 
    595619         
     
    598622         
    599623        void from_setting(const Setting &set){ 
    600                 BM::from_setting(set); 
     624            BM::from_setting(set); 
     625                UI::get ( log_level, set, "log_level", UI::optional ); 
     626 
    601627                UI::get(qom,set,"qom",UI::optional); 
    602628                UI::get(qth,set,"qth",UI::optional); 
     
    604630        } 
    605631        void validate(){ 
    606                 mpf_init(qom,qth,r); 
     632                mpf_init((floatx)qom,(floatx)qth,(floatx)r); 
    607633                 
    608634        } 
  • applications/pmsm/simulator_zdenek/ekf_example/mpf_double.cpp

    r1438 r1439  
    22#include "math.h" 
    33#include <stdio.h> 
    4  
    5 static double om[N]; 
    6 static double Pt[N]; 
    7 static double sth[N]; 
    8 static double cth[N]; 
    9 static double isdm[N]; 
    10 static double isqm[N]; 
    11 static double th[N]; 
    12 static double w[N]; 
    13 static double lwi[N]; 
    14  
    15 static double qth; 
    16 static double qom; 
    17 static double r; 
     4//#include <libconfig/lib/grammar.y> 
     5 
     6static floatx om[N]; 
     7static floatx Pt[N]; 
     8static floatx sth[N]; 
     9static floatx cth[N]; 
     10static floatx isdm[N]; 
     11static floatx isqm[N]; 
     12static floatx th[N]; 
     13static floatx w[N]; 
     14static floatx lwi[N]; 
     15 
     16static floatx qth; 
     17static floatx qom; 
     18static floatx r; 
     19 
    1820 
    1921#define MAXrand 100 
    2022#define MAXrandn 100 
    21 static const double RArandu[MAXrand]={0.8147, 0.9058, 0.1270, 0.9134, 0.6324, 0.0975, 0.2785, 0.5469, 0.9575, 0.9649, 
     23static const floatx RArandu[MAXrand]={0.8147, 0.9058, 0.1270, 0.9134, 0.6324, 0.0975, 0.2785, 0.5469, 0.9575, 0.9649, 
    2224                                      0.1576, 0.9706, 0.9572, 0.4854, 0.8003, 0.1419, 0.4218, 0.9157, 0.7922, 0.9595, 0.6557, 0.0357, 
    2325                                      0.8491, 0.9340, 0.6787, 0.7577, 0.7431, 0.3922, 0.6555, 0.1712, 0.7060, 0.0318, 0.2769, 0.0462, 
     
    2931                                      0.9340, 0.1299, 0.5688, 0.4694, 0.0119, 0.3371 
    3032                                     }; 
    31 static const double *randu_i=&RArandu[0]; 
    32 const static double *randu_last=&RArandu[MAXrand-1]; 
    33  
    34 static const double RArandn[MAXrandn]={ 
     33static const floatx *randu_i=&RArandu[0]; 
     34const static floatx *randu_last=&RArandu[MAXrand-1]; 
     35 
     36static const floatx RArandn[MAXrandn]={ 
    3537        0.6353, -0.6313, -1.0181,  0.4801,  0.4855,  0.9901, -0.5412, -1.0290,  1.0641, -0.0132, 
    3638        -0.6014, -2.3252, -0.1821,  0.6682, -0.0050,  0.2189, -1.3335,  0.2431, -0.2454, -0.5803, 
     
    4446        1.2366, -0.7043, -0.2512, -1.1071, -2.3646,  0.2809, -1.6640, -0.1161,  0.2608,  1.2698 
    4547}; 
    46 static const double *randn_i=&RArandn[0]; 
    47 const static double *randn_last=&RArandn[MAXrandn-1]; 
    48  
    49 double randu() { 
     48static const floatx *randn_i=&RArandn[0]; 
     49const static floatx *randn_last=&RArandn[MAXrandn-1]; 
     50 
     51floatx qrandu() { 
    5052        if ( randu_i==randu_last ) 
    5153                randu_i =&RArandu[0]; 
     
    5658} 
    5759 
    58 double randn() { 
     60floatx qrandn() { 
    5961        if ( randn_i==randn_last ) 
    6062                randn_i =&RArandn[0]; 
     
    6769void resample() { 
    6870        int N_babies[N]; 
    69         double cumdist; 
    70         int i; 
    71         double ui; 
    72  
    73         double u0 = randu(); 
     71        floatx cumdist; 
     72        int i; 
     73        floatx ui; 
     74        int i_from=0; 
     75        int i_to=0; 
     76 
     77        floatx u0 = qrandu(); 
    7478 
    7579        int j=0; 
     
    9094 
    9195        // COPY 
    92         int i_from=0; 
    93         int i_to=0; 
     96 
    9497        while ( i_from<N ) { 
    9598                while ( N_babies[i_from]>1 ) { // 1 baby stays where it is 
     
    111114} 
    112115 
    113 void mpf_bayes ( const double &isa, const double &isb , const double &usa, const double &usb ) { 
    114  
    115         double isd; 
    116         double isq; 
    117         double usd; 
    118         double usq; 
    119  
    120         double Cd; 
    121         double Cq; 
    122         double CC; 
    123         double oCC; 
    124  
    125         double difid; 
    126         double difiq; 
    127  
    128         double zeta; 
    129         double Kd; 
    130         double Kq; 
    131         double ro; 
    132         double ypd; 
    133         double ypq; 
    134         double detRy; 
    135         double ydiffd; 
    136         double ydiffq; 
    137         double ydC; 
    138  
    139         double maxlwi, sumlwi; 
    140         int i; 
     116void mpf_bayes ( const floatx isa, const floatx isb , const floatx usa, const floatx usb ) { 
     117 
     118        floatx isd; 
     119        floatx isq; 
     120        floatx usd; 
     121        floatx usq; 
     122 
     123        floatx Cd; 
     124        floatx Cq; 
     125        floatx CC; 
     126        floatx oCC; 
     127 
     128        floatx difid; 
     129        floatx difiq; 
     130 
     131        floatx zeta; 
     132        floatx Kd; 
     133        floatx Kq; 
     134        floatx ro; 
     135        floatx ypd; 
     136        floatx ypq; 
     137        floatx detRy; 
     138        floatx ydiffd; 
     139        floatx ydiffq; 
     140        floatx ydC; 
     141 
     142        floatx maxlwi, sumlwi; 
     143        int i; 
     144         
     145        floatx *th_i, *Pt_i, *om_i, *isdm_i, *isqm_i; 
     146        floatx *w_i, *lw_i; 
     147        floatx *sth_i, *cth_i; 
    141148// implementation starts here 
     149        th_i = &th[0]; 
     150        Pt_i = &Pt[0]; 
     151        om_i = &om[0]; 
     152        isdm_i = &isdm[0]; 
     153        isqm_i = &isqm[0]; 
     154        sth_i = &sth[0]; 
     155        cth_i = &cth[0]; 
    142156        for ( i=0; i<N; i++ ) { 
    143                 Pt[i] = 1.0*1.0*Pt[i]+qom; // Pt is now predictive variance 
    144                 th[i] =th[i] + om[i]*_dt+sqrt ( qth+_dt*_dt*Pt[i] ) *  randn() ; 
    145                 while ( th[i]>M_PI ) th[i]=th[i]-2*M_PI; 
    146                 while ( th[i]<-M_PI ) th[i]=th[i]+2*M_PI; 
    147  
    148                 sth[i]=sin ( th[i] ); 
    149                 cth[i]=cos ( th[i] ); 
    150  
    151                 isd = cth[i]*isa+sth[i]*isb; 
    152                 isq = -sth[i]*isa+cth[i]*isb; 
    153                 usd = cth[i]*usa+sth[i]*usb; 
    154                 usq = -sth[i]*usa+cth[i]*usb; 
     157 
     158                // time update 
     159                *Pt_i = 1.0*1.0*(*Pt_i)+qom; // Pt is now predictive variance 
     160                *th_i += *om_i*_dt+qth *  qrandn() ; 
     161                while ( *th_i>M_PI ) *th_i -=2*M_PI; 
     162                while ( *th_i<-M_PI ) *th_i+=2*M_PI; 
     163 
     164                *sth_i=sin ( *th_i ); 
     165                *cth_i=cos ( *th_i ); 
     166                 
     167                isd = *cth_i*isa+*sth_i*isb; 
     168                isq = -*sth_i*isa+*cth_i*isb; 
     169                // process old voltage 
     170                usd = (*cth_i)*usa+(*sth_i)*usb; 
     171                usq = -(*sth_i)*usa+(*cth_i)*usb; 
    155172 
    156173                Cd = isq*_dt; 
    157174                Cq = -_b - isd* _dt; 
    158175 
    159                 difid=isd- ( 1.0- ( _ad ) ) *isdm[i] - _cd *usd; 
    160                 difiq=isq- ( 1.0- ( _aq ) ) *isqm[i] - _cq *usq; 
     176                difid=isd- _ad  * (*isdm_i) - _cd *(usd); 
     177                difiq=isq- _aq  * (*isqm_i) - _cq *(usq); 
    161178 
    162179                CC=Cd*Cd+Cq*Cq; 
    163                 zeta = Pt[i]/ ( r+Pt[i]*CC ); 
     180                zeta = *Pt_i/ ( r+*Pt_i*CC ); 
    164181                oCC = ( 1-zeta*CC ); 
    165182                ro = oCC/r; 
    166183 
    167                 Kd = Pt[i]*Cd*ro; 
    168                 Kq = Pt[i]*Cq*ro; 
    169  
    170                 Pt[i]=Pt[i]* ( 1- ( Kd*Cd+Kq*Cq ) ); 
    171  
    172                 ypd = Cd*om[i]; 
    173                 ypq = Cq*om[i]; 
    174  
    175                 detRy = ro/r; 
    176                 om[i] = om[i] + Kd* ( difid - ypd ) +Kq* ( difiq-ypq ); 
     184                Kd = *Pt_i*Cd*ro; 
     185                Kq = *Pt_i*Cq*ro; 
     186 
     187                (*Pt_i)=(*Pt_i)*( 1.0- ( Kd*Cd+Kq*Cq ) ); 
     188 
     189                ypd = Cd**om_i; 
     190                ypq = Cq**om_i; 
     191 
     192                //detRy = ro/r; 
     193                *om_i += Kd* ( difid - ypd ) +Kq* ( difiq-ypq ); 
    177194                ydiffd = ( ypd-difid ); 
    178195                ydiffq = ( ypq-difiq ); 
    179196                ydC = ydiffd*Cd + ydiffq*Cq; 
    180197 
    181                 lwi[i] = 0.5* ( log ( detRy ) + ( ydC*ydC*zeta -(ydiffd*ydiffd+ydiffq*ydiffq) ) /r ) ; 
    182                  
    183                 isdm[i]=isd; 
    184                 isqm[i]=isq; 
     198                //lwi[i] = 0.5* ( log ( detRy ) + ( ydC*ydC*zeta -(ydiffd*ydiffd+ydiffq*ydiffq) ) /r ) ; 
     199                lwi[i] = 0.5*( ydC*ydC*zeta -(ydiffd*ydiffd+ydiffq*ydiffq) ) /r ; 
     200                 
     201                *isdm_i=isd; 
     202                *isqm_i=isq; 
     203                 
     204                // shift all counters 
     205                th_i++; 
     206                Pt_i++; 
     207                om_i++; 
     208                isdm_i++; 
     209                isqm_i++; 
     210                sth_i++; 
     211                cth_i++; 
     212 
    185213        } 
    186214        maxlwi=-1e10; 
    187         for ( i=0;i<N;i++ ) { 
    188                 if ( lwi[i]>maxlwi ) maxlwi=lwi[i]; 
    189         } 
    190         for ( i=0;i<N;i++ ) lwi[i]-=maxlwi; 
    191         for ( i=0;i<N;i++ ) w[i]=exp ( lwi[i] ); // always resample -> wmin=1/n; 
     215        lw_i = &lwi[0]; 
     216        for ( i=0;i<N;i++,lw_i++ ) { 
     217                if ( *lw_i>maxlwi ) maxlwi=*lw_i; 
     218        } 
     219        lw_i = &lwi[0]; 
     220        w_i = &w[0]; 
     221        for ( i=0;i<N;i++,lw_i++,w_i++ ) { 
     222                *lw_i-=maxlwi; 
     223                (*w_i)=exp ( *lw_i ); // always resample -> wmin=1/n; 
     224        } 
    192225 
    193226        sumlwi=0.0; 
    194         for ( i=0;i<N;i++ ) sumlwi+=w[i]; 
    195         for ( i=0;i<N;i++ ) w[i]/=sumlwi; 
     227        w_i = &w[0]; 
     228        for ( i=0;i<N;i++,w_i++ ) sumlwi+=*w_i; 
     229        w_i = &w[0]; 
     230        for ( i=0;i<N;i++,w_i++ ) *w_i/=sumlwi; 
     231         
     232        // NEFF 
     233        floatx sw2=0.0; 
     234        for ( i=0;i<N;i++ ) sw2+=w[i]*w[i]; 
     235        printf("%f\n",1./sw2*N); 
     236         
    196237        resample(); 
    197238} 
    198239 
    199240 
    200 void mpf_init(double qom0, double qth0, double r0) { 
     241void mpf_init(floatx qom0, floatx qth0, floatx r0) { 
     242        int i; 
    201243        r=r0; 
    202244        qth=qth0; 
    203245        qom=qom0; 
    204         int i; 
     246 
    205247        for ( i=0; i<N; i++ ) { 
    206                 th[i]=randu() *2*M_PI - M_PI; 
     248                th[i]=qrandu() *2*M_PI - M_PI; 
     249                sth[i]=sin ( th[i] ); 
     250                cth[i]=cos ( th[i] ); 
     251                 
    207252                om[i]=0; 
    208                 Pt[i]=1; 
     253                Pt[i]=10.; 
    209254                isdm[i]=0; 
    210255                isqm[i]=0; 
     
    213258 
    214259} 
    215 void mpf_mean ( double *Ecosth, double *Esinth, double *Eome ) { 
     260void mpf_mean ( floatx *Ecosth, floatx *Esinth, floatx *Eome ) { 
    216261        int i; 
    217262        *Ecosth=0.0; 
     
    225270 
    226271} 
    227 void mpf_th(double th1[N]){ 
    228         for (int i=0;i<N;i++) th1[i]=th[i]; 
    229 } 
    230  
    231 double kalman_om( const double &isa, const double &isb , const double &usa, const double &usb, const double &th ) { 
    232  
    233         double isd; 
    234         double isq; 
    235         double usd; 
    236         double usq; 
    237  
    238         double Cd; 
    239         double Cq; 
    240         double CC; 
    241         double oCC; 
    242  
    243         double difid; 
    244         double difiq; 
    245  
    246         double zeta; 
    247         double Kd; 
    248         double Kq; 
    249         double ro; 
    250         double ypd; 
    251         double ypq; 
    252         double detRy; 
    253         double ydiffd; 
    254         double ydiffq; 
    255         double ydC; 
    256  
    257         static double Pt; 
    258         static double om; 
    259         double cth, sth; 
    260         static double isdm, isqm; 
     272void mpf_th(floatx th1[N]){ 
     273        int i; 
     274        for (i=0;i<N;i++) th1[i]=th[i]; 
     275} 
     276 
     277floatx kalman_om( const floatx isa, const floatx isb , const floatx usa, const floatx usb, const floatx th ) { 
     278 
     279        floatx isd; 
     280        floatx isq; 
     281        floatx usd; 
     282        floatx usq; 
     283 
     284        floatx Cd; 
     285        floatx Cq; 
     286        floatx CC; 
     287        floatx oCC; 
     288 
     289        floatx difid; 
     290        floatx difiq; 
     291 
     292        floatx zeta; 
     293        floatx Kd; 
     294        floatx Kq; 
     295        floatx ro; 
     296        floatx ypd; 
     297        floatx ypq; 
     298        floatx detRy; 
     299        floatx ydiffd; 
     300        floatx ydiffq; 
     301        floatx ydC; 
     302 
     303        static floatx Pt; 
     304        static floatx om; 
     305        floatx cth, sth; 
     306        static floatx isdm, isqm; 
    261307 
    262308         
  • applications/pmsm/simulator_zdenek/ekf_example/mpf_double.h

    r1438 r1439  
    22 
    33#include "parametry_motoru.h" 
     4#define Fpm 0.1989 
     5//#define pi 3.141596 
    46 
    5 #define N 20 
     7#define N 1 
    68 
    79#define Lsd Ls*0.9 
    810#define Lsq Ls 
    911#define _dt 0.000125 
    10 #define _ad (1.-Rs*_dt/Lsd) 
    11 #define _aq (1.-Rs*_dt/Lsq) 
    12 #define _b  Fmag/Lsq*_dt 
    13 #define _cd  _dt/Lsd 
    14 #define _cq  _dt/Lsq 
     12#define _ad (1.-Rs*_dt/(Lsd)) 
     13#define _aq (1.-Rs*_dt/(Lsq)) 
     14#define _b  Fpm/Lsq*_dt 
     15#define _cd  _dt/(Lsd) 
     16#define _cq  _dt/(Lsq) 
    1517 
    16 double randn(); 
    17 double randu(); 
    1818 
    19 void mpf_bayes ( const double &isa, const double &isb , const double &usa, const double &usb ); 
    20 void mpf_init(double qom0, double qth0, double r0); 
    21 void mpf_mean(double *Ecosth, double *Esinth, double *Eome); 
    22 void mpf_th(double th1[N]); 
     19# define floatx float 
    2320 
    24 double kalman_om ( const double &isa, const double &isb , const double &usa, const double &usb, const double &th ); 
     21floatx qrandn(); 
     22floatx qrandu(); 
     23 
     24void mpf_bayes ( const floatx isa, const floatx isb , const floatx usa, const floatx usb ); 
     25void mpf_init(floatx qom0, floatx qth0, floatx r0); 
     26void mpf_mean(floatx *Ecosth, floatx *Esinth, floatx *Eome); 
     27void mpf_th(floatx th1[N]); 
     28 
     29floatx kalman_om ( const floatx isa, const floatx isb , const floatx usa, const floatx usb, const floatx th ); 
  • 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