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

Revision 1466, 2.5 kB (checked in by smidl, 12 years ago)

opraven test Ch

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, int16 *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        *detS = 32767; *rem=0;
48        carlson_fastC(E->difz,E->x_est,E->Chf,E->C,E->dR,2,2, detS, rem);
49}
50
51void init_ekfCh2(ekf_data *E, double Tv)
52{
53        // Tuning of matrix Q
54        E->Q[0]=prevod(0.005,15);      // 1e-3
55        E->Q[3]=prevod(0.001,15);      // 1e-3
56       
57        E->Chf[0]=0x1FFF;// !       // 0.05
58        E->Chf[1]=E->Chf[2]=0;
59        E->Chf[3]=0x1FFF;//!
60               
61        // Tuning of matrix R
62        E->dR[0]=prevod(0.001,15);         // 0.05
63        E->dR[1]=E->dR[0];
64       
65        // Motor model parameters
66        E->cA=prevod(1-Tv*Rs/Ls,15);
67        E->cB=prevod(Tv*Wref*Fmag/Iref/Ls,15);
68        E->cC=prevod(Tv/Ls/Iref*Uref,15);
69        //  cD=prevod(1-Tv*Bf/J,15);
70        //  cE=prevod(kp*p*p*Tv*Fmag*Iref/J/Wref,15);
71        //  cF=prevod(p*Tv*Mref/J/Wref,15);
72        E->cG=prevod(Tv*Wref/Thetaref,15); //in q15!
73        //cH=prevod(Tv*Wref*Fmag/Iref/Ls*Thetaref,15);
74        // cH=prevod(Tv*Wref*Thetaref*Fmag/Iref/Ls,15); // < ===========
75        E->cH=prevod(Tv*Wref*Fmag/Iref/Ls,15); //
76        //  cI=prevod(kp*p*p*Tv*Fmag*Iref/J/Wref*Thetaref);
77       
78        /* Init matrix PSI with permanently constant terms */
79        E->PSI[0]=0x7FFF;
80        E->PSI[2]=E->cG;
81        E->PSI[3]=0x7FFF;
82}
83
84void ekfmm(ekf_data* E1, ekf_data* E2, int16 ux, int16 uy, int16 isx, int16 isy)
85{
86        int16 det1, det2, 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.