Skip to content

Commit

Permalink
Add new Faulted state for pod failures (#78)
Browse files Browse the repository at this point in the history
Add faulted to podop
  • Loading branch information
ryescholin authored May 28, 2024
1 parent e3a54fe commit af5c7cb
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions pod-operation/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum State {
Running,
Stopped,
Halted,
Faulted,
}

type StateTransition = fn(&mut StateMachine) -> State;
Expand Down Expand Up @@ -57,6 +58,7 @@ impl StateMachine {
State::Running => StateMachine::_enter_running,
State::Stopped => StateMachine::_enter_stopped,
State::Halted => StateMachine::_enter_halted,
State::Faulted => StateMachine::_enter_faulted,
};

let state_transitions = enum_map! {
Expand All @@ -65,6 +67,7 @@ impl StateMachine {
State::Running => Some(StateMachine::_running_periodic as fn(&mut Self) -> State),
State::Stopped => None,
State::Halted => None,
State::Faulted => None,
};

io.ns("/control-station", |socket: SocketRef| {
Expand Down Expand Up @@ -187,6 +190,18 @@ impl StateMachine {
self.high_voltage_system.disable();
}

fn _enter_faulted(&mut self) {
info!("Entering Faulted state");
self.io
.of("/control-station")
.unwrap()
.emit("fault", "123")
.ok();
self.signal_light.disable();
self.brakes.engage();
self.high_voltage_system.disable();
}

/// Perform operations when the pod is loading
fn _load_periodic(&mut self) -> State {
info!("Rolling Load state");
Expand All @@ -202,7 +217,7 @@ impl StateMachine {
return State::Stopped;
}
if self.downstream_pressure_transducer.read_pressure() < MIN_PRESSURE {
return State::Halted;
return State::Faulted;
}
let default_readings: [f32; 4] = self.lim_temperature_port.read_lim_temps().into();
let alternative_readings: [f32; 4] = self.lim_temperature_starboard.read_lim_temps().into();
Expand All @@ -211,7 +226,7 @@ impl StateMachine {
.iter()
.any(|&reading| reading > LIM_TEMP_THRESHOLD)
{
return State::Halted;
return State::Faulted;
}

State::Running
Expand Down

0 comments on commit af5c7cb

Please sign in to comment.