Skip to content
This repository was archived by the owner on Oct 28, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions boards/recovery/src/data_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ impl DataManager {
messages::Data::Sensor(sensor) => match sensor.data {
messages::sensor::SensorData::Air(air_data) => {
/*

NOTE!!!
There should be added a counter to check how many times
the alt is dropped, if the number is high switch to
Expand Down
26 changes: 24 additions & 2 deletions boards/recovery/src/state_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use defmt::Format;
use enum_dispatch::enum_dispatch;
use messages::state;
use rtic::Mutex;
pub use states::Abort;
pub use states::Initializing;

pub trait StateMachineSharedResources {
Expand Down Expand Up @@ -61,6 +62,26 @@ impl StateMachine {
}
}

pub fn handle_event(&mut self, _event: RocketEvents, context: &mut StateMachineContext) {
if let Some(new_state) = self.state.event(event) {
self.state.exit();
new_state.enter(context);
self.state = new_state;
} else {
match event {
RocketEvents::DeployDrogue(true) => todo!(),
RocketEvents::DeployMain(true) => todo!(),
RocketEvents::Abort => {
self.state.exit();
let new_state = RocketStates::Abort(Abort {});
// new_state.enter(context);
self.state = new_state;
}
_ => {}
}
}
}

pub fn get_state(&self) -> RocketStates {
self.state.clone()
}
Expand All @@ -74,8 +95,9 @@ impl Default for StateMachine {

// All events are found here
pub enum RocketEvents {
DeployDrogue,
DeployMain,
DeployDrogue(bool),
DeployMain(bool),
Abort,
}

// All states are defined here. Another struct must be defined for the actual state, and that struct
Expand Down
13 changes: 12 additions & 1 deletion boards/recovery/src/state_machine/states/descent.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use super::Ascent;
use crate::app::fire_drogue;
use crate::state_machine::{
RocketStates, State, StateMachineContext, TerminalDescent, TransitionInto,
RocketEvents, RocketStates, State, StateMachineContext, TerminalDescent, TransitionInto,
};
use crate::{no_transition, transition};
use common_arm::spawn;
use defmt::{write, Format, Formatter};
use rtic::mutex::Mutex;
use typenum::False;

#[derive(Debug, Clone)]
pub struct Descent {}
Expand All @@ -27,6 +28,16 @@ impl State for Descent {
}
})
}

fn event(&mut self, event: RocketEvents, context: &mut StateMachineContext) -> Option<RocketStates> {
match event {
RocketEvents::DeployDrogue(false) => context.shared_resources.em.run(|| {
spawn!(fire_drogue)?;
Ok(())
}),
_ => None,
}
}
}

impl TransitionInto<Descent> for Ascent {
Expand Down
11 changes: 10 additions & 1 deletion boards/recovery/src/state_machine/states/terminal_descent.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::Descent;
use crate::app::fire_main;
use crate::state_machine::{
RocketStates, State, StateMachineContext, TransitionInto, WaitForRecovery,
RocketEvents, RocketStates, State, StateMachineContext, TransitionInto, WaitForRecovery,
};
use crate::{no_transition, transition};
use atsamd_hal::prelude::_embedded_hal_timer_CountDown;
Expand Down Expand Up @@ -37,6 +37,15 @@ impl State for TerminalDescent {
}
})
}
fn event(&mut self, event: RocketEvents, context: &mut StateMachineContext) -> Option<RocketStates> {
match event {
RocketEvents::DeployMain(false) => context.shared_resources.em.run(|| {
spawn!(fire_main)?;
Ok(())
}),
_ => None,
}
}
}

impl TransitionInto<TerminalDescent> for Descent {
Expand Down