Projet

Général

Profil

« Précédent | Suivant » 

Révision 279

Ajouté par nipelloux il y a presque 4 ans

Avancement Kalman + main.c

Voir les différences:

sp4a3_kalman.c
#include "sp4a3_kalman_extra.h"
void Add_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double b[nb][mb], double out[na][ma]){
void Add_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double b[nb][mb], double out[na][ma]){
int i=0;
int j=0;
if (na==nb && ma==mb)
{
for(i=0;i<=na-1;i++)
{
for(j=0;j<=ma-1;j++)
{
out[i][j] = A[i][j]+b[i][j];
}
}
}
}
void Inverse_Mat_22(int n,int m,double A[n][m],double B[n][m]){
double kdet;
kdet=(double)1/((A[0][0]*A[1][1])-(A[0][1]*A[1][0]));
B[0][0]=kdet*A[1][1];
B[1][1]=kdet*A[0][0];
B[0][1]=-kdet*A[0][1];
B[1][0]=-kdet*A[1][0];
}
......
}
void Sub_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double b[nb][mb], double out[na][ma]){
int i=0;
int j=0;
if (na==nb && ma==mb)
{
for(i=0;i<=na-1;i++)
{
for(j=0;j<=ma-1;j++)
{
out[i][j] = A[i][j]-b[i][j];
}
}
}
}
void Mul_Mat_Mat(int na,int ma,double A[na][ma], int nb,int mb,double B[nb][mb], double out[na][mb]){
void Mul_Mat_Mat(int na,int ma,double A[na][ma], int nb,int mb,double B[nb][mb], double out[na][mb]){
if (ma==nb)
{
int i;
int j;
int k;
for(int i=0;i<na;i++)
{
for(int j=0;j<mb;j++)
{
out[i][j]=0;
for (int k=0; k<ma;k++)
{
out[i][j] += A[i][k]*B[k][j];
}
}
}
}
}
}
void tests_unitaires(void){
//Matrices d'entrée
double T21a[2][1]={{7},{-5}};
......
{
t -= t0;x -= x0;y -= y0;
debug=0; ///Mettre à 1 pour afficher les matrices.
debug=1; ///Mettre à 1 pour afficher les matrices.
///Ajouter votre code ci-dessous///
// Kalman
// X = F*X
Plot_Mat(X," X(k+1|k) = ");
// X = F*X
double Xf [4][1];
Mul_Mat_Mat(4,4,F,4,1,X,Xf);
Plot_Mat(Xf," X(k+1|k) = ");
//P = F*P*F'+Q;
Plot_Mat(P,"P(k+1|k) = F.P(k|k).FT + Q = ");
// K = P*H' / ( H*P*H' + R);
//P = F*P*F'+Q;
double PP [4][4];
double PPPP [4][4];
double Pf [4][4];
Mul_Mat_Mat(4,4,F,4,4,P,PP);
Mul_Mat_Mat(4,4,PP,4,4,FT,PPPP);
Add_Mat_Mat(4,4,PPPP,4,4,Q,Pf);
Plot_Mat(Pf,"P(k+1|k) = F.P(k|k).FT + Q = ");
// K = P*H' / ( H*P*H' + R);
double PHT[4][2];
double sa [2][4];
double st [2][2];
double st2 [2][2];
double stt [2][2];
Mul_Mat_Mat(4,4,P,4,2,HT,PHT);
Mul_Mat_Mat(2,4,H,4,4,P,sa);
Mul_Mat_Mat(2,4,sa,4,2,HT,st);
Add_Mat_Mat(2,2,st,2,2,R,st2);
Transpose_Mat(2,2,st2,stt);
Mul_Mat_Mat(4,2,PHT,2,2,stt,K);
Plot_Mat(K,"K = ");
//X = X + K*([xb(i);yb(i)]-H*X);
//Plot_Mat(Delta,"DELTA = Obs - H.X(k+1|k)");
//Plot_Mat(Delta,"DELTA = Obs - H.X(k+1|k)");
double sd [2][1];
double se [2][1];
double sf [2][1];
double ps [2][1]={x,y};
double X2 [4][1];
Mul_Mat_Mat(2,4,H,4,1,X,sd);
Sub_Mat_Mat(2,1,ps,2,1,sd,se);
Mul_Mat_Mat(2,1,se,4,2,K,sf);
Add_Mat_Mat(2,1,sf,4,1,X,X);
Plot_Mat(X," X(k+1|k+1) = X(k+1|k) + K.Delta = ");
// P = P - K*H*P;
// P = P - K*H*P;
double KHP [2][2];
double KHP2 [2][2];
double P2 [4][4];
Mul_Mat_Mat(4,2,K,2,4,H,KHP);
Mul_Mat_Mat(2,2,KHP,4,4,P,KHP2);
Sub_Mat_Mat(4,4,P,2,2,KHP2,P);
Plot_Mat(P," P(k+1|k+1) = P(k+1|k) - K.H.P(k+1|k) = ");
/// La matrice X doit contenir la position filtrée ///

Formats disponibles : Unified diff