Subversion Repositories FlightCtrl

Rev

Rev 838 | Rev 981 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
838 MikeW 1
/*
2
Copyright 2008, by Michael Walter
3
 
4
All functions written by Michael Walter are free software and can be redistributed and/or modified under the terms of the GNU Lesser
5
General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but
6
WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7
See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public
8
License along with this program. If not, see <http://www.gnu.org/licenses/>.
9
 
10
Please note: The software is based on the framework provided by H. Buss and I. Busker in their Mikrokopter projekt. All functions that
11
are not written by Michael Walter are under the license by H. Buss and I. Busker (license_buss.txt) published by www.mikrokopter.de
12
unless it is stated otherwise.
13
*/
14
 
15
/*****************************************************************************
16
  INCLUDES
17
**************************************************************************** */
966 MikeW 18
#include "matmatrix.h"
838 MikeW 19
 
20
/*****************************************************************************
21
  (SYMBOLIC) CONSTANTS
22
*****************************************************************************/
23
 
966 MikeW 24
/*****************************************************************************
25
  VARIABLES
26
*****************************************************************************/
27
extern int sollGier;
838 MikeW 28
 
29
/* *************************************************************************** */
30
/* Uses the Compass to Estimate Theta, Phi, Psi  */
31
//#define USE_Extended_MM3_Measurement_Model
32
/* *************************************************************************** */
33
 
34
/* kalman filter model extensions change number of state variables */
35
#define KAFI_DIM_X   (3)    /* number of rows of state vector */
36
 
37
#ifdef USE_Extended_MM3_Measurement_Model
966 MikeW 38
    #define KAFI_DIM_Y   (6)    /* number of rows of measurement vector (ACC_X, ACC_Y, ACC_Z, HX, HY, HZ)*/
838 MikeW 39
#else
966 MikeW 40
    #define KAFI_DIM_Y   (4)   /* number of rows of measurement vector (ACC_X, ACC_Y, ACC_Z, CompassHeading)*/
838 MikeW 41
#endif
42
 
43
#define KAFI_DIM_U   (3)    /* number of rows of control vector */
44
 
966 MikeW 45
#ifdef MELEXIS_GYRO
46
    #define fCycleTime 12.5F; /* Use Different Cycle Times to account for Runtime / Gain Differences */
47
#else
838 MikeW 48
#ifdef USE_Extended_MM3_Measurement_Model
966 MikeW 49
    #define fCycleTime 16.0F;
838 MikeW 50
#else
966 MikeW 51
    #define fCycleTime 12.5F;
52
    #endif
838 MikeW 53
#endif
54
 
966 MikeW 55
/* Predict the Measurent */
56
void trPredictMeasurement(void);
57
/* Update the Jacobi Matrix */
58
void trUpdateJacobiMatrix(void);
59
/* Extract measurements and store them in vector matY.
60
   Measurement validity is indicated by fYValid[] */
61
void trMeasure(void);
62
/* Innovation: calculate Xd, and Pd  */
63
void trInnovate(void);
64
/* Update transition matrix Phi  */
65
void trUpdatePhi(void);
66
/* Update control matrix B */
67
void trUpdateBU(void);
68
/* Predict new state Xs and Ps */
69
void KAFIPrediction(void);
70
/* Main Kalman Filter Loop */
71
void FlightAttitudeEstimation(void);
72
/* Setup the Kalman Filter Parameter */
73
void Kafi_Init(void);
74
/* Not done yet */
75
void trEstimateVelocity(void);
76
/* Limit Angles to [-2Pi;...;+2Pi] */
77
void trLimitAngles(void);
78
 
79
typedef struct
80
{
81
f32_t Phi;
82
f32_t Theta;
83
f32_t Psi;
84
i32_t iPhi10;
85
i32_t iTheta10;
86
i32_t iPsi10;
87
f32_t dPhi;
88
f32_t dTheta;
89
f32_t dPsi;
90
f32_t du;
91
f32_t dv;
92
f32_t dw;
93
f32_t X;
94
f32_t Y;
95
f32_t Z;
96
} status_t;
97
 
98
status_t status;
99
 
838 MikeW 100
/*typedef*/ enum
101
{
102
   _p = 0,
103
   _q,
104
   _r,
105
   c_control_variables                       /* number of control variables */
106
} /*trControlVariables_e*/;
107
 
108
 
109
#ifdef USE_Extended_MM3_Measurement_Model
110
/*typedef*/ enum
111
{
112
  _ax = 0,
113
  _ay,
114
  _az,
115
  _mx,
116
  _my,
117
  _mz,
118
  c_observation_variables                       /* number of observation variables */
119
} /*trObservationVariables_e*/;
120
#else
121
/*typedef*/ enum
122
{
123
  _ax = 0,
124
  _ay,
125
  _az,
126
  _compass,
127
  c_observation_variables                       /* number of observation variables */
128
} /*trObservationVariables_e*/;
129
#endif
130
 
131
/*typedef*/ enum
132
{
133
   _Phi = 0,
134
   _Theta,
135
   _Psi,
136
   //_du,
137
   //_dv,
138
   //_dw,
139
   c_state_variables                       /* number of state variables */
140
} /*trStateVariables_e*/;
141
 
142
 
143
 
144
 
145
 
146