root/applications/pmsm/simulator_zdenek/ekf_example/ekf_mm.cpp @ 1468

Revision 1468, 2.4 kB (checked in by smidl, 11 years ago)

uprava generatoru

Line 
1#include "ekf_mm.h"
2#include "qmath.h"
3#include "stdio.h"
4
5
6
7void ekfCh2(ekf_data *E, int16 ux, int16 uy, int16 isx, int16 isy, int32 *detS, int16 *rem)
8{
9        int16 t_sin,t_cos;
10        int32 tmp;
11       
12        //x_est[0]=x_est[0];
13        //               q15              + q15*q13
14        (E->x_est)[1]=(((int32)(E->x_est[1])<<15)+(int32)(E->cG)*(E->x_est[0]))>>15;
15        E->x_pred[1]=E->x_est[1];
16        E->x_pred[0]=E->x_est[0];
17       
18        mmultACh(E->PSI,E->Chf,E->PSICh,2,2);
19       
20        givens_fast(E->PSICh,E->Q,2); // pracuje inplace
21        for (int i=0;i<4;i++) E->Chf[i]=E->PSICh[i];   
22       
23        // implementace v PC
24        t_sin=qsin(E->x_est[1]);
25        t_cos=qcos(E->x_est[1]);
26       
27        {       
28                E->C[0]=((int32)(E->cB)*t_sin)>>15;
29                tmp=((int32)(E->cH)*(E->x_est[0]))>>15; // ! cH =cB with different scale!!
30                E->C[1]=((int32)tmp*t_cos)>>15;
31                E->C[2]=-((int32)(E->cB)*t_cos)>>15;
32                E->C[3]=((int32)tmp*t_sin)>>15;
33        }
34       
35       
36        tmp=((int32)(E->cB)*(E->x_est[0]))>>15; // q15*q13 -> q13
37        //             q15*q13 +          q13*q15      + q15*q13??
38        E->y_est[0]=((int32)(E->cA)*(E->y_old[0])+(int32)tmp*t_sin+(int32)(E->cC)*(ux))>>15; // in q13
39        E->y_est[1]=((int32)(E->cA)*(E->y_old[1])-(int32)tmp*t_cos+(int32)(E->cC)*(uy))>>15; // q13
40       
41        E->difz[0]=(isx-(E->y_est[0])); // shift to q15!!
42        E->difz[1]=(isy-(E->y_est[1]));//<<2;
43       
44        E->y_old[0] = isx;
45        E->y_old[1] = isy;
46       
47        carlson_fastC(E->difz,E->x_est,E->Chf,E->C,E->dR,2,2, detS, rem);
48}
49
50void init_ekfCh2(ekf_data *E, double Tv)
51{
52        // Tuning of matrix Q
53        E->Q[0]=prevod(0.005,15);      // 1e-3
54        E->Q[3]=prevod(0.001,15);      // 1e-3
55       
56        E->Chf[0]=0x1FFF;// !       // 0.05
57        E->Chf[1]=E->Chf[2]=0;
58        E->Chf[3]=0x1FFF;//!
59               
60        // Tuning of matrix R
61        E->dR[0]=prevod(0.001,15);         // 0.05
62        E->dR[1]=E->dR[0];
63       
64        // Motor model parameters
65        E->cA=prevod(1-Tv*Rs/Ls,15);
66        E->cB=prevod(Tv*Wref*Fmag/Iref/Ls,15);
67        E->cC=prevod(Tv/Ls/Iref*Uref,15);
68        //  cD=prevod(1-Tv*Bf/J,15);
69        //  cE=prevod(kp*p*p*Tv*Fmag*Iref/J/Wref,15);
70        //  cF=prevod(p*Tv*Mref/J/Wref,15);
71        E->cG=prevod(Tv*Wref/Thetaref,15); //in q15!
72        //cH=prevod(Tv*Wref*Fmag/Iref/Ls*Thetaref,15);
73        // cH=prevod(Tv*Wref*Thetaref*Fmag/Iref/Ls,15); // < ===========
74        E->cH=prevod(Tv*Wref*Fmag/Iref/Ls,15); //
75        //  cI=prevod(kp*p*p*Tv*Fmag*Iref/J/Wref*Thetaref);
76       
77        /* Init matrix PSI with permanently constant terms */
78        E->PSI[0]=0x7FFF;
79        E->PSI[2]=E->cG;
80        E->PSI[3]=0x7FFF;
81}
82
83void ekfmm(ekf_data* E1, ekf_data* E2, int16 ux, int16 uy, int16 isx, int16 isy)
84{
85        int32 det1, det2;
86        int16 rem1, rem2;
87        ekfCh2(E1, ux,uy,isx,isy,&det1,&rem1);
88        ekfCh2(E2, ux,uy,isx,isy,&det2,&rem2);
89       
90       
91}
Note: See TracBrowser for help on using the browser.