Changeset 1464 for applications/pmsm
- Timestamp:
- 07/23/12 11:03:24 (12 years ago)
- Location:
- applications/pmsm/simulator_zdenek/ekf_example
- Files:
-
- 5 added
- 5 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/pmsm/simulator_zdenek/ekf_example/CMakeLists.txt
r1440 r1464 6 6 7 7 include_directories(../../bdm) 8 add_library (ekf_obj ekf_obj.cpp fixed.cpp matrix.cpp matrix_vs.cpp mpf_double.cpp )8 add_library (ekf_obj ekf_obj.cpp fixed.cpp matrix.cpp matrix_vs.cpp mpf_double.cpp ekf_mm.cpp qmath.cpp) -
applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.cpp
r1439 r1464 1076 1076 int16 dR[2];dR[0]=R[0];dR[1]=R[3]; 1077 1077 //int16 xb[4]; xb[0]=x_est[0]<<2; xb[1]=x_est[1]<<2; xb[2]=x_est[2]<<2; xb[3]=x_est[3]; 1078 carlson_fastC(difz,x_est,Chf,C,dR,2,2); 1078 int16 detS, rem; 1079 detS = 32767; rem=0; 1080 carlson_fastC(difz,x_est,Chf,C,dR,2,2, &detS, &rem); 1079 1081 //x_est[0] = xb[0]>>2; x_est[1]=xb[1]>>2; x_est[2]=xb[2]>>2; x_est[3]=xb[3]; 1080 1082 1083 log_level.store(logDet,vec_1((double)detS)); 1084 log_level.store(logRem,vec_1((double)rem)); 1085 1081 1086 // navrat estimovanych hodnot regulatoru 1082 1087 vec& mu = E._mu(); -
applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.h
r1463 r1464 23 23 #include "mpf_double.h" 24 24 #include "fast_exp.h" 25 #include "ekf_mm.h" 26 #include "qmath.h" 25 27 26 28 using namespace bdm; … … 413 415 class EKFfixedCh2 : public BM { 414 416 public: 415 LOG_LEVEL(EKFfixedCh2,logCh, logA, logC, logP );417 LOG_LEVEL(EKFfixedCh2,logCh, logA, logC, logP, logDet, logRem); 416 418 417 419 void init_ekf2(double Tv); … … 470 472 L.add_vector ( log_level, logC, RV ("C2", 4 ), prefix ); 471 473 L.add_vector ( log_level, logP, RV ("P2", 4 ), prefix ); 472 473 }; 474 //void from_setting(); 474 L.add_vector ( log_level, logDet, RV ("Det", 1 ), prefix ); 475 L.add_vector ( log_level, logRem, RV ("Rem", 1 ), prefix ); 476 477 }; 478 void from_setting ( const Setting &set ){ 479 BM::from_setting(set); 480 vec dQ,dR; 481 UI::get ( dQ, set, "dQ", UI::optional ); 482 UI::get ( dQ, set, "dR", UI::optional ); 483 if (dQ.length()==2){ 484 Q[0]=prevod(dQ[0],15); // 1e-3 485 Q[3]=prevod(dQ[1],15); // 1e-3 486 } 487 if (dR.length()==2){ 488 R[0]=prevod(dR[0],15); // 1e-3 489 R[3]=prevod(dR[1],15); // 1e-3 490 } 491 } 475 492 }; 476 493 … … 711 728 712 729 730 class ekfChfix: public BM{ 731 732 ekf_data E; 733 public: 734 ekfChfix(){ 735 init_ekfCh2(&E,0.000125);set_dim(2); dimc = 2; 736 dimy = 2; 737 } 738 void bayes ( const vec &val, const vec &cond ) { 739 int16 ux,uy; 740 ux=prevod(cond[0]/Uref,15); 741 uy=prevod(cond[1]/Uref,15); 742 743 int16 yx,yy; 744 // zadani mereni 745 yx=prevod(val[0]/Iref,15); 746 yy=prevod(val[1]/Iref,15); 747 748 int16 detS, rem; 749 ekfCh2(&E, ux,uy,yx,yy, &detS, &rem); 750 751 Est._mu()=vec_2(E.x_est[0]*Uref/32768., E.x_est[1]*Uref/32768.); 752 753 ll = -0.5*qlog(detS)-0.5*rem; 754 } 755 const epdf& posterior() const {return Est;}; 756 void from_setting ( const Setting &set ){ 757 BM::from_setting(set); 758 vec dQ,dR; 759 UI::get ( dQ, set, "dQ", UI::optional ); 760 UI::get ( dQ, set, "dR", UI::optional ); 761 if (dQ.length()==2){ 762 E.Q[0]=prevod(dQ[0],15); // 1e-3 763 E.Q[3]=prevod(dQ[1],15); // 1e-3 764 } 765 if (dR.length()==2){ 766 E.dR[0]=prevod(dR[0],15); // 1e-3 767 E.dR[1]=prevod(dR[1],15); // 1e-3 768 } 769 } 770 771 enorm<fsqmat> Est; 772 mat Ry; 773 }; 774 UIREGISTER(ekfChfix); 775 713 776 #endif // KF_H 714 777 -
applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.cpp
r1340 r1464 663 663 } 664 664 665 void carlson_fastC(int16 *difz, int16 *xp, int16 *Ch, int16 *C, int16 *R, unsigned int16 dimy, unsigned int16 dimx ) {665 void carlson_fastC(int16 *difz, int16 *xp, int16 *Ch, int16 *C, int16 *R, unsigned int16 dimy, unsigned int16 dimx, int16 *detS, int16 *rem ) { 666 666 int16 alpha,beta,gamma; 667 667 int16 delta, eta,epsilon,zeta,sigma,tau; … … 672 672 int16 *Ch_ij, *w_i, *x_i, *C_yi; 673 673 674 674 *detS = 32767; 675 675 for (iy=0; iy<dimy; iy++) 676 676 { … … 695 695 alpha=(tmp_long+(1<<14))>>15; // vyssi presnost 696 696 697 // 697 //gamma= qsqrt(((long)alpha*beta)); // verze pro DSP 698 698 gamma= (int16)(sqrt((double)((int32)alpha*beta))); // verze pro PC 699 699 // in q15 … … 734 734 w_i++; 735 735 } 736 } 737 } 738 736 737 *detS = ((int32)*detS*alpha+(1<<14))>>8; 738 *rem += ((int32)delta*delta)/alpha; 739 } 740 } 741 -
applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.h
r1340 r1464 52 52 extern void carlson(int16 *difz, int16 *xp, int16 *Ch, int16 *R, unsigned int16 dimy, unsigned int16 dimx ); 53 53 54 /* perform Givens update of Ch matrix using PSI*Ch ,Q, */54 /* perform Givens update of Ch matrix using PSI*Ch and Q, */ 55 55 extern void givens_fast(int16 *Ch /*= int16 *PSICh*/, int16 *Q, unsigned int16 dimx); 56 56 57 /* perform Carlson update of Ch matrix using difz, R and xp, for size dimx */57 /* perform Carlson update of Ch matrix using difz, R and xp, for size dimx, asuming identity matrix C*/ 58 58 extern void carlson_fast(int16 *difz, int16 *xp, int16 *Ch, int16 *R, unsigned int16 dimy, unsigned int16 dimx ); 59 59 60 60 /* perform Carlson update of Ch matrix using difz, R and xp, for size dimx*/ 61 extern void carlson_fastC(int16 *difz, int16 *xp, int16 *Ch, int16 *C, int16 *R, unsigned int16 dimy, unsigned int16 dimx);61 extern void carlson_fastC(int16* difz, int16* xp, int16* Ch, int16* C, int16* R, unsigned int16 dimy, unsigned int16 dimx, int16* detS, int16* rem );