Avionics
Core avionics package for CURE flight computers
Loading...
Searching...
No Matches
BurnoutStateMachine.cpp
Go to the documentation of this file.
1#include "ArduinoHAL.h"
2
7
8constexpr float GRAVITY = 9.8;
9
10uint32_t tempTimeStamp =0;
11int count = 0;
12
14 LaunchDetector* launchDetector,
15 ApogeeDetector* apogeeDetector,
16 VerticalVelocityEstimator* verticalVelocityEstimator)
17 : dataSaver(dataSaver),
18 launchDetector(launchDetector),
19 apogeeDetector(apogeeDetector),
20 verticalVelocityEstimator(verticalVelocityEstimator),
21 state(STATE_ARMED)
22{
23}
24
26 // Update the state
27 int lpStatus = LP_DEFAULT_FAIL;
28
29 if(count == 0)
30 {
32 count++;
33 }
34 switch (state) {
35 case STATE_ARMED:
36 // Serial.println("lp update");
37 lpStatus = launchDetector->update(accel);
38 // Serial.println(lpStatus);
39 if (launchDetector->isLaunched()) {
40 // Change state to ascent
42
43 // Log the state change
44 Serial.println("To pa (launch detected)");
45 Serial.print("PA timestamp: ");
46 Serial.println(accel.x.timestamp_ms);
47 dataSaver->saveDataPoint(
50 );
51
52 // Put the data saver into post-launch mode
53 dataSaver->launchDetected(launchDetector->getLaunchedTime());
54
55 // Start the vertical velocity estimator
56 verticalVelocityEstimator->update(accel, alt);
57
58 // Start the apogee detection system
59 apogeeDetector->init({alt.data, alt.timestamp_ms});
60
61 }
62 break;
63
65 // Serial.println("apogee update");
66 verticalVelocityEstimator->update(accel, alt);
67 apogeeDetector->update(verticalVelocityEstimator);
68 Serial.println(verticalVelocityEstimator->getInertialVerticalAcceleration());
69 if (verticalVelocityEstimator->getInertialVerticalAcceleration() <= 0) { // when acceleration returns to less than gravity after launch, we're coasting
70 state = STATE_COAST_ASCENT;
71
72 // Log the state change
73 Serial.println("To ca");
74 Serial.print("CA timestamp: ");
75 Serial.println(accel.y.timestamp_ms);
76 dataSaver->saveDataPoint(
79 );
80 }
81 break;
82
84 verticalVelocityEstimator->update(accel, alt);
85 apogeeDetector->update(verticalVelocityEstimator);
86 if (apogeeDetector->isApogeeDetected()) {
87 state = STATE_DESCENT;
88
89 // Log the state change
90 Serial.println("To descent");
91 Serial.print("Descent timestamp: ");
92 Serial.println(accel.x.timestamp_ms);
93 dataSaver->saveDataPoint(
96 );
97 }
98 break;
99
100 case STATE_DESCENT:
101 // Do nothing
102 break;
103 }
104
105 return 0;
106}
107
109 return state;
110}
constexpr float GRAVITY
uint32_t tempTimeStamp
#define STATE_CHANGE
Definition DataNames.h:26
@ LP_DEFAULT_FAIL
@ STATE_ARMED
Definition States.h:14
@ STATE_COAST_ASCENT
Definition States.h:17
@ STATE_DESCENT
Definition States.h:18
@ STATE_POWERED_ASCENT
Definition States.h:16
Detects the apogee (peak altitude) of a rocket flight using estimated altitude and vertical velocity.
int update(const AccelerationTriplet &accel, const DataPoint &alt) override
Update machine with new sensor inputs and transition on burnout cues.
BurnoutStateMachine(IDataSaver *dataSaver, LaunchDetector *launchDetector, ApogeeDetector *apogeeDetector, VerticalVelocityEstimator *verticalVelocityEstimator)
Construct with logging and detector dependencies.
uint8_t getState() const override
Current state identifier.
Timestamped float measurement container.
Definition DataPoint.h:11
float data
Definition DataPoint.h:14
uint32_t timestamp_ms
Definition DataPoint.h:13
Abstract interface for persisting timestamped data points.
Definition DataSaver.h:13
Sliding-window launch detector based on acceleration magnitude.
1D Kalman filter fusing altimeter and accelerometer data.
MockSerial Serial