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
9 LaunchDetector* launchDetector,
10 ApogeeDetector* apogeeDetector,
11 VerticalVelocityEstimator* verticalVelocityEstimator)
13 dataSaver_(dataSaver),
14 launchDetector_(launchDetector),
15 apogeeDetector_(apogeeDetector),
16 verticalVelocityEstimator_(verticalVelocityEstimator)
17
18{
19}
20
22 switch (getFlightState()) {
23 case STATE_ARMED:
24 // Serial.println("lp update");
25 launchDetector_->update(accel);
26 // Serial.println(lpStatus);
27 if (launchDetector_->isLaunched()) {
28 // Change state to ascent.
30
31 // Log the state change.
32 Serial.println("To pa (launch detected)");
33 Serial.print("PA timestamp: ");
34 Serial.println(accel.x.timestamp_ms);
35 dataSaver_->saveDataPoint(
38 );
39
40 // Put the data saver into post-launch mode
41 dataSaver_->launchDetected(launchDetector_->getLaunchedTime());
42
43 // Start the vertical velocity estimator
44 verticalVelocityEstimator_->update(accel, alt);
45
46 // Start the apogee detection system
47 apogeeDetector_->init({alt.data, alt.timestamp_ms});
48
49 }
50 break;
51
53 // Serial.println("apogee update");
54 verticalVelocityEstimator_->update(accel, alt);
55 apogeeDetector_->update(verticalVelocityEstimator_);
56 Serial.println(verticalVelocityEstimator_->getInertialVerticalAcceleration());
57 if (verticalVelocityEstimator_->getInertialVerticalAcceleration() <= 0) { // when acceleration returns to less than gravity after launch, we're coasting
59
60 // Log the state change.
61 Serial.println("To ca");
62 Serial.print("CA timestamp: ");
63 Serial.println(accel.y.timestamp_ms);
64 dataSaver_->saveDataPoint(
67 );
68 }
69 break;
70
72 verticalVelocityEstimator_->update(accel, alt);
73 apogeeDetector_->update(verticalVelocityEstimator_);
74 if (apogeeDetector_->isApogeeDetected()) {
76
77 // Log the state change.
78 Serial.println("To descent");
79 Serial.print("Descent timestamp: ");
80 Serial.println(accel.x.timestamp_ms);
81 dataSaver_->saveDataPoint(
84 );
85 }
86 break;
87
88 default:
89 // All other states have no actions or transitions
90 break;
91 }
92
93 return 0;
94}
#define STATE_CHANGE
Definition DataNames.h:26
@ STATE_ARMED
Definition States.h:19
@ STATE_COAST_ASCENT
Definition States.h:23
@ STATE_DESCENT
Definition States.h:24
@ STATE_POWERED_ASCENT
Definition States.h:22
Detects the apogee (peak altitude) of a rocket flight using estimated altitude and vertical velocity.
bool changeState(FlightState newState)
Transition to a new state and trigger registered on-entry callbacks.
FlightState getFlightState() const
Current state as FlightState enum.
BaseStateMachine(FlightState initialState=STATE_UNARMED)
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.
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.