Spaceshot Flight Software
The Illinois Space Society's Homemade Rocket Firmware
dataLog.h
1 #ifndef DATALOG_H
2 #define DATALOG_H
3 
4 #include <ChRt.h>
5 #include <SD.h>
6 #include <stdint.h>
7 
8 #include "FifoBuffer.h"
9 #include "HistoryBuffer.h"
10 #include "MS5611.h" //Barometer Library
11 #include "SparkFunLSM9DS1.h" //Low-G IMU Library
12 #include "SparkFun_Qwiic_KX13X.h" //High-G IMU Library
13 #include "SparkFun_u-blox_GNSS_Arduino_Library.h"
14 #include "VoltageSensor.h"
15 #include "rocketFSM.h"
16 // #include "acShared.h"
17 // #include "dataStructs.h"
18 
23 struct LowGData {
24  float ax;
25  float ay;
26  float az;
27  float gx;
28  float gy;
29  float gz;
30  float mx;
31  float my;
32  float mz;
33  systime_t timeStamp_lowG;
34 };
35 
40 struct HighGData {
41  float hg_ax;
42  float hg_ay;
43  float hg_az;
44  systime_t timeStamp_highG;
45 };
46 
51 struct GpsData {
52  float latitude;
53  float longitude;
54  float altitude;
55  uint32_t siv_count;
56  uint32_t fix_type;
57  bool posLock;
58  systime_t timeStamp_GPS;
59 };
60 
65 struct FlapData {
66  float extension;
67  systime_t timeStamp_flaps;
68 };
69 
74 struct BarometerData {
75  float temperature; // in degC
76  float pressure; // in mbar
77  float altitude; // in meter
78  systime_t timeStamp_barometer;
79 };
80 
85 struct stateData {
86  float state_x = 0;
87  float state_vx = 0;
88  float state_ax = 0;
89  float state_apo = 0;
90  // float state_q0 = 0;
91 
92  systime_t timeStamp_state = 0;
93 };
94 
101  // data for lowGimu
102  bool has_lowG_data;
103  LowGData lowG_data;
104 
105  // data for highGimu accel data (hg_x, hg_y, hg_z)
106  bool has_highG_data;
107  HighGData highG_data;
108 
109  // GPS DATA
110  bool has_gps_data;
111  GpsData gps_data;
112 
113  // Barometer data (temp and pres)
114  bool has_barometer_data;
115  BarometerData barometer_data;
116 
117  // State variables
118  bool has_state_data;
119  stateData state_data;
120 
121  // Rocket State
122  bool has_rocketState_data;
123  rocketStateData<4> rocketState_data;
124 
125  // Flap state
126  bool has_flap_data;
127  FlapData flap_data;
128 
129  // Voltage state
130  bool has_voltage_data;
131  VoltageData voltage_data;
132 };
133 
138 enum sensors { LOWG_IMU, HIGHG_IMU, BAROMETER, GPS };
139 
140 #define FIFO_SIZE 1000
147  private:
148  FifoBuffer<LowGData, FIFO_SIZE> lowGFifo{};
149  FifoBuffer<HighGData, FIFO_SIZE> highGFifo{};
150  FifoBuffer<GpsData, FIFO_SIZE> gpsFifo{};
151  FifoBuffer<stateData, FIFO_SIZE> stateFifo{};
152  FifoBuffer<rocketStateData<4>, FIFO_SIZE> rocketStateFifo{};
153  FifoBuffer<FlapData, FIFO_SIZE> flapFifo{};
154  FifoBuffer<VoltageData, FIFO_SIZE> voltageFifo{};
155  FifoBuffer<BarometerData, FIFO_SIZE> barometerFifo{};
156 
157  public:
158  MUTEX_DECL(dataMutex_lowG);
159  MUTEX_DECL(dataMutex_highG);
160  MUTEX_DECL(dataMutex_GPS);
161  MUTEX_DECL(dataMutex_barometer);
162  MUTEX_DECL(dataMutex_flaps);
163  MUTEX_DECL(dataMutex_rocket_state);
164  MUTEX_DECL(dataMutex_voltage);
165  MUTEX_DECL(dataMutex_state);
166 
167  HistoryBuffer<50> altitude_history_50 = HistoryBuffer<50>();
168  HistoryBuffer<50> IMU_acceleration_history_50 = HistoryBuffer<50>();
169 
170  HistoryBuffer<6> altitude_history_6 = HistoryBuffer<6>();
171  HistoryBuffer<6> IMU_acceleration_history_6 = HistoryBuffer<6>();
172 
173  HistoryBuffer<6> gnc_altitude_history_6 = HistoryBuffer<6>();
174  HistoryBuffer<6> gnc_IMU_acceleration_history_6 = HistoryBuffer<6>();
175 
176  sensorDataStruct_t current_data;
177 
178  File dataFile;
179 
180  bool pushLowGFifo(LowGData* lowG_Data);
181  bool popLowGFifo(LowGData* lowG_Data);
182 
183  bool pushHighGFifo(HighGData* highG_Data);
184  bool popHighGFifo(HighGData* highG_Data);
185 
186  bool pushGpsFifo(GpsData* gps_Data);
187  bool popGpsFifo(GpsData* gps_Data);
188 
189  bool pushStateFifo(stateData* state_data);
190  bool popStateFifo(stateData* state_data);
191 
192  bool pushRocketStateFifo(rocketStateData<4>* rocket_data);
193  bool popRocketStateFifo(rocketStateData<4>* rocket_data);
194 
195  bool pushBarometerFifo(BarometerData* barometer_data);
196  bool popBarometerFifo(BarometerData* barometer_data);
197 
198  bool pushFlapsFifo(FlapData* flap_data);
199  bool popFlapsFifo(FlapData* flap_data);
200 
201  bool pushVoltageFifo(VoltageData* voltage_data);
202  bool popVoltageFifo(VoltageData* voltage_data);
203 };
204 
205 // forward declare;
206 struct Telemetry;
207 // TODO: Re-think this struct
208 struct pointers {
209  LSM9DS1* lowGimuPointer{};
210  QwiicKX134* highGimuPointer{};
211  MS5611* barometerPointer{};
212  SFE_UBLOX_GNSS* GPSPointer{};
213  Telemetry* telemetry{};
214 
215  sensorDataStruct_t* sensorDataPointer{};
216 
217  DataLogBuffer dataloggerTHDVarsPointer;
218  bool abort;
219 };
220 
222 
223 char* sd_file_namer(char* inputName, char* fileExtensionParam);
224 
225 void logData(File* dataFile, sensorDataStruct_t* data);
226 
227 #endif
A class to hold all info for ring buffers and mutexes used for data.
Definition: dataLog.h:146
Definition: telemetry.h:113
char * sd_file_namer(char *fileName, char *fileExtensionParam)
Creates the name for a file to be written to SD card.
Definition: dataLog.cpp:95
void dataLoggerTickFunction(pointers *pointer_struct)
Construct a new thd function object to log data to the SD card.
Definition: dataLog.cpp:31
Structure for all values collected from the barometer.
Definition: dataLog.h:74
Structure for values relevant to active control flaps.
Definition: dataLog.h:65
Structure for all values collected from the gps.
Definition: dataLog.h:51
Structure for all values collected from the high g sensor.
Definition: dataLog.h:40
Structure for all values collected from the low g sensor.
Definition: dataLog.h:23
Definition: VoltageSensor.h:7
Definition: dataLog.h:208
A struct to hold all of the data that could come from any of the sensors.
Definition: dataLog.h:100
Structure for all values tracked for state estimation.
Definition: dataLog.h:85