Changeset 1168
- Timestamp:
- 08/27/10 17:05:55 (14 years ago)
- Files:
-
- 6 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/pmsm/CMakeLists.txt
r744 r1168 22 22 ## Build simulator 23 23 add_subdirectory (simulator_zdenek) 24 #add_subdirectory (simulator_zdenek/ekf_example)24 add_subdirectory (simulator_zdenek/ekf_example) 25 25 26 26 ## Use it 27 27 include_directories (./simulator_zdenek) 28 28 link_directories (./simulator_zdenek) 29 #link_directories (./simulator_zdenek/ekf_example)29 link_directories (./simulator_zdenek/ekf_example) 30 30 31 EXEC (pmsm_estim pmsmsim )31 EXEC (pmsm_estim pmsmsim ekf_obj) 32 32 #EXEC (sim pmsmsim) 33 33 #EXEC (sim_var pmsmsim) -
applications/pmsm/pmsm_estim.cpp
r706 r1168 13 13 #include "filters.h" 14 14 #include "base/datasources.h" 15 15 #include "simulator_zdenek/ekf_example/ekf_obj.h" 16 16 17 17 using namespace bdm; -
applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.cpp
r384 r1168 8 8 9 9 /////////////// 10 void EKFfixed::bayes(const vec &dt){ 11 ekf(dt(2),dt(3),dt(0),dt(1)); 10 void EKFfixed::bayes(const vec &yt, const vec &ut){ 11 ekf(yt(0),yt(1),ut(0),ut(1)); 12 12 13 vec xhat(4); 13 14 //UGLY HACK!!! reliance on a predictor!! … … 15 16 xhat(1)=zprevod(x_est[1],Qm)*Iref; 16 17 xhat(2)=zprevod(x_est[2],Qm)*Wref; 17 xhat(3)=zprevod(x_est[3],15) ;18 xhat(3)=zprevod(x_est[3],15)*Thetaref; 18 19 19 20 E.set_mu(xhat); … … 33 34 double* Pp=Pfull._data(); 34 35 for(int i=0;i<16;i++){*(Pp++) = zprevod(P_est[i],15);} 36 37 E._R()._M()=Pfull; 38 35 39 36 40 BM::ll = -0.5* ( 4 * 1.83787706640935 +log ( det ( Pfull ) ) +xdif* ( inv(Pfull)*xdif ) ); -
applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.h
r384 r1168 65 65 //! Default constructor 66 66 EKFfixed ():BM(),E(),Ry(2,2){ 67 int i;68 69 67 int i; 68 for(i=0;i<16;i++){Q[i]=0;} 69 for(i=0;i<4;i++){R[i]=0;} 70 70 71 72 73 74 75 76 77 78 79 80 81 71 for(i=0;i<4;i++){x_est[i]=0;} 72 for(i=0;i<4;i++){x_pred[i]=0;} 73 for(i=0;i<16;i++){P_pred[i]=0;} 74 for(i=0;i<16;i++){P_est[i]=0;} 75 P_est[0]=0x7FFF; 76 P_est[5]=0x7FFF; 77 P_est[10]=0x7FFF; 78 P_est[15]=0x7FFF; 79 for(i=0;i<2;i++){Y_mes[i]=0;} 80 for(i=0;i<2;i++){ukalm[i]=0;} 81 for(i=0;i<8;i++){Kalm[i]=0;} 82 82 83 for(i=0;i<16;i++){PSI[i]=0;} 84 }; 83 for(i=0;i<16;i++){PSI[i]=0;} 84 85 set_dim(4); 86 E._mu()=zeros(4); 87 E._R()=zeros(4,4); 88 init_ekf(0.000125); 89 }; 85 90 //! Here dt = [yt;ut] of appropriate dimensions 86 void bayes ( const vec & dt );91 void bayes ( const vec &yt, const vec &ut ); 87 92 //!dummy! 88 epdf& posterior(){return E;}; 89 void condition ( const vec &Q0 ) { 90 91 Q[0]=prevod(minQ(Q0(0)),15); // 0.05 92 Q[5]=prevod(minQ(Q0(1)),15); 93 Q[10]=prevod(minQ(Q0(2)),15); // 1e-3 94 Q[15]=prevod(minQ(Q0(3)),15); // 1e-3 95 96 } 93 const epdf& posterior() const {return E;}; 94 97 95 }; 98 96 97 UIREGISTER(EKFfixed); 99 98 100 99 #endif // KF_H -
library/bdm/estim/kalman.cpp
r1158 r1168 513 513 } 514 514 } 515 516 if ( log_level[logU] ){ 517 // transformed U 518 mat tU; 519 mat P= U*diag(D)*U.T(); 520 521 vec xref(5); 522 xref(0)= 30.0*1.4142; 523 xref(1)= 30.0*1.4142; 524 xref(2)= 6.283185*200.; 525 xref(3) = 3.141593; 526 xref(4) = 34.0; 527 528 mat T = diag(1.0/(xref)); 529 mat Pf = T*P*T; 530 531 ldmat Pld(Pf); 532 533 //vec tmp=vec(U._data(),dimension()*dimension()); 534 vec tmp=vec(Pld._L()._data(),dimension()*dimension()); 535 log_level.store(logU,round(((int)1<<14)*tmp)); 536 } 537 if ( log_level[logG] ){ 538 vec tmp=vec(G._data(),dimension()*dimension()); 539 log_level.store(logG,tmp); 540 } 541 { 542 } 515 543 //cout << "Ut: " << U << endl; 516 544 //cout << "Dt: " << D << endl; … … 535 563 D(j) = beta*gamma*D(j); 536 564 537 cout << "a: " << alpha << "g: " << gamma << endl;565 // cout << "a: " << alpha << "g: " << gamma << endl; 538 566 for (i=0;i<j;i++){ 539 567 beta = U(i,j); … … 584 612 UI::get ( dR, set, "dR", UI::compulsory ); 585 613 set_parameters ( IM, OM, diag ( dQ ), dR ); 586 } 587 588 } 614 615 UI::get(log_level, set, "log_level", UI::optional); 616 } 617 618 } -
library/bdm/estim/kalman.h
r1158 r1168 429 429 class EKF_UD : public BM { 430 430 protected: 431 //! logger 432 LOG_LEVEL(EKF_UD,logU, logG); 431 433 //! Internal Model f(x,u) 432 434 shared_ptr<diffbifn> pfxu; … … 447 449 enorm<ldmat> est; 448 450 public: 451 449 452 //! copy constructor duplicated 450 453 EKF_UD* _copy() const { … … 458 461 } 459 462 460 461 463 EKF_UD(){} 464 462 465 463 466 EKF_UD(const EKF_UD &E0): pfxu(E0.pfxu),phxu(E0.phxu), U(E0.U), D(E0.D){} … … 469 472 void bayes ( const vec &yt, const vec &cond = empty_vec ); 470 473 474 void log_register ( bdm::logger& L, const string& prefix ){ 475 BM::log_register ( L, prefix ); 476 477 if ( log_level[logU] ) 478 L.add_vector ( log_level, logU, RV ( dimension()*dimension() ), prefix ); 479 if ( log_level[logG] ) 480 L.add_vector ( log_level, logG, RV ( dimension()*dimension() ), prefix ); 481 482 } 471 483 /*! Create object from the following structure 472 484