From 5ce14078a772014cf3088ca2d781875fc7443ff9 Mon Sep 17 00:00:00 2001 From: kUin1 Date: Sat, 28 Sep 2024 17:19:21 -0500 Subject: [PATCH 1/9] Process-profiling Added a new ProcessTime struct. Added calculation of the loop time for each thread. --- MIDAS/src/data_logging.cpp | 1 + MIDAS/src/log_format.h | 2 + MIDAS/src/sensor_data.h | 12 ++++++ MIDAS/src/systems.cpp | 75 +++++++++++++++++++++++++++++++++++++- 4 files changed, 89 insertions(+), 1 deletion(-) diff --git a/MIDAS/src/data_logging.cpp b/MIDAS/src/data_logging.cpp index e6cb5ce2..f0a0fe4b 100644 --- a/MIDAS/src/data_logging.cpp +++ b/MIDAS/src/data_logging.cpp @@ -25,6 +25,7 @@ ASSOCIATE(Orientation, ID_ORIENTATION) ASSOCIATE(FSMState, ID_FSM) ASSOCIATE(KalmanData, ID_KALMAN) ASSOCIATE(PyroState, ID_PYRO) +ASSOCIATE(ProcessTime, ID_PROCESSTIME); /** * @brief writes a reading, with its ID, timestamp, and data to a specific sink diff --git a/MIDAS/src/log_format.h b/MIDAS/src/log_format.h index dde361bb..a251fc0d 100644 --- a/MIDAS/src/log_format.h +++ b/MIDAS/src/log_format.h @@ -20,6 +20,7 @@ enum ReadingDiscriminant { ID_FSM = 10, ID_KALMAN = 11, ID_PYRO = 12, + ID_PROCESSTIME = 13, }; @@ -51,5 +52,6 @@ struct LoggedReading { KalmanData kalman; FSMState fsm; PyroState pyro; + ProcessTime processtime; } data; }; diff --git a/MIDAS/src/sensor_data.h b/MIDAS/src/sensor_data.h index d6b8b765..7b8a98f0 100644 --- a/MIDAS/src/sensor_data.h +++ b/MIDAS/src/sensor_data.h @@ -229,3 +229,15 @@ struct PyroState { bool is_global_armed = false; PyroChannel channels[4]; }; + +/** + * @struct ProcessTime + * + * @brief The process time of the processes in the thread +*/ +struct ProcessTime +{ + char ProcessName[32]; + float dt; +}; + diff --git a/MIDAS/src/systems.cpp b/MIDAS/src/systems.cpp index 36bff5b8..df81fd6e 100644 --- a/MIDAS/src/systems.cpp +++ b/MIDAS/src/systems.cpp @@ -19,24 +19,41 @@ DECLARE_THREAD(logger, RocketSystems* arg) { log_begin(arg->log_sink); while (true) { + TickType_t startTime = xTaskGetTickCount(); + log_data(arg->log_sink, arg->rocket_data); arg->rocket_data.log_latency.tick(); + float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; + ProcessTime new_processTime; + new_processTime.dt = dt; + strcpy(new_processTime.ProcessName, "logger"); + THREAD_SLEEP(1); } } DECLARE_THREAD(barometer, RocketSystems* arg) { while (true) { + TickType_t startTime = xTaskGetTickCount(); + Barometer reading = arg->sensors.barometer.read(); arg->rocket_data.barometer.update(reading); + + float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; + ProcessTime new_processTime; + new_processTime.dt = dt; + strcpy(new_processTime.ProcessName, "barometer"); + THREAD_SLEEP(6); } } DECLARE_THREAD(accelerometers, RocketSystems* arg) { while (true) { + TickType_t startTime = xTaskGetTickCount(); + #ifdef IS_SUSTAINER LowGData lowg = arg->sensors.low_g.read(); arg->rocket_data.low_g.update(lowg); @@ -45,25 +62,46 @@ DECLARE_THREAD(accelerometers, RocketSystems* arg) { arg->rocket_data.low_g_lsm.update(lowglsm); HighGData highg = arg->sensors.high_g.read(); arg->rocket_data.high_g.update(highg); + + float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; + ProcessTime new_processTime; + new_processTime.dt = dt; + strcpy(new_processTime.ProcessName, "accelerometers"); + THREAD_SLEEP(2); } } DECLARE_THREAD(orientation, RocketSystems* arg) { while (true) { + TickType_t startTime = xTaskGetTickCount(); + Orientation reading = arg->sensors.orientation.read(); if (reading.has_data) { arg->rocket_data.orientation.update(reading); } + float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; + ProcessTime new_processTime; + new_processTime.dt = dt; + strcpy(new_processTime.ProcessName, "orientation"); + THREAD_SLEEP(100); } } DECLARE_THREAD(magnetometer, RocketSystems* arg) { while (true) { + TickType_t startTime = xTaskGetTickCount(); + Magnetometer reading = arg->sensors.magnetometer.read(); arg->rocket_data.magnetometer.update(reading); + + float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; + ProcessTime new_processTime; + new_processTime.dt = dt; + strcpy(new_processTime.ProcessName, "magnetometer"); + THREAD_SLEEP(50); //data rate is 155hz so 7 is closest } } @@ -73,6 +111,8 @@ DECLARE_THREAD(i2c, RocketSystems* arg) { int i = 0; while (true) { + TickType_t startTime = xTaskGetTickCount(); + if (i % 10 == 0) { GPS reading = arg->sensors.gps.read(); arg->rocket_data.gps.update(reading); @@ -91,6 +131,11 @@ DECLARE_THREAD(i2c, RocketSystems* arg) { arg->led.update(); i += 1; + float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; + ProcessTime new_processTime; + new_processTime.dt = dt; + strcpy(new_processTime.ProcessName, "i2c"); + THREAD_SLEEP(10); } } @@ -100,6 +145,8 @@ DECLARE_THREAD(fsm, RocketSystems* arg) { FSM fsm{}; bool already_played_freebird = false; while (true) { + TickType_t startTime = xTaskGetTickCount(); + FSMState current_state = arg->rocket_data.fsm_state.getRecentUnsync(); StateEstimate state_estimate(arg->rocket_data); @@ -112,14 +159,26 @@ DECLARE_THREAD(fsm, RocketSystems* arg) { already_played_freebird = true; } + float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; + ProcessTime new_processTime; + new_processTime.dt = dt; + strcpy(new_processTime.ProcessName, "fsm"); + THREAD_SLEEP(50); } } DECLARE_THREAD(buzzer, RocketSystems* arg) { while (true) { + TickType_t startTime = xTaskGetTickCount(); + arg->buzzer.tick(); + float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; + ProcessTime new_processTime; + new_processTime.dt = dt; + strcpy(new_processTime.ProcessName, "buzzer"); + THREAD_SLEEP(10); } } @@ -129,6 +188,7 @@ DECLARE_THREAD(kalman, RocketSystems* arg) { TickType_t last = xTaskGetTickCount(); while (true) { + TickType_t startTime = xTaskGetTickCount(); // add the tick update function Barometer current_barom_buf = arg->rocket_data.barometer.getRecentUnsync(); LowGData current_accelerometer = arg->rocket_data.low_g.getRecentUnsync(); @@ -143,17 +203,30 @@ DECLARE_THREAD(kalman, RocketSystems* arg) { KalmanData current_state = yessir.getState(); arg->rocket_data.kalman.update(current_state); - last = xTaskGetTickCount(); + dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; + ProcessTime new_processTime; + new_processTime.dt; + strcpy(new_processTime.ProcessName, "Kalman Filter"); + + THREAD_SLEEP(50); } } DECLARE_THREAD(telemetry, RocketSystems* arg) { while (true) { + TickType_t startTime = xTaskGetTickCount(); + arg->tlm.transmit(arg->rocket_data, arg->led); + float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; + ProcessTime new_processTime; + new_processTime.dt; + strcpy(new_processTime.ProcessName, "telemetry"); + + THREAD_SLEEP(1); } } From d14affa1dafb47f333d41315594bed6f68cf11c3 Mon Sep 17 00:00:00 2001 From: kUin1 Date: Sat, 5 Oct 2024 14:44:08 -0500 Subject: [PATCH 2/9] added log statement --- MIDAS/src/rocket_state.h | 1 + MIDAS/src/systems.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/MIDAS/src/rocket_state.h b/MIDAS/src/rocket_state.h index 139acd3d..4899b5c0 100644 --- a/MIDAS/src/rocket_state.h +++ b/MIDAS/src/rocket_state.h @@ -176,6 +176,7 @@ struct RocketData { SensorData magnetometer; SensorData orientation; SensorData voltage; + SensorData processTime; Latency log_latency; }; diff --git a/MIDAS/src/systems.cpp b/MIDAS/src/systems.cpp index df81fd6e..6b57d54e 100644 --- a/MIDAS/src/systems.cpp +++ b/MIDAS/src/systems.cpp @@ -29,6 +29,7 @@ DECLARE_THREAD(logger, RocketSystems* arg) { ProcessTime new_processTime; new_processTime.dt = dt; strcpy(new_processTime.ProcessName, "logger"); + arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(1); } @@ -45,6 +46,7 @@ DECLARE_THREAD(barometer, RocketSystems* arg) { ProcessTime new_processTime; new_processTime.dt = dt; strcpy(new_processTime.ProcessName, "barometer"); + arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(6); } @@ -67,6 +69,7 @@ DECLARE_THREAD(accelerometers, RocketSystems* arg) { ProcessTime new_processTime; new_processTime.dt = dt; strcpy(new_processTime.ProcessName, "accelerometers"); + arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(2); } @@ -85,6 +88,7 @@ DECLARE_THREAD(orientation, RocketSystems* arg) { ProcessTime new_processTime; new_processTime.dt = dt; strcpy(new_processTime.ProcessName, "orientation"); + arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(100); } @@ -101,6 +105,7 @@ DECLARE_THREAD(magnetometer, RocketSystems* arg) { ProcessTime new_processTime; new_processTime.dt = dt; strcpy(new_processTime.ProcessName, "magnetometer"); + arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(50); //data rate is 155hz so 7 is closest } @@ -135,6 +140,7 @@ DECLARE_THREAD(i2c, RocketSystems* arg) { ProcessTime new_processTime; new_processTime.dt = dt; strcpy(new_processTime.ProcessName, "i2c"); + arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(10); } @@ -163,6 +169,7 @@ DECLARE_THREAD(fsm, RocketSystems* arg) { ProcessTime new_processTime; new_processTime.dt = dt; strcpy(new_processTime.ProcessName, "fsm"); + arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(50); } @@ -178,6 +185,7 @@ DECLARE_THREAD(buzzer, RocketSystems* arg) { ProcessTime new_processTime; new_processTime.dt = dt; strcpy(new_processTime.ProcessName, "buzzer"); + arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(10); } @@ -209,6 +217,7 @@ DECLARE_THREAD(kalman, RocketSystems* arg) { ProcessTime new_processTime; new_processTime.dt; strcpy(new_processTime.ProcessName, "Kalman Filter"); + arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(50); @@ -225,6 +234,7 @@ DECLARE_THREAD(telemetry, RocketSystems* arg) { ProcessTime new_processTime; new_processTime.dt; strcpy(new_processTime.ProcessName, "telemetry"); + arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(1); From 3a3b3be66399d6e7593ed7e501db8d11ba8a0aeb Mon Sep 17 00:00:00 2001 From: kUin1 Date: Sat, 5 Oct 2024 15:26:14 -0500 Subject: [PATCH 3/9] fixed bugs --- MIDAS/src/sensor_data.h | 15 ++++++++++++++- MIDAS/src/systems.cpp | 20 ++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/MIDAS/src/sensor_data.h b/MIDAS/src/sensor_data.h index 7b8a98f0..e4c87b23 100644 --- a/MIDAS/src/sensor_data.h +++ b/MIDAS/src/sensor_data.h @@ -230,6 +230,19 @@ struct PyroState { PyroChannel channels[4]; }; +enum class ProcessName : char { + TELEMETRY = 1, + ORIENTATION = 2, + KALMAN = 3, + BUZZER = 4, + FSM = 5, + I2C = 6, + MAGNETOMETER = 7, + ACCELEROMETERS = 8, + BAROMETER = 9, + LOGGER = 10 +}; + /** * @struct ProcessTime * @@ -237,7 +250,7 @@ struct PyroState { */ struct ProcessTime { - char ProcessName[32]; + ProcessName name; float dt; }; diff --git a/MIDAS/src/systems.cpp b/MIDAS/src/systems.cpp index 6b57d54e..6c922820 100644 --- a/MIDAS/src/systems.cpp +++ b/MIDAS/src/systems.cpp @@ -28,7 +28,7 @@ DECLARE_THREAD(logger, RocketSystems* arg) { float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; ProcessTime new_processTime; new_processTime.dt = dt; - strcpy(new_processTime.ProcessName, "logger"); + new_processTime.name = ProcessName::LOGGER; arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(1); @@ -45,7 +45,7 @@ DECLARE_THREAD(barometer, RocketSystems* arg) { float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; ProcessTime new_processTime; new_processTime.dt = dt; - strcpy(new_processTime.ProcessName, "barometer"); + new_processTime.name = ProcessName::BAROMETER; arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(6); @@ -68,7 +68,7 @@ DECLARE_THREAD(accelerometers, RocketSystems* arg) { float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; ProcessTime new_processTime; new_processTime.dt = dt; - strcpy(new_processTime.ProcessName, "accelerometers"); + new_processTime.name = ProcessName::ACCELEROMETERS; arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(2); @@ -87,7 +87,7 @@ DECLARE_THREAD(orientation, RocketSystems* arg) { float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; ProcessTime new_processTime; new_processTime.dt = dt; - strcpy(new_processTime.ProcessName, "orientation"); + new_processTime.name = ProcessName::ORIENTATION; arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(100); @@ -104,7 +104,7 @@ DECLARE_THREAD(magnetometer, RocketSystems* arg) { float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; ProcessTime new_processTime; new_processTime.dt = dt; - strcpy(new_processTime.ProcessName, "magnetometer"); + new_processTime.name = ProcessName::MAGNETOMETER; arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(50); //data rate is 155hz so 7 is closest @@ -139,7 +139,7 @@ DECLARE_THREAD(i2c, RocketSystems* arg) { float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; ProcessTime new_processTime; new_processTime.dt = dt; - strcpy(new_processTime.ProcessName, "i2c"); + new_processTime.name = ProcessName::I2C; arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(10); @@ -168,7 +168,7 @@ DECLARE_THREAD(fsm, RocketSystems* arg) { float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; ProcessTime new_processTime; new_processTime.dt = dt; - strcpy(new_processTime.ProcessName, "fsm"); + new_processTime.name = ProcessName::FSM; arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(50); @@ -184,7 +184,7 @@ DECLARE_THREAD(buzzer, RocketSystems* arg) { float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; ProcessTime new_processTime; new_processTime.dt = dt; - strcpy(new_processTime.ProcessName, "buzzer"); + new_processTime.name = ProcessName::BUZZER; arg->rocket_data.processTime.update(new_processTime); THREAD_SLEEP(10); @@ -216,7 +216,7 @@ DECLARE_THREAD(kalman, RocketSystems* arg) { dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; ProcessTime new_processTime; new_processTime.dt; - strcpy(new_processTime.ProcessName, "Kalman Filter"); + new_processTime.name = ProcessName::KALMAN; arg->rocket_data.processTime.update(new_processTime); @@ -233,7 +233,7 @@ DECLARE_THREAD(telemetry, RocketSystems* arg) { float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; ProcessTime new_processTime; new_processTime.dt; - strcpy(new_processTime.ProcessName, "telemetry"); + new_processTime.name = ProcessName::TELEMETRY; arg->rocket_data.processTime.update(new_processTime); From 4f9fad05410dd0046e5554a41fc7accb34a91de4 Mon Sep 17 00:00:00 2001 From: kUin1 Date: Sat, 5 Oct 2024 15:50:15 -0500 Subject: [PATCH 4/9] Fixed another bug The code for processing time is tested on the hardware. --- MIDAS/src/data_logging.cpp | 1 + MIDAS/src/sensor_data.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/MIDAS/src/data_logging.cpp b/MIDAS/src/data_logging.cpp index f0a0fe4b..5b3e8b6d 100644 --- a/MIDAS/src/data_logging.cpp +++ b/MIDAS/src/data_logging.cpp @@ -89,6 +89,7 @@ void log_data(LogSink& sink, RocketData& data) { log_from_sensor_data(sink, data.fsm_state); log_from_sensor_data(sink, data.kalman); log_from_sensor_data(sink, data.pyro); + log_from_sensor_data(sink, data.processTime); } #ifndef SILSIM diff --git a/MIDAS/src/sensor_data.h b/MIDAS/src/sensor_data.h index e4c87b23..e03a08ad 100644 --- a/MIDAS/src/sensor_data.h +++ b/MIDAS/src/sensor_data.h @@ -230,7 +230,7 @@ struct PyroState { PyroChannel channels[4]; }; -enum class ProcessName : char { +enum class ProcessName { TELEMETRY = 1, ORIENTATION = 2, KALMAN = 3, From d4629037c5acd73300f9f80dcdbaba01d35a97c4 Mon Sep 17 00:00:00 2001 From: kUin1 Date: Wed, 23 Oct 2024 20:24:27 -0500 Subject: [PATCH 5/9] put logging states into a macro function --- MIDAS/lib/ADS7138Q1/ads7138-q1.cpp | 2 + MIDAS/lib/ADXL355/PL_ADXL355.cpp | 1 + .../Adafruit BNO08x/src/Adafruit_BNO08x.cpp | 2 +- MIDAS/lib/Arduino_LSM6DS3/src/LSM6DS3.cpp | 4 +- MIDAS/lib/MS5611/MS5611.cpp | 2 +- .../src/SparkFun_Qwiic_KX13X.cpp | 2 +- .../src/teseo_liv3f_class.cpp | 7 ++ .../X-NUCLEO-GNSS1A1/src/teseo_liv3f_class.h | 2 +- MIDAS/src/data_logging.cpp | 8 +- MIDAS/src/hardware/Barometer.cpp | 2 +- MIDAS/src/hardware/Continuity.cpp | 2 +- MIDAS/src/hardware/Emmc.cpp | 2 +- MIDAS/src/hardware/GPSSensor.cpp | 2 +- MIDAS/src/hardware/HighG.cpp | 1 + MIDAS/src/hardware/LowG.cpp | 3 +- MIDAS/src/hardware/LowGLSM.cpp | 1 + MIDAS/src/hardware/Magnetometer.cpp | 12 ++- MIDAS/src/hardware/Orientation.cpp | 2 +- MIDAS/src/hardware/Pyro.cpp | 2 +- MIDAS/src/hardware/SDLog.cpp | 2 +- MIDAS/src/log_format.h | 2 + MIDAS/src/rocket_state.h | 1 + MIDAS/src/sensor_data.h | 5 ++ MIDAS/src/systems.cpp | 74 ++++++------------- ground/lib/RadioHead/RH_RF95.cpp | 2 +- 25 files changed, 75 insertions(+), 70 deletions(-) diff --git a/MIDAS/lib/ADS7138Q1/ads7138-q1.cpp b/MIDAS/lib/ADS7138Q1/ads7138-q1.cpp index 2e8630e1..5a0c1de4 100644 --- a/MIDAS/lib/ADS7138Q1/ads7138-q1.cpp +++ b/MIDAS/lib/ADS7138Q1/ads7138-q1.cpp @@ -66,6 +66,8 @@ bool ADS7138Init(){ AdcRegReadResult reg = adc_reg_read(ADC_ADDR, ADC_SYSTEM_STATUS); if(reg.error != AdcError::NoError){ return false; + } else{ + //process profiling continuity sensor initialize error } return reg.value != 0; } diff --git a/MIDAS/lib/ADXL355/PL_ADXL355.cpp b/MIDAS/lib/ADXL355/PL_ADXL355.cpp index d7b743b7..a41dc29e 100644 --- a/MIDAS/lib/ADXL355/PL_ADXL355.cpp +++ b/MIDAS/lib/ADXL355/PL_ADXL355.cpp @@ -136,6 +136,7 @@ namespace PL { SPI.begin(); pinMode(csPin, OUTPUT); digitalWrite(csPin, HIGH); + //process profiling acceleration lowG } //============================================================================== diff --git a/MIDAS/lib/Adafruit BNO08x/src/Adafruit_BNO08x.cpp b/MIDAS/lib/Adafruit BNO08x/src/Adafruit_BNO08x.cpp index f66369fa..53eebdd8 100644 --- a/MIDAS/lib/Adafruit BNO08x/src/Adafruit_BNO08x.cpp +++ b/MIDAS/lib/Adafruit BNO08x/src/Adafruit_BNO08x.cpp @@ -180,7 +180,7 @@ bool Adafruit_BNO08x::begin_SPI(uint8_t cs_pin, uint8_t int_pin, _HAL.getTimeUs = hal_getTimeUs; return _init(sensor_id); -} +}//process profiling orientation /*! @brief Initializer for post i2c/spi init * @param sensor_id Optional unique ID for the sensor set diff --git a/MIDAS/lib/Arduino_LSM6DS3/src/LSM6DS3.cpp b/MIDAS/lib/Arduino_LSM6DS3/src/LSM6DS3.cpp index a695df41..e1627e4d 100644 --- a/MIDAS/lib/Arduino_LSM6DS3/src/LSM6DS3.cpp +++ b/MIDAS/lib/Arduino_LSM6DS3/src/LSM6DS3.cpp @@ -66,9 +66,9 @@ int LSM6DS3Class::begin() // Set the ODR config register to ODR/4 writeRegister(LSM6DS3_CTRL8_XL, 0x09); - + //process profiling acceleration initialized return 1; -} +}//process profiling lowglsm void LSM6DS3Class::end() { diff --git a/MIDAS/lib/MS5611/MS5611.cpp b/MIDAS/lib/MS5611/MS5611.cpp index 74852587..9d9479af 100644 --- a/MIDAS/lib/MS5611/MS5611.cpp +++ b/MIDAS/lib/MS5611/MS5611.cpp @@ -77,7 +77,7 @@ void MS5611::init() { C[reg] = readProm(reg); } SPI.endTransaction(); -} +}//process profiling barometer initialized int MS5611::read(uint8_t bits) { // VARIABLES NAMES BASED ON DATASHEET <- Nice! diff --git a/MIDAS/lib/SparkFun_KX13X_Arduino_Library-1.0.7/src/SparkFun_Qwiic_KX13X.cpp b/MIDAS/lib/SparkFun_KX13X_Arduino_Library-1.0.7/src/SparkFun_Qwiic_KX13X.cpp index f43986f3..3b2cbbf6 100644 --- a/MIDAS/lib/SparkFun_KX13X_Arduino_Library-1.0.7/src/SparkFun_Qwiic_KX13X.cpp +++ b/MIDAS/lib/SparkFun_KX13X_Arduino_Library-1.0.7/src/SparkFun_Qwiic_KX13X.cpp @@ -617,7 +617,7 @@ bool QwiicKX134::beginSPI(uint8_t csPin, uint32_t spiPortSpeed, return true; else return false; -} +}//process profiling acceleration highG // Grabs raw accel data and passes it to the following function to be // converted. diff --git a/MIDAS/lib/X-NUCLEO-GNSS1A1/src/teseo_liv3f_class.cpp b/MIDAS/lib/X-NUCLEO-GNSS1A1/src/teseo_liv3f_class.cpp index ed9c79c8..fbe496e8 100644 --- a/MIDAS/lib/X-NUCLEO-GNSS1A1/src/teseo_liv3f_class.cpp +++ b/MIDAS/lib/X-NUCLEO-GNSS1A1/src/teseo_liv3f_class.cpp @@ -48,6 +48,7 @@ + /* * Constant for strtol base param */ @@ -99,6 +100,10 @@ GNSS_StatusTypeDef TeseoLIV3F::I2CUpdate() { GNSS_PARSER_ParseMsg(&data, (eNMEAMsg)m, buffer); } + } else{ + //process profiling + //LogMessage error; + //error.message = 'GNSS PARSER ERROR'; } strncpy(i2ch.inputString, i2ch.inputString2, sizeof(i2ch.inputString)); memset(i2ch.inputString2, 0, sizeof(i2ch.inputString2)); @@ -127,6 +132,8 @@ GNSS_StatusTypeDef TeseoLIV3F::UARTUpdate() { GNSS_PARSER_ParseMsg(&data, (eNMEAMsg)m, buffer); } + } else{ + //process profiling } memset(uarth.inputString, 0, sizeof(uarth.inputString)); uarth.stringComplete = false; diff --git a/MIDAS/lib/X-NUCLEO-GNSS1A1/src/teseo_liv3f_class.h b/MIDAS/lib/X-NUCLEO-GNSS1A1/src/teseo_liv3f_class.h index 657b5068..d2832cda 100644 --- a/MIDAS/lib/X-NUCLEO-GNSS1A1/src/teseo_liv3f_class.h +++ b/MIDAS/lib/X-NUCLEO-GNSS1A1/src/teseo_liv3f_class.h @@ -132,7 +132,7 @@ class TeseoLIV3F Wire.endTransmission(false); delay(2000); return GNSS_OK; - } + }//process profiling /** * @brief Update the internal data structures of the sensor using the appropriate communication method diff --git a/MIDAS/src/data_logging.cpp b/MIDAS/src/data_logging.cpp index 5b3e8b6d..514f20fc 100644 --- a/MIDAS/src/data_logging.cpp +++ b/MIDAS/src/data_logging.cpp @@ -1,7 +1,7 @@ #include "data_logging.h" #include "log_format.h" #include "log_checksum.h" - +#include /** * @brief Forward decleration of the ID recieving function */ @@ -11,6 +11,10 @@ constexpr ReadingDiscriminant get_discriminant(); /** * @brief macro to associate a certain sensor with a specific number ID */ + +//std::queue logQueue; // data logging for process profiling + + #define ASSOCIATE(ty, id) template<> constexpr ReadingDiscriminant get_discriminant() { return ReadingDiscriminant::id; } ASSOCIATE(LowGData, ID_LOWG) @@ -26,6 +30,7 @@ ASSOCIATE(FSMState, ID_FSM) ASSOCIATE(KalmanData, ID_KALMAN) ASSOCIATE(PyroState, ID_PYRO) ASSOCIATE(ProcessTime, ID_PROCESSTIME); +//ASSOCIATE(LogMessages, ID_LOGMESSAGE) /** * @brief writes a reading, with its ID, timestamp, and data to a specific sink @@ -90,6 +95,7 @@ void log_data(LogSink& sink, RocketData& data) { log_from_sensor_data(sink, data.kalman); log_from_sensor_data(sink, data.pyro); log_from_sensor_data(sink, data.processTime); + //log_from_sensor_data(sink, data.logMessages); } #ifndef SILSIM diff --git a/MIDAS/src/hardware/Barometer.cpp b/MIDAS/src/hardware/Barometer.cpp index 8adae988..d8fdda5b 100644 --- a/MIDAS/src/hardware/Barometer.cpp +++ b/MIDAS/src/hardware/Barometer.cpp @@ -10,7 +10,7 @@ MS5611 MS(MS5611_CS); //singleton object for the MS sensor */ ErrorCode BarometerSensor::init() { MS.init(); - + //process profiling return ErrorCode::NoError; } diff --git a/MIDAS/src/hardware/Continuity.cpp b/MIDAS/src/hardware/Continuity.cpp index a57a5ab0..ce19c95e 100644 --- a/MIDAS/src/hardware/Continuity.cpp +++ b/MIDAS/src/hardware/Continuity.cpp @@ -12,7 +12,7 @@ */ ErrorCode ContinuitySensor::init() { ADS7138Init(); // Ask ADS to init the pins, we still need to get the device to actually read - + //process profiling return ErrorCode::NoError; } diff --git a/MIDAS/src/hardware/Emmc.cpp b/MIDAS/src/hardware/Emmc.cpp index 06bbd5bf..86806108 100644 --- a/MIDAS/src/hardware/Emmc.cpp +++ b/MIDAS/src/hardware/Emmc.cpp @@ -37,6 +37,6 @@ ErrorCode EMMCSink::init(){ if (!file) { return ErrorCode::EmmcCouldNotOpenFile; } - + //process profiling return ErrorCode::NoError; } diff --git a/MIDAS/src/hardware/GPSSensor.cpp b/MIDAS/src/hardware/GPSSensor.cpp index 460d2b8a..5de20c26 100644 --- a/MIDAS/src/hardware/GPSSensor.cpp +++ b/MIDAS/src/hardware/GPSSensor.cpp @@ -16,7 +16,7 @@ TeseoLIV3F teseo(&Wire, GPS_RESET, GPS_ENABLE); // singleton for the teseo g */ ErrorCode GPSSensor::init() { teseo.init(); // always returns ok for some reason - + //process profiling return ErrorCode::NoError; } diff --git a/MIDAS/src/hardware/HighG.cpp b/MIDAS/src/hardware/HighG.cpp index 1123f9bd..68466362 100644 --- a/MIDAS/src/hardware/HighG.cpp +++ b/MIDAS/src/hardware/HighG.cpp @@ -20,6 +20,7 @@ ErrorCode HighGSensor::init() { KX.setRange(3); return ErrorCode::NoError; + //process profiling } /** diff --git a/MIDAS/src/hardware/LowG.cpp b/MIDAS/src/hardware/LowG.cpp index 1eac7371..31f9fae5 100644 --- a/MIDAS/src/hardware/LowG.cpp +++ b/MIDAS/src/hardware/LowG.cpp @@ -16,7 +16,8 @@ ErrorCode LowGSensor::init() { // todo set low pass filter frequency to 250hx sensor.enableMeasurement(); return error; -} + //process profiling +} /** * @brief Reads and returns the data from the sensor diff --git a/MIDAS/src/hardware/LowGLSM.cpp b/MIDAS/src/hardware/LowGLSM.cpp index 951be540..78992e85 100644 --- a/MIDAS/src/hardware/LowGLSM.cpp +++ b/MIDAS/src/hardware/LowGLSM.cpp @@ -13,6 +13,7 @@ ErrorCode LowGLSMSensor::init() { return ErrorCode::GyroCouldNotBeInitialized; } return ErrorCode::NoError; + //process profiling } /** diff --git a/MIDAS/src/hardware/Magnetometer.cpp b/MIDAS/src/hardware/Magnetometer.cpp index 23ef322d..3b1bcdaa 100644 --- a/MIDAS/src/hardware/Magnetometer.cpp +++ b/MIDAS/src/hardware/Magnetometer.cpp @@ -1,8 +1,10 @@ #include - +#include #include "sensors.h" #include "hal.h" +//extern std::queue logQueue; // global variable queue for logging the important status of the sensor. + Adafruit_LIS3MDL LIS3MDL; // global static instance of the sensor ErrorCode MagnetometerSensor::init() { @@ -11,9 +13,13 @@ ErrorCode MagnetometerSensor::init() { } LIS3MDL.setOperationMode(LIS3MDL_CONTINUOUSMODE); // Reading continuously, instead of single-shot or off LIS3MDL.setDataRate(LIS3MDL_DATARATE_155_HZ); - LIS3MDL.setRange(LIS3MDL_RANGE_4_GAUSS); // Earth's magnetic field is 1/2 gauss, can detect high current + LIS3MDL.setRange(LIS3MDL_RANGE_4_GAUSS); + // Earth's magnetic field is 1/2 gauss, can detect high current + //char message[32]; + //snprintf(message, sizeof(message), "Magnetometer init w/ mode:%d rate:%d range:%d", LIS3MDL_CONTINUOUSMODE, static_cast(LIS3MDL_DATARATE_155_HZ), LIS3MDL_RANGE_4_GAUSS); + //logQueue.push(message); return ErrorCode::NoError; -} +}//process profiling Magnetometer MagnetometerSensor::read() { // read from aforementioned global instance of sensor diff --git a/MIDAS/src/hardware/Orientation.cpp b/MIDAS/src/hardware/Orientation.cpp index 0d6a3526..3ccbe4ba 100644 --- a/MIDAS/src/hardware/Orientation.cpp +++ b/MIDAS/src/hardware/Orientation.cpp @@ -23,7 +23,7 @@ ErrorCode OrientationSensor::init() { return ErrorCode::CannotInitBNO; } return ErrorCode::NoError; -} +}//process profiling /** * @brief Turns a quaternion into its corresponding Euler 3D vector representation diff --git a/MIDAS/src/hardware/Pyro.cpp b/MIDAS/src/hardware/Pyro.cpp index 1c5c3bdb..ee374c26 100644 --- a/MIDAS/src/hardware/Pyro.cpp +++ b/MIDAS/src/hardware/Pyro.cpp @@ -55,7 +55,7 @@ ErrorCode Pyro::init() { // } else { return ErrorCode::NoError; // GPIO Driver always claimes it errored even when it doesn't. // } -} +}//process profiling #ifdef IS_SUSTAINER diff --git a/MIDAS/src/hardware/SDLog.cpp b/MIDAS/src/hardware/SDLog.cpp index bb8d1879..6593aa3a 100644 --- a/MIDAS/src/hardware/SDLog.cpp +++ b/MIDAS/src/hardware/SDLog.cpp @@ -30,7 +30,7 @@ ErrorCode SDSink::init() { } return ErrorCode::NoError; -} +}//process profiling /** * @brief Writes a byte buffer to the SD card diff --git a/MIDAS/src/log_format.h b/MIDAS/src/log_format.h index a251fc0d..17dfbb6b 100644 --- a/MIDAS/src/log_format.h +++ b/MIDAS/src/log_format.h @@ -21,6 +21,7 @@ enum ReadingDiscriminant { ID_KALMAN = 11, ID_PYRO = 12, ID_PROCESSTIME = 13, + //ID_LOGMESSAGE = 14 }; @@ -53,5 +54,6 @@ struct LoggedReading { FSMState fsm; PyroState pyro; ProcessTime processtime; + //LogMessages logMessages; } data; }; diff --git a/MIDAS/src/rocket_state.h b/MIDAS/src/rocket_state.h index 4899b5c0..854934aa 100644 --- a/MIDAS/src/rocket_state.h +++ b/MIDAS/src/rocket_state.h @@ -177,6 +177,7 @@ struct RocketData { SensorData orientation; SensorData voltage; SensorData processTime; + //SensorData logMessages; Latency log_latency; }; diff --git a/MIDAS/src/sensor_data.h b/MIDAS/src/sensor_data.h index e03a08ad..4b551030 100644 --- a/MIDAS/src/sensor_data.h +++ b/MIDAS/src/sensor_data.h @@ -254,3 +254,8 @@ struct ProcessTime float dt; }; +struct LogMessages +{ + char message[64]; +}; + diff --git a/MIDAS/src/systems.cpp b/MIDAS/src/systems.cpp index 6c922820..4e7af278 100644 --- a/MIDAS/src/systems.cpp +++ b/MIDAS/src/systems.cpp @@ -9,6 +9,18 @@ #error "At least one of IS_SUSTAINER and IS_BOOSTER must be defined." #endif +#define DEBUG + +#ifdef DEBUG + #define MEASURE_LOOP_TIME(startTime, processName, arg) \ + ProcessTime new_processTime; \ + new_processTime.dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime);; \ + new_processTime.name = processName; \ + arg->rocket_data.processTime.update(new_processTime); +#else + #define MEASURE_LOOP_TIME(startTime, processName, arg) \ // No-op in release mode +#endif + /** * @brief These are all the functions that will run in each task @@ -24,12 +36,8 @@ DECLARE_THREAD(logger, RocketSystems* arg) { log_data(arg->log_sink, arg->rocket_data); arg->rocket_data.log_latency.tick(); - - float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; - ProcessTime new_processTime; - new_processTime.dt = dt; - new_processTime.name = ProcessName::LOGGER; - arg->rocket_data.processTime.update(new_processTime); + + MEASURE_LOOP_TIME(startTime, ProcessName::LOGGER, arg); THREAD_SLEEP(1); } @@ -42,11 +50,7 @@ DECLARE_THREAD(barometer, RocketSystems* arg) { Barometer reading = arg->sensors.barometer.read(); arg->rocket_data.barometer.update(reading); - float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; - ProcessTime new_processTime; - new_processTime.dt = dt; - new_processTime.name = ProcessName::BAROMETER; - arg->rocket_data.processTime.update(new_processTime); + MEASURE_LOOP_TIME(startTime, ProcessName::BAROMETER, arg); THREAD_SLEEP(6); } @@ -65,11 +69,7 @@ DECLARE_THREAD(accelerometers, RocketSystems* arg) { HighGData highg = arg->sensors.high_g.read(); arg->rocket_data.high_g.update(highg); - float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; - ProcessTime new_processTime; - new_processTime.dt = dt; - new_processTime.name = ProcessName::ACCELEROMETERS; - arg->rocket_data.processTime.update(new_processTime); + MEASURE_LOOP_TIME(startTime, ProcessName::ACCELEROMETERS, arg); THREAD_SLEEP(2); } @@ -84,11 +84,7 @@ DECLARE_THREAD(orientation, RocketSystems* arg) { arg->rocket_data.orientation.update(reading); } - float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; - ProcessTime new_processTime; - new_processTime.dt = dt; - new_processTime.name = ProcessName::ORIENTATION; - arg->rocket_data.processTime.update(new_processTime); + MEASURE_LOOP_TIME(startTime, ProcessName::ORIENTATION, arg); THREAD_SLEEP(100); } @@ -101,11 +97,7 @@ DECLARE_THREAD(magnetometer, RocketSystems* arg) { Magnetometer reading = arg->sensors.magnetometer.read(); arg->rocket_data.magnetometer.update(reading); - float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; - ProcessTime new_processTime; - new_processTime.dt = dt; - new_processTime.name = ProcessName::MAGNETOMETER; - arg->rocket_data.processTime.update(new_processTime); + MEASURE_LOOP_TIME(startTime, ProcessName::MAGNETOMETER, arg); THREAD_SLEEP(50); //data rate is 155hz so 7 is closest } @@ -136,11 +128,7 @@ DECLARE_THREAD(i2c, RocketSystems* arg) { arg->led.update(); i += 1; - float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; - ProcessTime new_processTime; - new_processTime.dt = dt; - new_processTime.name = ProcessName::I2C; - arg->rocket_data.processTime.update(new_processTime); + MEASURE_LOOP_TIME(startTime, ProcessName::I2C, arg); THREAD_SLEEP(10); } @@ -165,11 +153,7 @@ DECLARE_THREAD(fsm, RocketSystems* arg) { already_played_freebird = true; } - float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; - ProcessTime new_processTime; - new_processTime.dt = dt; - new_processTime.name = ProcessName::FSM; - arg->rocket_data.processTime.update(new_processTime); + MEASURE_LOOP_TIME(startTime, ProcessName::FSM, arg); THREAD_SLEEP(50); } @@ -181,11 +165,7 @@ DECLARE_THREAD(buzzer, RocketSystems* arg) { arg->buzzer.tick(); - float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; - ProcessTime new_processTime; - new_processTime.dt = dt; - new_processTime.name = ProcessName::BUZZER; - arg->rocket_data.processTime.update(new_processTime); + MEASURE_LOOP_TIME(startTime, ProcessName::BUZZER, arg); THREAD_SLEEP(10); } @@ -213,11 +193,7 @@ DECLARE_THREAD(kalman, RocketSystems* arg) { arg->rocket_data.kalman.update(current_state); last = xTaskGetTickCount(); - dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; - ProcessTime new_processTime; - new_processTime.dt; - new_processTime.name = ProcessName::KALMAN; - arg->rocket_data.processTime.update(new_processTime); + MEASURE_LOOP_TIME(startTime, ProcessName::KALMAN, arg); THREAD_SLEEP(50); @@ -230,11 +206,7 @@ DECLARE_THREAD(telemetry, RocketSystems* arg) { arg->tlm.transmit(arg->rocket_data, arg->led); - float dt = pdTICKS_TO_MS(xTaskGetTickCount() - startTime) / 1000.0f; - ProcessTime new_processTime; - new_processTime.dt; - new_processTime.name = ProcessName::TELEMETRY; - arg->rocket_data.processTime.update(new_processTime); + MEASURE_LOOP_TIME(startTime, ProcessName::TELEMETRY, arg); THREAD_SLEEP(1); diff --git a/ground/lib/RadioHead/RH_RF95.cpp b/ground/lib/RadioHead/RH_RF95.cpp index 655bbabe..a22f5e67 100644 --- a/ground/lib/RadioHead/RH_RF95.cpp +++ b/ground/lib/RadioHead/RH_RF95.cpp @@ -188,7 +188,7 @@ void RH_RF95::handleInterrupt() // our ISR will be reinvoked to handle that case) // kevinh: turn this off until root cause is known, because it can cause missed interrupts! // spiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags - spiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags + spiWrite(RH_RF95_REG_12_IRQ_FLAGS, 0xff); // Clear all IRQ flags // error if: // timeout From 790c7062bdd9a5990db769eac4509cba208d783a Mon Sep 17 00:00:00 2001 From: kUin1 Date: Thu, 31 Oct 2024 20:47:05 -0500 Subject: [PATCH 6/9] added message logging --- MIDAS/src/data_logging.cpp | 4 ++-- MIDAS/src/hardware/Barometer.cpp | 3 +++ MIDAS/src/hardware/Continuity.cpp | 5 ++++- MIDAS/src/hardware/HighG.cpp | 10 +++++++++- MIDAS/src/hardware/Magnetometer.cpp | 14 ++++++++++---- MIDAS/src/log_format.h | 4 ++-- MIDAS/src/rocket_state.h | 2 +- MIDAS/src/systems.cpp | 15 +++++++++++++++ 8 files changed, 46 insertions(+), 11 deletions(-) diff --git a/MIDAS/src/data_logging.cpp b/MIDAS/src/data_logging.cpp index 514f20fc..925dac58 100644 --- a/MIDAS/src/data_logging.cpp +++ b/MIDAS/src/data_logging.cpp @@ -30,7 +30,7 @@ ASSOCIATE(FSMState, ID_FSM) ASSOCIATE(KalmanData, ID_KALMAN) ASSOCIATE(PyroState, ID_PYRO) ASSOCIATE(ProcessTime, ID_PROCESSTIME); -//ASSOCIATE(LogMessages, ID_LOGMESSAGE) +ASSOCIATE(LogMessages, ID_LOGMESSAGE) /** * @brief writes a reading, with its ID, timestamp, and data to a specific sink @@ -95,7 +95,7 @@ void log_data(LogSink& sink, RocketData& data) { log_from_sensor_data(sink, data.kalman); log_from_sensor_data(sink, data.pyro); log_from_sensor_data(sink, data.processTime); - //log_from_sensor_data(sink, data.logMessages); + log_from_sensor_data(sink, data.logMessages); } #ifndef SILSIM diff --git a/MIDAS/src/hardware/Barometer.cpp b/MIDAS/src/hardware/Barometer.cpp index d8fdda5b..8536a45d 100644 --- a/MIDAS/src/hardware/Barometer.cpp +++ b/MIDAS/src/hardware/Barometer.cpp @@ -1,7 +1,9 @@ #include "sensors.h" #include +#include MS5611 MS(MS5611_CS); //singleton object for the MS sensor +extern std::queue logQueue; /** * @brief Initializes barometer, returns NoError @@ -11,6 +13,7 @@ MS5611 MS(MS5611_CS); //singleton object for the MS sensor ErrorCode BarometerSensor::init() { MS.init(); //process profiling + logQueue.push("BarometerInitialized"); return ErrorCode::NoError; } diff --git a/MIDAS/src/hardware/Continuity.cpp b/MIDAS/src/hardware/Continuity.cpp index ce19c95e..3aba09c4 100644 --- a/MIDAS/src/hardware/Continuity.cpp +++ b/MIDAS/src/hardware/Continuity.cpp @@ -1,9 +1,12 @@ #include "sensors.h" #include "ads7138-q1.h" #include +#include + #define PYRO_VOLTAGE_DIVIDER (5.0 / (5.0 + 20.0)) //voltage divider for pyro batt voltage, check hardware schematic #define CONT_VOLTAGE_DIVIDER (5.0 / (5.0 + 20.0)) //voltage divider for continuity voltage, check hardware schematic +extern std::queue logQueue; /** * @brief Initializes ADC, returns NoError @@ -12,7 +15,7 @@ */ ErrorCode ContinuitySensor::init() { ADS7138Init(); // Ask ADS to init the pins, we still need to get the device to actually read - //process profiling + logQueue.push("BarometerInitialized");//process profiling return ErrorCode::NoError; } diff --git a/MIDAS/src/hardware/HighG.cpp b/MIDAS/src/hardware/HighG.cpp index 68466362..bcc033f3 100644 --- a/MIDAS/src/hardware/HighG.cpp +++ b/MIDAS/src/hardware/HighG.cpp @@ -1,7 +1,9 @@ #include "sensors.h" #include "SparkFun_Qwiic_KX13X.h" +#include QwiicKX134 KX; // global static instance of the sensor +extern std::queue logQueue; /** * @brief Initializes the high G sensor @@ -11,16 +13,22 @@ QwiicKX134 KX; // global static instance of the sensor ErrorCode HighGSensor::init() { KX.beginSPI(KX134_CS); if (!KX.initialize(DEFAULT_SETTINGS)) { + + logQueue.push("HighGCouldNotBeInitialized");//process profiling return ErrorCode::HighGCouldNotBeInitialized; } if(!KX.setOutputDataRate(0xb)) { + logQueue.push("HighGCouldNotUpdateDataRate");//process profiling return ErrorCode::HighGCouldNotUpdateDataRate; } + + logQueue.push("HighGInitialized");//process profiling KX.setRange(3); return ErrorCode::NoError; - //process profiling + + } /** diff --git a/MIDAS/src/hardware/Magnetometer.cpp b/MIDAS/src/hardware/Magnetometer.cpp index 3b1bcdaa..2686341c 100644 --- a/MIDAS/src/hardware/Magnetometer.cpp +++ b/MIDAS/src/hardware/Magnetometer.cpp @@ -3,7 +3,7 @@ #include "sensors.h" #include "hal.h" -//extern std::queue logQueue; // global variable queue for logging the important status of the sensor. +extern std::queue logQueue; // global variable queue for logging the important status of the sensor. Adafruit_LIS3MDL LIS3MDL; // global static instance of the sensor @@ -15,9 +15,9 @@ ErrorCode MagnetometerSensor::init() { LIS3MDL.setDataRate(LIS3MDL_DATARATE_155_HZ); LIS3MDL.setRange(LIS3MDL_RANGE_4_GAUSS); // Earth's magnetic field is 1/2 gauss, can detect high current - //char message[32]; - //snprintf(message, sizeof(message), "Magnetometer init w/ mode:%d rate:%d range:%d", LIS3MDL_CONTINUOUSMODE, static_cast(LIS3MDL_DATARATE_155_HZ), LIS3MDL_RANGE_4_GAUSS); - //logQueue.push(message); + char message[64]; + snprintf(message, sizeof(message), "MagnetometerInitizedW/Mode:%dRate:%dRange:%d", LIS3MDL_CONTINUOUSMODE, static_cast(LIS3MDL_DATARATE_155_HZ), LIS3MDL_RANGE_4_GAUSS); + logQueue.push(message); return ErrorCode::NoError; }//process profiling @@ -31,3 +31,9 @@ Magnetometer MagnetometerSensor::read() { Magnetometer reading{mx, my, mz}; return reading; } + +//void addMessageQueue(String m){ + // char message[64]; + //snprintf(message, sizeof(message), m); + //logQueue.push(message); +//} \ No newline at end of file diff --git a/MIDAS/src/log_format.h b/MIDAS/src/log_format.h index 17dfbb6b..b6def08c 100644 --- a/MIDAS/src/log_format.h +++ b/MIDAS/src/log_format.h @@ -21,7 +21,7 @@ enum ReadingDiscriminant { ID_KALMAN = 11, ID_PYRO = 12, ID_PROCESSTIME = 13, - //ID_LOGMESSAGE = 14 + ID_LOGMESSAGE = 14 }; @@ -54,6 +54,6 @@ struct LoggedReading { FSMState fsm; PyroState pyro; ProcessTime processtime; - //LogMessages logMessages; + LogMessages logMessages; } data; }; diff --git a/MIDAS/src/rocket_state.h b/MIDAS/src/rocket_state.h index 854934aa..0a7cafcb 100644 --- a/MIDAS/src/rocket_state.h +++ b/MIDAS/src/rocket_state.h @@ -177,7 +177,7 @@ struct RocketData { SensorData orientation; SensorData voltage; SensorData processTime; - //SensorData logMessages; + SensorData logMessages; Latency log_latency; }; diff --git a/MIDAS/src/systems.cpp b/MIDAS/src/systems.cpp index 4e7af278..439defc6 100644 --- a/MIDAS/src/systems.cpp +++ b/MIDAS/src/systems.cpp @@ -1,5 +1,7 @@ #include "systems.h" +#include + #include "hal.h" #include "gnc/yessir.h" @@ -21,6 +23,7 @@ #define MEASURE_LOOP_TIME(startTime, processName, arg) \ // No-op in release mode #endif +std::queue logQueue; /** * @brief These are all the functions that will run in each task @@ -43,6 +46,18 @@ DECLARE_THREAD(logger, RocketSystems* arg) { } } +DECLARE_THREAD(messages, RocketSystems* arg){ + while(true){ + if(!logQueue.empty()){ + LogMessages newMessage; + std::strncpy(newMessage.message, logQueue.front().c_str(), sizeof(newMessage.message) - 1); + newMessage.message[sizeof(newMessage.message) - 1] = '\0'; + arg->rocket_data.logMessages.update(newMessage); + THREAD_SLEEP(20); + } + } +} + DECLARE_THREAD(barometer, RocketSystems* arg) { while (true) { TickType_t startTime = xTaskGetTickCount(); From e93e6ae919b156117703f52c6dc1cbd43e0d124e Mon Sep 17 00:00:00 2001 From: kUin1 Date: Thu, 31 Oct 2024 21:06:20 -0500 Subject: [PATCH 7/9] fix bug --- MIDAS/.gitignore | 1 - MIDAS/src/log_checksum.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 MIDAS/src/log_checksum.h diff --git a/MIDAS/.gitignore b/MIDAS/.gitignore index 4ba81f14..15541236 100644 --- a/MIDAS/.gitignore +++ b/MIDAS/.gitignore @@ -1,5 +1,4 @@ .pio .vscode -/src/log_checksum.h **/.DS_Store *.launch diff --git a/MIDAS/src/log_checksum.h b/MIDAS/src/log_checksum.h new file mode 100644 index 00000000..0eb10445 --- /dev/null +++ b/MIDAS/src/log_checksum.h @@ -0,0 +1,2 @@ +// autogenerated on build by applying crc32 on the concatenation of log_format.h and sensor_data.h +#define LOG_CHECKSUM (0xde027446) From 088d07241efea5d70b9d70dbbd87cbdcffe42ba7 Mon Sep 17 00:00:00 2001 From: kUin1 Date: Thu, 31 Oct 2024 21:07:47 -0500 Subject: [PATCH 8/9] fixed bug --- MIDAS/src/log_format.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MIDAS/src/log_format.h b/MIDAS/src/log_format.h index b6def08c..4f5f00c2 100644 --- a/MIDAS/src/log_format.h +++ b/MIDAS/src/log_format.h @@ -21,7 +21,7 @@ enum ReadingDiscriminant { ID_KALMAN = 11, ID_PYRO = 12, ID_PROCESSTIME = 13, - ID_LOGMESSAGE = 14 + ID_LOGMESSAGES = 14 }; From 46b1af3a002a9ab9b5ec49b79b6044008ac122cf Mon Sep 17 00:00:00 2001 From: kUin1 Date: Thu, 31 Oct 2024 21:14:17 -0500 Subject: [PATCH 9/9] bug fixed --- MIDAS/src/data_logging.cpp | 2 +- MIDAS/src/log_checksum.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MIDAS/src/data_logging.cpp b/MIDAS/src/data_logging.cpp index 925dac58..08db0ffe 100644 --- a/MIDAS/src/data_logging.cpp +++ b/MIDAS/src/data_logging.cpp @@ -30,7 +30,7 @@ ASSOCIATE(FSMState, ID_FSM) ASSOCIATE(KalmanData, ID_KALMAN) ASSOCIATE(PyroState, ID_PYRO) ASSOCIATE(ProcessTime, ID_PROCESSTIME); -ASSOCIATE(LogMessages, ID_LOGMESSAGE) +ASSOCIATE(LogMessages, ID_LOGMESSAGES) /** * @brief writes a reading, with its ID, timestamp, and data to a specific sink diff --git a/MIDAS/src/log_checksum.h b/MIDAS/src/log_checksum.h index 0eb10445..4abe9b14 100644 --- a/MIDAS/src/log_checksum.h +++ b/MIDAS/src/log_checksum.h @@ -1,2 +1,2 @@ // autogenerated on build by applying crc32 on the concatenation of log_format.h and sensor_data.h -#define LOG_CHECKSUM (0xde027446) +#define LOG_CHECKSUM (0xb8f3527e)