Spaceshot Flight Software
The Illinois Space Society's Homemade Rocket Firmware
kalmanFilter.h
1 #include "../EigenArduino-Eigen30/Eigen30.h"
2 #include "ServoControl.h"
3 #include "dataLog.h"
4 #include "rk4.h"
5 #include "rocketFSM.h"
6 #include "sensors.h"
7 
8 class KalmanFilter {
9  public:
10  KalmanFilter(struct pointers* pointer_struct);
11 
12  void Initialize();
13  void Initialize(float pos_f, float vel_f);
14  void priori();
15  void update();
16  void SetQ(float dt, float sd);
17  void SetF(float dt);
18 
19  void kfTickFunction(float dt, float sd);
20 
21  private:
22  float s_dt = 0.050;
23 
24  DataLogBuffer* data_logger_;
25  mutex_t* mutex_lowG_;
26  mutex_t* mutex_highG_;
27  mutex_t* dataMutex_barometer_;
28  mutex_t* dataMutex_state_;
29  stateData* stateData_;
30  RocketFSM::FSM_State* current_state_;
31  float* b_alt;
32  float* gz_L;
33  float* gz_H;
34 
35  Eigen::Matrix<float, 3, 1> x_k{0, 0, 0};
36  Eigen::Matrix<float, 3, 3> F_mat = Eigen::Matrix<float, 3, 3>::Zero();
37  Eigen::Matrix<float, 2, 3> H = Eigen::Matrix<float, 2, 3>::Zero();
38  Eigen::Matrix<float, 3, 3> P_k = Eigen::Matrix<float, 3, 3>::Zero();
39  Eigen::Matrix<float, 3, 3> Q = Eigen::Matrix<float, 3, 3>::Zero();
40  Eigen::Matrix<float, 2, 2> R = Eigen::Matrix<float, 2, 2>::Zero();
41  Eigen::Matrix<float, 3, 3> P_priori = Eigen::Matrix<float, 3, 3>::Zero();
42  Eigen::Matrix<float, 3, 1> x_priori = Eigen::Matrix<float, 3, 1>::Zero();
43  Eigen::Matrix<float, 3, 2> K = Eigen::Matrix<float, 3, 2>::Zero();
44  Eigen::Matrix<float, 2, 1> y_k = Eigen::Matrix<float, 2, 1>::Zero();
45 
46  Eigen::Matrix<float, 3, 2> B = Eigen::Matrix<float, 3, 2>::Zero();
47 };
A class to hold all info for ring buffers and mutexes used for data.
Definition: dataLog.h:146
Definition: kalmanFilter.h:8
void update()
Update Kalman Gain.
Definition: kalmanFilter.cpp:180
void Initialize()
Sets altitude by averaging 30 barometer measurements taken 100 ms apart.
Definition: kalmanFilter.cpp:79
void kfTickFunction(float dt, float sd)
Run Kalman filter calculations as long as FSM has passed IDLE.
Definition: kalmanFilter.cpp:53
FSM_State
Labels for each FSM state. Contains intermediary states (eg: Launch Detect) along with actual states ...
Definition: rocketFSM.h:17
Sensor (Low-G, High-G and GPS) struct definitions.
Definition: dataLog.h:208
Structure for all values tracked for state estimation.
Definition: dataLog.h:85