Skip to content

Commit

Permalink
Indicate reason for pod failures leading to Faulted (#111)
Browse files Browse the repository at this point in the history
* add fault reasons

* chk

* chk

* chk
  • Loading branch information
ryescholin authored Jun 1, 2024
1 parent 7133018 commit 8a90245
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
9 changes: 8 additions & 1 deletion control-station/src/services/PodSocketClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ export enum State {
Running = "Running",
Stopped = "Stopped",
Halted = "Halted",
Faulted = "Faulted",
fault = "Faulted",
}

interface ServerToClientEvents {
connect: () => void;
disconnect: (reason: Socket.DisconnectReason) => void;
serverResponse: (data: Partial<PodData>) => void;
fault: (data: string) => void;
}

interface Message {
Expand Down Expand Up @@ -71,6 +72,7 @@ class PodSocketClient {
connect: this.onConnect.bind(this),
disconnect: this.onDisconnect.bind(this),
serverResponse: this.onData.bind(this),
fault: this.onFault.bind(this),
} as const;
this.setPodData = setPodData;
}
Expand Down Expand Up @@ -138,6 +140,11 @@ class PodSocketClient {
this.setPodData((d) => ({ ...d, ...data }));
}

private onFault(data: string): void {
console.error("Server fault with message:", data);
this.addMessage(data, State.fault);
}

private addMessage(response: string, newState: State): void {
const timestamp = new Date();
const newMessage = {
Expand Down
27 changes: 27 additions & 0 deletions pod-operation/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,17 @@ impl StateMachine {
}

if self.downstream_pressure_transducer.read_pressure() < MIN_PRESSURE {
self.io
.of("/control-station")
.unwrap()
.emit(
"fault",
(
"Low pressure detected. Currently {}, should be above 126 PSI.",
self.downstream_pressure_transducer.read_pressure(),
),
)
.ok();
return State::Faulted;
}
let default_readings = self.lim_temperature_port.read_lim_temps();
Expand All @@ -248,10 +259,26 @@ impl StateMachine {
.chain(alternative_readings.iter())
.any(|&reading| reading > LIM_TEMP_THRESHOLD)
{
self.io
.of("/control-station")
.unwrap()
.emit(
"fault",
(
"High temperature detected, should be below {} C.",
LIM_TEMP_THRESHOLD,
),
)
.ok();
return State::Faulted;
}
// Last 20% of the track, as indicated by braking
if self.lidar.read_distance() < END_OF_TRACK {
self.io
.of("/control-station")
.unwrap()
.emit("fault", ("End of track detected. Current distance to end: {}, less than {} meters away", self.lidar.read_distance(), END_OF_TRACK))
.ok();
return State::Faulted;
}

Expand Down

0 comments on commit 8a90245

Please sign in to comment.