Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add events for state machine #112

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
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 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 @@
}
}

pub fn handle_event(&mut self, _event: RocketEvents, context: &mut StateMachineContext) {
if let Some(new_state) = self.state.event(event) {

Check failure on line 66 in boards/recovery/src/state_machine/mod.rs

View workflow job for this annotation

GitHub Actions / All

cannot find value `event` in this scope
self.state.exit();
new_state.enter(context);
self.state = new_state;
} else {
match event {

Check failure on line 71 in boards/recovery/src/state_machine/mod.rs

View workflow job for this annotation

GitHub Actions / All

cannot find value `event` in this scope
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 @@

// 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 @@
}
})
}

fn event(&mut self, event: RocketEvents, context: &mut StateMachineContext) -> Option<RocketStates> {

Check failure on line 32 in boards/recovery/src/state_machine/states/descent.rs

View workflow job for this annotation

GitHub Actions / All

method `event` has 3 parameters but the declaration in trait `black_magic::State::event` has 2
match event {
RocketEvents::DeployDrogue(false) => context.shared_resources.em.run(|| {

Check failure on line 34 in boards/recovery/src/state_machine/states/descent.rs

View workflow job for this annotation

GitHub Actions / All

mismatched types
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 @@
}
})
}
fn event(&mut self, event: RocketEvents, context: &mut StateMachineContext) -> Option<RocketStates> {

Check failure on line 40 in boards/recovery/src/state_machine/states/terminal_descent.rs

View workflow job for this annotation

GitHub Actions / All

method `event` has 3 parameters but the declaration in trait `black_magic::State::event` has 2
match event {
RocketEvents::DeployMain(false) => context.shared_resources.em.run(|| {

Check failure on line 42 in boards/recovery/src/state_machine/states/terminal_descent.rs

View workflow job for this annotation

GitHub Actions / All

mismatched types
spawn!(fire_main)?;
Ok(())
}),
_ => None,
}
}
}

impl TransitionInto<TerminalDescent> for Descent {
Expand Down
Loading