From e9b2d3e424efb6345d8749843fdf12abc47a042d Mon Sep 17 00:00:00 2001 From: Thomas Day Date: Wed, 9 Sep 2026 15:44:41 -0400 Subject: [PATCH 1/3] Added data names for new sensor data in JEM --- include/data_handling/DataNames.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/data_handling/DataNames.h b/include/data_handling/DataNames.h index 50fcb76..8f0170f 100644 --- a/include/data_handling/DataNames.h +++ b/include/data_handling/DataNames.h @@ -45,4 +45,18 @@ // Payload #define PROBE_TEMPERATURE 28 +// JEM +#define BMI_ACCEL_X 29 +#define BMI_ACCEL_Y 30 +#define BMI_ACCEL_Z 31 +#define BMI_GYRO_X 32 +#define BMI_GYRO_Y 33 +#define BMI_GYRO_Z 34 +#define MS5_PRESSURE 35 +#define MS5_TEMP 36 +#define MS5_ALTITUDE 37 +#define KX_ACCEL_X 38 +#define KX_ACCEL_Y 39 +#define KX_ACCEL_Z 40 + #endif From db6096a9fb4e046b5e53116dd79c05d691d14748 Mon Sep 17 00:00:00 2001 From: Thomas Day Date: Fri, 18 Sep 2026 13:38:03 -0400 Subject: [PATCH 2/3] Updated code to not conflict with Eduardo --- include/data_handling/DataNames.h | 24 ++-- .../test_state_machine_csv.cpp | 125 ++++++++++++++++++ 2 files changed, 137 insertions(+), 12 deletions(-) create mode 100644 test/test_basic_state_machine/test_state_machine_csv.cpp diff --git a/include/data_handling/DataNames.h b/include/data_handling/DataNames.h index 8f0170f..1a1f2b2 100644 --- a/include/data_handling/DataNames.h +++ b/include/data_handling/DataNames.h @@ -46,17 +46,17 @@ #define PROBE_TEMPERATURE 28 // JEM -#define BMI_ACCEL_X 29 -#define BMI_ACCEL_Y 30 -#define BMI_ACCEL_Z 31 -#define BMI_GYRO_X 32 -#define BMI_GYRO_Y 33 -#define BMI_GYRO_Z 34 -#define MS5_PRESSURE 35 -#define MS5_TEMP 36 -#define MS5_ALTITUDE 37 -#define KX_ACCEL_X 38 -#define KX_ACCEL_Y 39 -#define KX_ACCEL_Z 40 +#define CURE_BMI_ACCEL_X 29 +#define CURE_BMI_ACCEL_Y 30 +#define CURE_BMI_ACCEL_Z 31 +#define CURE_BMI_GYRO_X 32 +#define CURE_BMI_GYRO_Y 33 +#define CURE_BMI_GYRO_Z 34 +#define CURE_MS5_PRESSURE 35 +#define CURE_MS5_TEMP 36 +#define CURE_MS5_ALTITUDE 37 +#define CURE_KX_ACCEL_X 38 +#define CURE_KX_ACCEL_Y 39 +#define CURE_KX_ACCEL_Z 40 #endif diff --git a/test/test_basic_state_machine/test_state_machine_csv.cpp b/test/test_basic_state_machine/test_state_machine_csv.cpp new file mode 100644 index 0000000..55b74b2 --- /dev/null +++ b/test/test_basic_state_machine/test_state_machine_csv.cpp @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include +#include "unity.h" +#include "state_estimation/BasicStateMachine.h" +#include "state_estimation/LaunchDetector.h" +#include "state_estimation/ApogeeDetector.h" +#include "state_estimation/VerticalVelocityEstimator.h" +#include "data_handling/DataPoint.h" +#include "DataSaver_mock.h" +#include "../CSVMockData.h" + +/** + * Test the BasicStateMachine using real flight data from CSV. + * This test reads sensor data from a CSV file, feeds it into the state machine, + * and logs the results including launch and apogee predictions. + */ +void test_state_machine_with_real_data(void) { + // Create CSV provider to read test data with 25Hz sample rate (40ms interval) + CSVDataProvider provider("data/MARTHA_3-8_1.3_B2_SingleID_transformed.csv", 25.0f); + + // Initialize components + LaunchDetector lp(30, 1000, 40); // threshold, window, min samples + ApogeeDetector ad; + VerticalVelocityEstimator vve; + DataSaverMock dataSaver; + FastLaunchDetector fld (30, 500); + BasicStateMachine sm(&dataSaver, &lp, &ad, &vve, &fld); + + // Create output CSV file for analysis + std::ofstream outputFile("state_machine_results.csv"); + if (!outputFile.is_open()) { + std::cerr << "Failed to open output CSV file" << std::endl; + TEST_FAIL(); + return; + } + + // Write CSV header + outputFile << "timestamp,accelX,accelY,accelZ,raw_altitude,state,launch_predicted,apogee_predicted,estimated_altitude,estimated_velocity\n"; + + bool hasData = false; + float maxAltitude = -1000.0f; + uint32_t maxAltitudeTime = 0; + uint32_t launchTime = 0; + + // Process each data point at 25Hz + while (provider.hasNextDataPoint()) { + hasData = true; + SensorData data = provider.getNextDataPoint(); + + // Create DataPoints for the state machine + DataPoint accelX(data.time, data.accelx); + DataPoint accelY(data.time, data.accely); + DataPoint accelZ(data.time, data.accelz); + DataPoint alt(data.time, data.altitude); + + AccelerationTriplet accel = {accelX, accelY, accelZ}; + + // Update state machine with sensor data + sm.update(accel, alt); + + // Track maximum altitude for validation + if (data.altitude > maxAltitude) { + maxAltitude = data.altitude; + maxAltitudeTime = data.time; + } + + // Track launch time + if (lp.isLaunched() && launchTime == 0) { + launchTime = lp.getLaunchedTime(); + } + + // Write results to CSV + // Only output apogee predictions after launch is detected + float estAlt = 0.0f; + float estVel = 0.0f; + if (sm.getState() >= STATE_ASCENT) { + estAlt = vve.getEstimatedAltitude(); + estVel = vve.getEstimatedVelocity(); + } + + outputFile << data.time << "," + << data.accelx << "," + << data.accely << "," + << data.accelz << "," + << data.altitude << "," + << sm.getState() << "," + << (lp.isLaunched() ? "1" : "0") << "," + << (ad.isApogeeDetected() ? "1" : "0") << "," + << estAlt << "," + << estVel << "\n"; + } + + outputFile.close(); + + // Verify test data was processed + TEST_ASSERT_TRUE(hasData); + + // Verify launch was detected + TEST_ASSERT_TRUE(lp.isLaunched()); + + // Verify apogee was detected + TEST_ASSERT_TRUE(ad.isApogeeDetected()); + + // Verify state progression + TEST_ASSERT_GREATER_THAN(STATE_ARMED, sm.getState()); + + // Get detected apogee information + DataPoint detectedApogee = ad.getApogee(); + + // Verify apogee altitude is reasonable (within 10% of max recorded altitude) + float altitudeDifference = std::abs(detectedApogee.data - maxAltitude); + float allowedError = maxAltitude * 0.10f; + TEST_ASSERT_TRUE_MESSAGE(altitudeDifference <= allowedError, + "Detected apogee altitude differs significantly from maximum recorded altitude"); + + // Verify apogee timing is reasonable (within 1 second of max altitude time) + const int64_t timeDifference_ms = std::llabs( + static_cast(detectedApogee.timestamp_ms) - static_cast(maxAltitudeTime)); + TEST_ASSERT_TRUE_MESSAGE(timeDifference_ms <= 1000LL, + "Detected apogee time differs significantly from maximum altitude time"); +} From 7633cb63db68a3302d227a9a326d1832b1ce9bba Mon Sep 17 00:00:00 2001 From: Thomas Day <122122322+Mayday-01@users.noreply.github.com> Date: Fri, 18 Sep 2026 13:41:25 -0400 Subject: [PATCH 3/3] Delete test/test_basic_state_machine/test_state_machine_csv.cpp I'm just going to merge the new version whenever i merge --- .../test_state_machine_csv.cpp | 125 ------------------ 1 file changed, 125 deletions(-) delete mode 100644 test/test_basic_state_machine/test_state_machine_csv.cpp diff --git a/test/test_basic_state_machine/test_state_machine_csv.cpp b/test/test_basic_state_machine/test_state_machine_csv.cpp deleted file mode 100644 index 55b74b2..0000000 --- a/test/test_basic_state_machine/test_state_machine_csv.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include "unity.h" -#include "state_estimation/BasicStateMachine.h" -#include "state_estimation/LaunchDetector.h" -#include "state_estimation/ApogeeDetector.h" -#include "state_estimation/VerticalVelocityEstimator.h" -#include "data_handling/DataPoint.h" -#include "DataSaver_mock.h" -#include "../CSVMockData.h" - -/** - * Test the BasicStateMachine using real flight data from CSV. - * This test reads sensor data from a CSV file, feeds it into the state machine, - * and logs the results including launch and apogee predictions. - */ -void test_state_machine_with_real_data(void) { - // Create CSV provider to read test data with 25Hz sample rate (40ms interval) - CSVDataProvider provider("data/MARTHA_3-8_1.3_B2_SingleID_transformed.csv", 25.0f); - - // Initialize components - LaunchDetector lp(30, 1000, 40); // threshold, window, min samples - ApogeeDetector ad; - VerticalVelocityEstimator vve; - DataSaverMock dataSaver; - FastLaunchDetector fld (30, 500); - BasicStateMachine sm(&dataSaver, &lp, &ad, &vve, &fld); - - // Create output CSV file for analysis - std::ofstream outputFile("state_machine_results.csv"); - if (!outputFile.is_open()) { - std::cerr << "Failed to open output CSV file" << std::endl; - TEST_FAIL(); - return; - } - - // Write CSV header - outputFile << "timestamp,accelX,accelY,accelZ,raw_altitude,state,launch_predicted,apogee_predicted,estimated_altitude,estimated_velocity\n"; - - bool hasData = false; - float maxAltitude = -1000.0f; - uint32_t maxAltitudeTime = 0; - uint32_t launchTime = 0; - - // Process each data point at 25Hz - while (provider.hasNextDataPoint()) { - hasData = true; - SensorData data = provider.getNextDataPoint(); - - // Create DataPoints for the state machine - DataPoint accelX(data.time, data.accelx); - DataPoint accelY(data.time, data.accely); - DataPoint accelZ(data.time, data.accelz); - DataPoint alt(data.time, data.altitude); - - AccelerationTriplet accel = {accelX, accelY, accelZ}; - - // Update state machine with sensor data - sm.update(accel, alt); - - // Track maximum altitude for validation - if (data.altitude > maxAltitude) { - maxAltitude = data.altitude; - maxAltitudeTime = data.time; - } - - // Track launch time - if (lp.isLaunched() && launchTime == 0) { - launchTime = lp.getLaunchedTime(); - } - - // Write results to CSV - // Only output apogee predictions after launch is detected - float estAlt = 0.0f; - float estVel = 0.0f; - if (sm.getState() >= STATE_ASCENT) { - estAlt = vve.getEstimatedAltitude(); - estVel = vve.getEstimatedVelocity(); - } - - outputFile << data.time << "," - << data.accelx << "," - << data.accely << "," - << data.accelz << "," - << data.altitude << "," - << sm.getState() << "," - << (lp.isLaunched() ? "1" : "0") << "," - << (ad.isApogeeDetected() ? "1" : "0") << "," - << estAlt << "," - << estVel << "\n"; - } - - outputFile.close(); - - // Verify test data was processed - TEST_ASSERT_TRUE(hasData); - - // Verify launch was detected - TEST_ASSERT_TRUE(lp.isLaunched()); - - // Verify apogee was detected - TEST_ASSERT_TRUE(ad.isApogeeDetected()); - - // Verify state progression - TEST_ASSERT_GREATER_THAN(STATE_ARMED, sm.getState()); - - // Get detected apogee information - DataPoint detectedApogee = ad.getApogee(); - - // Verify apogee altitude is reasonable (within 10% of max recorded altitude) - float altitudeDifference = std::abs(detectedApogee.data - maxAltitude); - float allowedError = maxAltitude * 0.10f; - TEST_ASSERT_TRUE_MESSAGE(altitudeDifference <= allowedError, - "Detected apogee altitude differs significantly from maximum recorded altitude"); - - // Verify apogee timing is reasonable (within 1 second of max altitude time) - const int64_t timeDifference_ms = std::llabs( - static_cast(detectedApogee.timestamp_ms) - static_cast(maxAltitudeTime)); - TEST_ASSERT_TRUE_MESSAGE(timeDifference_ms <= 1000LL, - "Detected apogee time differs significantly from maximum altitude time"); -}