Skip to content
Closed
1 change: 1 addition & 0 deletions MIDAS/GroundStation
Submodule GroundStation added at a06616
2 changes: 1 addition & 1 deletion MIDAS/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,4 @@ build_unflags =
lib_deps =
Eigen
lib_ignore =
TCAL9538
TCAL9539
2 changes: 2 additions & 0 deletions MIDAS/src/data_logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void log_data(LogSink& sink, RocketData& data) {
log_from_sensor_data(sink, data.cam_data);
}



#ifndef SILSIM
#define MAX_FILES 999

Expand Down
11 changes: 11 additions & 0 deletions MIDAS/src/data_logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
//#include "hardware/Emmc.h"
#endif




/**
* @class LogSink
*
Expand All @@ -23,6 +26,7 @@ class LogSink {
virtual ErrorCode init() = 0;
virtual void write(const uint8_t* data, size_t size) = 0;

virtual void write_meta(const uint8_t* data, size_t size) = 0;
uint16_t current_file_no = 0;
};

Expand All @@ -39,6 +43,8 @@ class MultipleLogSink : public LogSink {
};

void write(const uint8_t* data, size_t size) override {};

void write_meta(const uint8_t* data, size_t size) override {};
};

template<typename Sink, typename... Sinks>
Expand All @@ -59,6 +65,11 @@ class MultipleLogSink<Sink, Sinks...> : public LogSink {
sinks.write(data, size);
};

void write_meta(const uint8_t* data, size_t size) override {
sink.write(data, size);
sinks.write(data, size);
};

private:
Sink sink;
MultipleLogSink<Sinks...> sinks;
Expand Down
32 changes: 32 additions & 0 deletions MIDAS/src/data_logging_meta.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "data_logging_meta.h"
#include "log_format.h"
#include "log_checksum.h"

/*

Queue<MetaLogging::MetaLogEntry> _q;

bool MetaLogging::get_queued(MetaLogEntry* out) { return _q.receive(out); }

void log_event(MetaDataCode event_type, uint32_t timestamp) {
MetaLogging::MetaLogEntry entry{event_type, 0, 0};
entry.size = sizeof(uint32_t);
memcpy(entry.data, &timestamp, entry.size);
_q.send(entry);
}

template <typename T>
void log_data(MetaDataCode data_type, const T& data) {

// double check...
static_assert(sizeof(T) <= META_LOGGING_MAX_SIZE, "Datatype for log_data too large");

MetaLogEntry entry{data_type, 0, 0};
entry.size = sizeof(T);
memcpy(entry.data, &data, entry.size);
_q.send(entry);


}

*/
42 changes: 42 additions & 0 deletions MIDAS/src/data_logging_meta.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once
//#include "rocket_state.h"
//#include "errors.h"

/*

#define META_LOGGING_MAX_SIZE 64

enum MetaDataCode {
// Launch events
EVENT_TLAUNCH,
EVENT_TBURNOUT,
EVENT_TIGNITION,
EVENT_TAPOGEE,
EVENT_TMAIN,

// Non-events
DATA_LAUNCHSITE_BARO,
DATA_LAUNCHSITE_GPS,
DATA_LAUNCH_INITIAL_TILT,
DATA_TILT_AT_BURNOUT,
DATA_TILT_AT_IGNITION
};

struct MetaLogging {

public:
struct MetaLogEntry {
MetaDataCode log_type;
char data[META_LOGGING_MAX_SIZE];
size_t size;
};

bool get_queued(MetaLogEntry* out);

void log_event(MetaDataCode event_type, uint32_t timestamp);

template <typename T>
void log_data(MetaDataCode data_type, const T& data);
};

*/
2 changes: 2 additions & 0 deletions MIDAS/src/esp_eeprom_checksum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// autogenerated on build by applying crc32 on esp_eeprom_format.h
#define EEPROM_CHECKSUM (0xcfa22d7d)
12 changes: 10 additions & 2 deletions MIDAS/src/finite-state-machines/fsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ StateEstimate::StateEstimate(RocketData& state) {
*
* @return New FSM State
*/
FSMState FSM::tick_fsm(FSMState& state, StateEstimate state_estimate, CommandFlags& commands) {
FSMState FSM::tick_fsm(RocketData& sys) {
FSMState state = sys.fsm_state.getRecentUnsync();
StateEstimate state_estimate(sys);
CommandFlags& commands = sys.command_flags;

//get current time
double current_time = pdTICKS_TO_MS(xTaskGetTickCount());

Expand Down Expand Up @@ -338,7 +342,11 @@ FSMState FSM::tick_fsm(FSMState& state, StateEstimate state_estimate, CommandFla
*
* @return New FSM State
*/
FSMState FSM::tick_fsm(FSMState& state, StateEstimate state_estimate, CommandFlags& commands) {
FSMState FSM::tick_fsm(RocketData& sys) {
FSMState state = sys.fsm_state.getRecentUnsync();
StateEstimate state_estimate(sys);
CommandFlags& commands = sys.command_flags;

double current_time = pdTICKS_TO_MS(xTaskGetTickCount());

switch (state) {
Expand Down
6 changes: 5 additions & 1 deletion MIDAS/src/finite-state-machines/fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ class FSM {
public:
FSM() = default;

FSMState tick_fsm(FSMState& curr_state, StateEstimate state_estimate, CommandFlags& commands);
// FSMState tick_fsm(FSMState& curr_state, StateEstimate state_estimate, CommandFlags& commands);

// Constructor for the metadata
// Created so that FSMState, StateEstimate, and CommandFlags objects can supercede the mutex lock
FSMState tick_fsm(RocketData& sys);

private:
double launch_time;
Expand Down
23 changes: 21 additions & 2 deletions MIDAS/src/hardware/SDLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,23 @@ ErrorCode SDSink::init() {
int filenumber = -1;
sdFileNamer(file_name, ext, SD_MMC, current_file_no, &filenumber);


if(filenumber != -1) {
Serial.print("[SD] Beginning log: "); Serial.println(current_file_no);
} else {
failed = true;
return ErrorCode::SDBeginFailed;
}

char meta_name[255] = {0};
strcpy(meta_name, file_name);
char* extpos = strrchr(meta_name, '.');
if (extpos) {
strcpy(extpos, ".meta");
}

file = SD_MMC.open(file_name, FILE_WRITE, true);
if (!file) {
meta = SD_MMC.open(meta_name, FILE_WRITE, true);
if (!file || !meta) {
failed = true;
return ErrorCode::SDCouldNotOpenFile;
}
Expand Down Expand Up @@ -73,4 +80,16 @@ void SDSink::write(const uint8_t* data, size_t size) {
unflushed_bytes = 0;
}
}

return;
}

void SDSink::write_meta(const uint8_t* data, size_t size) {
if (failed) { return; }

file.write(data, size);
file.write('\n');
file.flush(); // Meta writes are infrequent, so flushing is OK.

return;
}
2 changes: 2 additions & 0 deletions MIDAS/src/hardware/SDLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class SDSink : public LogSink {

ErrorCode init() override;
void write(const uint8_t* data, size_t size) override;
void write_meta(const uint8_t* data, size_t size) override;
private:
File file;
File meta;
size_t unflushed_bytes = 0;
};
9 changes: 6 additions & 3 deletions MIDAS/src/hardware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
*/

// #ifdef IS_SUSTAINER
// MultipleLogSink<EMMCSink> sinks;
SDSink sink;
//MultipleLogSink<EMMCSink> sinks;
MultipleLogSink<SDSink> sinks;
// #else
// MultipleLogSink<> sinks;
// #endif
RocketSystems systems{.log_sink = sink};
RocketSystems systems{.log_sink = sinks};
/**
* @brief Sets up pinmodes for all sensors and starts threads
*/
Expand Down Expand Up @@ -107,8 +107,11 @@ void setup()

// init and start threads
begin_systems(&systems);

loop();
}

void loop()
{
printf("\nHI!");
}
61 changes: 60 additions & 1 deletion MIDAS/src/rocket_state.h
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For rocket_state.h, idk if it is a quick oversight but the data_logging_meta.h already has some of the code that this header has (excluding a couple lines within rocket_state.h, there are some differences between the two).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok I understand now, compile time stuff

Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,65 @@ class Latency {
}
};

#define META_LOGGING_MAX_SIZE 64

enum MetaDataCode {
// Launch events
EVENT_TLAUNCH,
EVENT_TBURNOUT,
EVENT_TIGNITION,
EVENT_TAPOGEE,
EVENT_TMAIN,
EVENT_TMAX_ACCEL,
EVENT_TMAX_VEL,
EVENT_TMAX_DESCENT_RATE,

// Non-events
DATA_LAUNCHSITE_BARO,
DATA_LAUNCHSITE_GPS,
DATA_LAUNCH_INITIAL_TILT,
DATA_TILT_AT_BURNOUT,
DATA_TILT_AT_IGNITION,
DATA_MAX_ACCEL,
DATA_MAX_VEL,
DATA_ALT_AT_BURNOUT,
DATA_MAX_DESCENT_RATE
};

struct MetaLogging {
public:
struct MetaLogEntry {
MetaDataCode log_type;
size_t size;
char data[META_LOGGING_MAX_SIZE];
};

Queue<MetaLogEntry> _q;

bool get_queued(MetaLogEntry* out) { return _q.receive(out); }

void log_event(MetaDataCode event_type, uint32_t timestamp) {
MetaLogEntry entry{event_type, 0, 0};
entry.size = sizeof(uint32_t);
memcpy(entry.data, &timestamp, entry.size);
_q.send(entry);
}

template <typename T>
void log_data(MetaDataCode data_type, const T& data) {

// double check...
static_assert(sizeof(T) <= META_LOGGING_MAX_SIZE, "Datatype for log_data too large");

MetaLogEntry entry{data_type, 0, 0};
entry.size = sizeof(T);
memcpy(entry.data, &data, entry.size);
_q.send(entry);

fprintf(stderr, "Data has been logged: %c", entry.data);
}
};

/**
* @struct CommandFlags
*
Expand Down Expand Up @@ -196,7 +255,7 @@ struct RocketData {
SensorData<Magnetometer> magnetometer;
SensorData<Voltage> voltage;
SensorData<CameraData> cam_data;

CommandFlags command_flags;
Latency log_latency;
};
Loading
Loading