Changeset 1294
- Timestamp:
- 03/14/11 09:32:33 (14 years ago)
- Files:
-
- 11 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/pmsm/experiments/EKFfixed.cfg
r1264 r1294 9 9 params = "pmsm107@../cfg/zcu.cfg"; 10 10 tstep = 1; // steps for profile in [s] 11 //profileW = [0, 0, -30, -200, -90, -60, -30, 0, 30, 200];12 // profileW = [30 ];//[30, 30, 30, 60, 90, 60, 30, 0, -30, -60, -30];13 profileW = [0,0,1, 1, 5, 2, 2, 3, 0, 0, -3, -3, -1, -1, -4, 0, 0];11 profileW = [0, 0, -30, -200, -90, -60, -30, 0, 30, 200]; 12 // profileW = [30, 30, 30, 60, 90, 60, 30, 0, -30, -60, -30]; 13 // profileW = [0,0,1, 1, 5, 2, 2, 3, 0, 0, -3, -3, -1, -1, -4, 0, 0]; 14 14 // profileM = [0, 30, 0, 0, 30, 0, 0, 0, 0, 0, 10, 0, 0]; 15 15 profileM = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; 16 16 }; 17 17 18 estimators = ( 19 {class="EKF _UD";20 IM = {class="IMpmsmStat"; 18 estimators = ( 19 {class="EKFfixedCh"; 20 IM = {class="IMpmsmStat"; 21 21 params = "pmsm107@../cfg/zcu.cfg"; 22 22 }; 23 OM = {class="OMpmsm RO";};24 dQ=[0.01, 0.01, 0.0005, 0.001];25 // dQ=[18., 18., 157., 0.001]; 26 dR=[ 0.05, 0.05];27 // dR=[ 90., 90.];28 dP0=[1 8000., 18000., 157000000., 10.];23 OM = {class="OMpmsm";}; 24 // dQ=[0.01, 0.01, 0.0005, 0.001]; 25 dQ=[289., 289., 12630., 0.009]; // 0.01*170^2, 0.0005*5026^2, 0.001*3.14^2 26 dR=[1445, 1445]; 27 // dR=[0.05., 0.05.]; 28 dP0=[14450., 144500., 157000000., 10.]; 29 29 //connect 30 30 yrv = {class="RV"; names=("o_ia","o_ib");}; // observed u -
applications/pmsm/experiments/EKFfixedCh.cfg
r1264 r1294 34 34 name = "Est0"; 35 35 }, 36 {class="EKFfixed UD";36 {class="EKFfixedCh"; 37 37 //connect 38 38 yrv = {class="RV"; names=("o_ia","o_ib");}; // observed u -
applications/pmsm/experiments/ctrl.cfg
r1257 r1294 2 2 3 3 experiment={ 4 Ndat = 20000;4 Ndat = 50000; 5 5 }; 6 6 7 7 system= { 8 8 class= "pmsmDSctrl"; 9 params = "pmsm107@. /cfg/zcu.cfg";9 params = "pmsm107@../cfg/zcu.cfg"; 10 10 tstep = 1; // steps for profile in [s] 11 profileW = [0, 30, 0, 2];11 profileW = [0, 50, 0, -50, 0, 50 ]; 12 12 // profileW = [0, -10, 30, 60, 90, 60, 30, 0, -30, -60, -30]; 13 13 // profileW = [1, 10, 50, 200, 200, 30, 0, 0, -30, -30, -100, -100, -40, 0, 0]; … … 16 16 }; 17 17 18 UD = {class="EKF Ch";18 UD = {class="EKFfixedCh"; 19 19 IM = {class="IMpmsmStat"; 20 params = "pmsm107@. /cfg/zcu.cfg";20 params = "pmsm107@../cfg/zcu.cfg"; 21 21 }; 22 22 OM = {class="OMpmsm";}; 23 dQ=[0.01, 0.01, 0.0001, 0.000001]; 24 dR=[0.05, 0.05]; 23 name = "Est0"; 24 }; 25 26 full = {class="EKFCh"; 27 IM = {class="IMpmsmStat"; 28 params = "pmsm107@../cfg/zcu.cfg"; 29 compensate = 1; 30 }; 31 OM = {class="OMpmsm";}; 32 dQ=[289., 289., 12630., 0.009]; // 0.01*170^2, 0.0005*5026^2, 0.001*3.14^2 33 dR=[1445, 1445]; 34 dP0=[14450., 144500., 157000000., 10.]; 25 35 //connect 26 36 log_level="logmean,logU,logG,logD"; -
applications/pmsm/experiments/ctrl_lq_dq.cfg
r1278 r1294 30 30 controllers=({ 31 31 class = "PMSM_LQCtrl_dq"; 32 estim = "UD";32 // estim = "UD"; 33 33 r = 0.0001; 34 34 h = 100; -
applications/pmsm/pmsm_ctrl.h
r1289 r1294 63 63 PMSMCtrl():Controller() { 64 64 rv = RV("{ua ub }"); 65 rvc = RV("{o_ia o_ib t_ua t_ub o_om o_th Ww }");65 rvc = RV("{o_ia o_ib o_ua o_ub o_om o_th Ww }"); 66 66 } 67 67 -
applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.cpp
r1245 r1294 505 505 { 506 506 // Tuning of matrix Q 507 Q[0]=prevod(.0 1,15); // 0.05507 Q[0]=prevod(.001,15); // 0.05 508 508 Q[5]=Q[0]; 509 509 Q[10]=prevod(0.0005,15); // 1e-3 510 Q[15]=prevod(0.00 1,15); // 1e-3510 Q[15]=prevod(0.0001,15); // 1e-3 511 511 512 512 Uf[0]=0x7FFF;// ! // 0.05 … … 603 603 mmultACh(PSI,Chf,PSICh,4,4); 604 604 //thorton(int16 *U, int16 *D, int16 *PSIU, int16 *Q, int16 *G, int16 *Dold, unsigned int16 dimx); 605 householder(PSICh,Q,4);606 //givens(PSICh,Q,4);605 //householder(PSICh,Q,4); 606 givens_fast(PSICh,Q,4); 607 607 // COPY 608 608 for (int16 ii=0; ii<16; ii++){Chf[ii]=PSICh[ii];} … … 629 629 //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]; 630 630 631 carlson (difz,x_est,Chf,dR,2,4);631 carlson_fast(difz,x_est,Chf,dR,2,4); 632 632 //x_est[0] = xb[0]>>2; x_est[1]=xb[1]>>2; x_est[2]=xb[2]>>2; x_est[3]=xb[3]; 633 633 … … 649 649 Q[0]=prevod(.01,15); // 0.05 650 650 Q[5]=Q[0]; 651 Q[10]=prevod(0.0 1,15); // 1e-3652 Q[15]=prevod(0.0 1,15); // 1e-3651 Q[10]=prevod(0.0005,15); // 1e-3 652 Q[15]=prevod(0.001,15); // 1e-3 653 653 654 654 Chf[0]=0x3FFF;// ! // 0.05 … … 661 661 662 662 // Tuning of matrix R 663 R[0]=prevod(0. 1,15); // 0.05663 R[0]=prevod(0.05,15); // 0.05 664 664 R[3]=R[0]; 665 665 -
applications/pmsm/simulator_zdenek/ekf_example/ekf_obj.h
r1264 r1294 106 106 107 107 //! EKF for testing q44 108 class EKFtest: public EKF full{108 class EKFtest: public EKF_UD{ 109 109 void bayes ( const vec &yt, const vec &cond ) { 110 EKFfull::bayes(yt,cond); 111 mat &P = est._R(); 112 if (P(3,3)>3.14) 113 P(3,3)=3.14; 110 EKF_UD::bayes(yt,cond); 111 vec D = prior()._R()._D(); 112 113 if (D(3)>10) D(3) = 10; 114 115 prior()._R().__D()=D; 114 116 } 115 117 }; -
applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.cpp
r1245 r1294 221 221 if (x>6554) { 222 222 int16 xm05=x-16384; 223 tmp = (( long)k1*xm05)>>15;224 tmp-=((( long(k2)*xm05)>>15)*xm05)>>15;223 tmp = ((int32)k1*xm05)>>15; 224 tmp-=(((int32(k2)*xm05)>>15)*xm05)>>15; 225 225 tmp +=k1; 226 226 } else { 227 227 tmp = 4*x; 228 tmp-= long(8*x)*x>>15;228 tmp-=int32(8*x)*x>>15; 229 229 } 230 230 return tmp; … … 251 251 for (j=0;j<dimx;j++) 252 252 { 253 sigma+=(( long)B[k*dimx+j]*B[k*dimx+j]);253 sigma+=((int32)B[k*dimx+j]*B[k*dimx+j]); 254 254 } 255 255 for (j=0;j<=k;j++) 256 256 { 257 sigma+=(( long)Ch[k*dimx+j]*Ch[k*dimx+j]);257 sigma+=((int32)Ch[k*dimx+j]*Ch[k*dimx+j]); 258 258 } 259 259 260 260 //alpha in qCh 261 alpha = (int )(sqrt((double)sigma)+0.5); // predelat pro DSP261 alpha = (int16)(sqrt((double)sigma)+0.5); // predelat pro DSP 262 262 263 263 sigma=0; 264 264 for (j=0;j<dimx;j++) { 265 265 w[j]=B[k*dimx+j]; 266 sigma+=( long)w[j]*w[j];266 sigma+=(int32)w[j]*w[j]; 267 267 } 268 268 for (j=0; j<=k;j++) { … … 272 272 v[j]=Ch[k*dimx+j]; 273 273 } 274 sigma+=( long)v[j]*v[j];274 sigma+=(int32)v[j]*v[j]; 275 275 } 276 276 … … 281 281 sigma=0; 282 282 for (j=0;j<dimx;j++) { 283 sigma+=(( long)B[i*dimx+j]*w[j]);283 sigma+=((int32)B[i*dimx+j]*w[j]); 284 284 } 285 285 for (j=0;j<=k;j++) { 286 sigma+=( long)Ch[i*dimx+j]*v[j];286 sigma+=(int32)Ch[i*dimx+j]*v[j]; 287 287 } 288 288 … … 338 338 sigma=Ch[iy*dimx+j]; 339 339 beta=alpha; 340 alpha+=(( long)sigma*sigma)>>15;340 alpha+=((int32)sigma*sigma)>>15; 341 341 // double ab=(double)alpha*beta/32768./32768.; 342 342 // double s_ab=sqrt(ab); 343 gamma=(int )(sqrt((double)((long)alpha*beta))+0.5); // predelat v DSP343 gamma=(int16)(sqrt((double)((int32)alpha*beta))+0.5); // predelat v DSP 344 344 //gamma = round(s_ab*(1<<15)); 345 345 // eta=((long)beta<<15) / gamma; … … 348 348 for (i=0;i<=j;i++) { 349 349 tau=Ch[i*dimx+j]; 350 tmp_long=(( long)beta*Ch[i*dimx+j] -(long)sigma*w[i])/gamma;350 tmp_long=((int32)beta*Ch[i*dimx+j] -(int32)sigma*w[i])/gamma; 351 351 if (tmp_long>32767) { 352 352 Ch[i*dimx+j]=32767; … … 359 359 } 360 360 361 w[i]+=(( long)tau*sigma)>>15;361 w[i]+=((int32)tau*sigma)>>15; 362 362 } 363 363 } … … 365 365 //epsilon=(long(difz)<<15) / (alpha); // q15*q13/q13 = q15 366 366 for (i=0;i<dimx;i++) { 367 xp[i]+=(( long)w[i]*delta)/alpha;367 xp[i]+=((int32)w[i]*delta)/alpha; 368 368 } 369 369 } … … 385 385 for (i=dimx-1; i>=0; i--){ 386 386 for (j=0; j<dimx; j++) { 387 tmp_long=( long)Ch[i*dimx+i]*Ch[i*dimx+i]+long(A[i*dimx+j])*A[i*dimx+j];387 tmp_long=(int32)Ch[i*dimx+i]*Ch[i*dimx+i]+int32(A[i*dimx+j])*A[i*dimx+j]; 388 388 if (tmp_long>0){ 389 389 rho=sqrt(double(tmp_long)); 390 s=( long(A[i*dimx+j])<<15)/rho;391 c=( long(Ch[i*dimx+i])<<15)/rho;390 s=(int32(A[i*dimx+j])<<15)/rho; 391 c=(int32(Ch[i*dimx+i])<<15)/rho; 392 392 for (k=0;k<=i; k++){ 393 tau=( long(c)*A[k*dimx+j]-long(s)*Ch[k*dimx+i])>>15;394 Ch[k*dimx +i]=( long(s)*A[k*dimx+j]+long(c)*Ch[k*dimx+i])>>15;393 tau=(int32(c)*A[k*dimx+j]-int32(s)*Ch[k*dimx+i])>>15; 394 Ch[k*dimx +i]=(int32(s)*A[k*dimx+j]+int32(c)*Ch[k*dimx+i])>>15; 395 395 A[k*dimx +j]=tau; 396 396 } … … 399 399 400 400 for (j=0; j<i; j++){ 401 tmp_long=( long(Ch[i*dimx+i])*Ch[i*dimx+i]+long(Ch[i*dimx+j])*Ch[i*dimx+j]);401 tmp_long=(int32(Ch[i*dimx+i])*Ch[i*dimx+i]+int32(Ch[i*dimx+j])*Ch[i*dimx+j]); 402 402 if (tmp_long>0){ 403 403 rho=sqrt((double)(tmp_long)); 404 s=( long(Ch[i*dimx+j])<<15)/rho;405 c=( long(Ch[i*dimx+i])<<15)/rho;404 s=(int32(Ch[i*dimx+j])<<15)/rho; 405 c=(int32(Ch[i*dimx+i])<<15)/rho; 406 406 for (k=0; k<=i; k++){ 407 tau=( long(c)*Ch[k*dimx+j]-long(s)*Ch[k*dimx+i])>>15;408 Ch[k*dimx+i]=( long(s)*Ch[k*dimx+j]+long(c)*Ch[k*dimx+i])>>15;407 tau=(int32(c)*Ch[k*dimx+j]-int32(s)*Ch[k*dimx+i])>>15; 408 Ch[k*dimx+i]=(int32(s)*Ch[k*dimx+j]+int32(c)*Ch[k*dimx+i])>>15; 409 409 Ch[k*dimx+j]=tau; 410 410 } … … 443 443 } 444 444 } 445 446 447 void givens_fast(int16 *Ch, int16 *Q, unsigned int16 dimx) 448 { 449 int16 i,j,k; 450 int16 rho,s,c,tau; 451 int32 tmp_long; 452 453 int16 A[25];//beware 454 455 int16 *A_ij, *Q_i, *Ch_ki, *Ch_kj, *Ch_ii, *Ch_ij, *A_kj; 456 457 A_ij=A; 458 Q_i=Q; 459 // copy Q to A 460 for (i=0;i<dimx*dimx;i++) 461 { 462 // A[i]=Q[i]>>(15-qCh); 463 *A_ij++=(*Q_i++)>>(15-qCh); 464 } 465 466 for (i=dimx-1; i>=0; i--) 467 { 468 Ch_ii=Ch+i*dimx+i; 469 A_ij=A+i*dimx; 470 471 for (j=0; j<dimx; j++) 472 { 473 // tmp_long=(long)Ch[i*dimx+i]*Ch[i*dimx+i]+(long)A[i*dimx+j]*A[i*dimx+j]; 474 475 tmp_long=(int32)*Ch_ii**Ch_ii+(int32)*A_ij**A_ij; 476 477 if (tmp_long>0) 478 { 479 // rho=qsqrt(tmp_long); // verze pro DSP 480 rho=(int16)(sqrt((double)tmp_long)); // verze pro PC 481 s=((int32)*A_ij<<15)/rho; 482 c=((int32)*Ch_ii<<15)/rho; 483 484 Ch_ki=Ch+i; 485 A_kj=A+j; 486 487 for (k=0;k<=i; k++) 488 { 489 tau=((int32)c**A_kj-(int32)s**Ch_ki)>>15; 490 *Ch_ki=((int32)s**A_kj+(int32)c**Ch_ki)>>15; 491 *A_kj=tau; 492 493 Ch_ki+=dimx; 494 A_kj+=dimx; 495 } 496 } 497 A_ij++; 498 } 499 500 Ch_ij = Ch+i*dimx; 501 502 for (j=0; j<i; j++) 503 { 504 tmp_long=(int32)*Ch_ii**Ch_ii+(int32)*Ch_ij**Ch_ij; 505 506 if (tmp_long>0) 507 { 508 // rho=qsqrt(tmp_long); // verze pro DSP 509 rho=(int16)(sqrt((double)tmp_long)); // verze pro PC 510 s=((int32)*Ch_ij<<15)/rho; 511 c=((int32)*Ch_ii<<15)/rho; 512 513 Ch_kj = Ch + j; 514 Ch_ki = Ch + i; 515 516 for (k=0; k<=i; k++) 517 { 518 tau=((int32)c**Ch_kj-(int32)s**Ch_ki)>>15; 519 *Ch_ki =((int32)s**Ch_kj+(int32)c**Ch_ki)>>15; 520 *Ch_kj=tau; 521 522 Ch_kj += dimx; 523 Ch_ki += dimx; 524 } 525 } 526 Ch_ij++; 527 } 528 } 529 } 530 531 void carlson_fast(int16 *difz, int16 *xp, int16 *Ch, int16 *R, unsigned int16 dimy, unsigned int16 dimx ) { 532 int16 alpha,beta,gamma; 533 int16 delta, eta,epsilon,zeta,sigma,tau; 534 int16 i,j,iy; 535 int16 w[5]; 536 int32 tmp_long; 537 538 int16 *Ch_ij, *w_i, *x_i; 539 540 541 for (iy=0; iy<dimy; iy++) 542 { 543 alpha=R[iy]; 544 delta = difz[iy]; 545 546 for (j=0;j<dimx;j++) 547 { 548 sigma=Ch[iy*dimx+j]; 549 beta=alpha; 550 // alpha+=((long)sigma*sigma)>>15; 551 alpha=(((int32)alpha<<15)+(int32)sigma*sigma)>>15; // vyssi presnost 552 // gamma= qsqrt(((long)alpha*beta)); // verze pro DSP 553 gamma= (int16)(sqrt((double)((int32)alpha*beta))); // verze pro PC 554 555 w[j]=0; 556 557 Ch_ij=Ch+j; 558 w_i=w; 559 560 for (i=0;i<=j;i++) 561 { 562 // tau=Ch[i*dimx+j]; 563 tau=*Ch_ij; 564 // tmp_long=((long)beta*Ch[i*dimx+j] -(long)sigma*w[i])/gamma; 565 tmp_long=((int32)beta**Ch_ij -(int32)sigma**w_i)/gamma; 566 567 if (tmp_long>32767) 568 tmp_long=32767; 569 if (tmp_long<-32768) 570 tmp_long=-32768; 571 *Ch_ij=tmp_long; 572 573 // w_i+=((long)tau*sigma)>>15; 574 *w_i=(((int32)*w_i<<15)+(int32)tau*sigma)>>15; 575 576 w_i++; 577 Ch_ij+=dimx; 578 } 579 } 580 581 x_i=xp; 582 w_i=w; 583 for (i=0;i<dimx;i++) { 584 // xp[i]+=((long)w[i]*delta)/alpha; 585 // *x_i+=((long)*w_i*delta)/alpha; 586 *x_i=((int32)*x_i*alpha+(int32)*w_i*delta)/alpha; // vyssi presnost 587 x_i++; 588 w_i++; 589 } 590 } 591 } 592 -
applications/pmsm/simulator_zdenek/ekf_example/matrix_vs.h
r1245 r1294 15 15 #define qCh 14 16 16 17 #define int16 int18 #define int32 long17 #define int16 short 18 #define int32 int 19 19 20 20 /* Matrix multiply Full matrix by upper diagonal matrix with unit diagonal; */ … … 44 44 /* perform Carlson update of Ch matrix using difz, R and xp, for size dimx*/ 45 45 extern void carlson(int16 *difz, int16 *xp, int16 *Ch, int16 *R, unsigned int16 dimy, unsigned int16 dimx ); 46 47 /* perform Givens update of Ch matrix using PSI*Ch , Q, */ 48 extern void givens_fast(int16 *Ch /*= int16 *PSICh*/, int16 *Q, unsigned int16 dimx); 49 50 /* perform Carlson update of Ch matrix using difz, R and xp, for size dimx*/ 51 extern void carlson_fast(int16 *difz, int16 *xp, int16 *Ch, int16 *R, unsigned int16 dimy, unsigned int16 dimx ); -
applications/pmsm/simulator_zdenek/simulator.cpp
r1293 r1294 475 475 *(u+1)+=0.00157;*/ 476 476 // uprava velikosti vzhledem k Uc!=Ucn 477 kor_Uc=Ucn/230.;478 *u*=kor_Uc; /**/477 // kor_Uc=Ucn/230.; 478 // *u*=kor_Uc; /**/ 479 479 480 480 pwm(modulace); -
library/bdm/estim/kalman.cpp
r1226 r1294 532 532 mat Pf = T*P*T; 533 533 534 mat TQT = T*Q*T; 535 534 536 ldmat Pld(Pf); 535 537