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
8
9constexpr float GRAVITY = 9.8;
10
11uint32_t tempTimeStamp =0;
12int count = 0;
13
15 LaunchDetector* launchDetector,
16 ApogeeDetector* apogeeDetector,
17 VerticalVelocityEstimator* verticalVelocityEstimator)
18 : dataSaver(dataSaver),
19 launchDetector(launchDetector),
20 apogeeDetector(apogeeDetector),
21 verticalVelocityEstimator(verticalVelocityEstimator),
22 state(STATE_ARMED)
23{
24}
25
27 // Update the state
28 int lpStatus = LP_DEFAULT_FAIL;
29
30 if(count == 0)
31 {
33 count++;
34 }
35 switch (state) {
36 case STATE_ARMED:
37 // Serial.println("lp update");
38 lpStatus = launchDetector->update(accel);
39 // Serial.println(lpStatus);
40 if (launchDetector->isLaunched()) {
41 // Change state to ascent
43
44 // Log the state change
45 Serial.println("To pa (launch detected)");
46 Serial.print("PA timestamp: ");
47 Serial.println(accel.x.timestamp_ms);
48 dataSaver->saveDataPoint(
51 );
52
53 // Put the data saver into post-launch mode
54 dataSaver->launchDetected(launchDetector->getLaunchedTime());
55
56 // Start the vertical velocity estimator
57 verticalVelocityEstimator->update(accel, alt);
58
59 // Start the apogee detection system
60 apogeeDetector->init({alt.data, alt.timestamp_ms});
61
62 }
63 break;
64
66 // Serial.println("apogee update");
67 verticalVelocityEstimator->update(accel, alt);
68 apogeeDetector->update(verticalVelocityEstimator);
69 Serial.println(verticalVelocityEstimator->getInertialVerticalAcceleration());
70 if (verticalVelocityEstimator->getInertialVerticalAcceleration() <= 0) { // when acceleration returns to less than gravity after launch, we're coasting
71 state = STATE_COAST_ASCENT;
72
73 // Log the state change
74 Serial.println("To ca");
75 Serial.print("CA timestamp: ");
76 Serial.println(accel.y.timestamp_ms);
77 dataSaver->saveDataPoint(
80 );
81 }
82 break;
83
85 verticalVelocityEstimator->update(accel, alt);
86 apogeeDetector->update(verticalVelocityEstimator);
87 if (apogeeDetector->isApogeeDetected()) {
88 state = STATE_DESCENT;
89
90 // Log the state change
91 Serial.println("To descent");
92 Serial.print("Descent timestamp: ");
93 Serial.println(accel.x.timestamp_ms);
94 dataSaver->saveDataPoint(
97 );
98 }
99 break;
100
101 case STATE_DESCENT:
102 // Do nothing
103 break;
104 }
105
106 return 0;
107}
108
110 return state;
111}
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:18
@ STATE_DESCENT
Definition States.h:19
@ STATE_POWERED_ASCENT
Definition States.h:17
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