Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 5 additions & 39 deletions MIDAS/src/finite-state-machines/fsm.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
#include <cmath>

#include "fsm.h"
#include "thresholds.h"

/**
* @brief Helper to calculate the average value of a buffered sensor data
*
* @param sensor Buffered sensor struct
* @param get_item Lambda get function
*
* @return Average value
*/

// helper functions

template<typename T, size_t count>
double sensor_average(BufferedSensorData<T, count>& sensor, double (* get_item)(T&)) {
auto arr = sensor.template getBufferRecent<count>();
Expand All @@ -21,14 +14,6 @@ double sensor_average(BufferedSensorData<T, count>& sensor, double (* get_item)(
return sum / count;
}

/**
* @brief Helper to calculate the derivative over a buffered sensor data
*
* @param sensor Buffered sensor struct
* @param get_item Lambda get function
*
* @return Derivative
*/
template<typename T, size_t count>
double sensor_derivative(BufferedSensorData<T, count>& sensor, double (* get_item)(T&)) {
auto arr = sensor.template getBufferRecent<count>();
Expand All @@ -55,9 +40,7 @@ double sensor_derivative(BufferedSensorData<T, count>& sensor, double (* get_ite
return (second_average - first_average) / (second_average_time - first_average_time);
}

/**
* @brief Populates StateEstimate struct with the correct values for accel, alt, jerk, and speed
*/

StateEstimate::StateEstimate(RocketData& state) {
acceleration = sensor_average<HighGData, 8>(state.high_g, [](HighGData& data) {
return (double) data.ax;
Expand All @@ -76,14 +59,6 @@ StateEstimate::StateEstimate(RocketData& state) {

#ifdef IS_SUSTAINER

/**
* @brief Sustainer FSM tick function, which will advance the current state if necessary
*
* @param state current FSM state
* @param state_estimate StateEstimate struct for the current estimate for accel, alt, jerk, and speed
*
* @return New FSM State
*/
FSMState FSM::tick_fsm(FSMState& state, StateEstimate state_estimate) {
//get current time
double current_time = pdTICKS_TO_MS(xTaskGetTickCount());
Expand Down Expand Up @@ -240,16 +215,7 @@ FSMState FSM::tick_fsm(FSMState& state, StateEstimate state_estimate) {

#else

/**
* @brief Booster FSM tick function, which will advance the current state if necessary
*
* This is similar to the previous function but contains less states
*
* @param state current FSM state
* @param state_estimate StateEstimate struct for the current estimate for accel, alt, jerk, and speed
*
* @return New FSM State
*/
// this is similar to the previous function but contains less states
FSMState FSM::tick_fsm(FSMState& state, StateEstimate state_estimate) {
double current_time = pdTICKS_TO_MS(xTaskGetTickCount());

Expand Down
5 changes: 4 additions & 1 deletion MIDAS/src/finite-state-machines/fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#include "FreeRTOSConfig.h"
#include "fsm_states.h"
#include "thresholds.h"


#include "sg1-4.h"
Comment thread
Aadityavoru marked this conversation as resolved.
Outdated

#include "sensor_data.h"
#include "Buffer.h"
#include "rocket_state.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#define sustainer_main_to_main_deploy_timer_threshold 3000

// Height required to deploy the main parachutes
#define sustainer_main_deploy_altitude_threshold 3000
#define sustainer_main_deploy_altitude_threshold 1006

// Return to SUSTAINER_IGNITION if not in SECOND_BOOST for this amount of time (ms)
#define sustainer_ignition_to_second_boost_time_threshold 1000
Expand All @@ -53,7 +53,7 @@
#define sustainer_first_boost_to_burnout_time_threshold 1000

// Transition to LANDED from MAIN if vertical speed is less than this threshold
#define sustainer_landed_vertical_speed_threshold 20
#define sustainer_landed_vertical_speed_threshold 3

// Stores a small jerk value
#define sustainer_drogue_jerk_threshold 200
Expand Down Expand Up @@ -108,7 +108,7 @@
#define booster_first_boost_to_burnout_time_threshold 1000

// Transition to LANDED from MAIN if vertical speed is less than this threshold
#define booster_landed_vertical_speed_threshold 20
#define booster_landed_vertical_speed_threshold 4

// Stores a small jerk value
#define booster_first_separation_jerk_threshold 300
Expand Down