From f9c467d3e348361989b59e89cdfe11a7964ff840 Mon Sep 17 00:00:00 2001 From: ryescholin Date: Fri, 31 May 2024 20:09:08 -0700 Subject: [PATCH 1/4] add fault reasons --- .../src/services/PodSocketClient.ts | 7 +++++++ pod-operation/src/state_machine.rs | 20 ++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/control-station/src/services/PodSocketClient.ts b/control-station/src/services/PodSocketClient.ts index 23d7deea..e2fbd754 100644 --- a/control-station/src/services/PodSocketClient.ts +++ b/control-station/src/services/PodSocketClient.ts @@ -16,6 +16,7 @@ interface ServerToClientEvents { connect: () => void; disconnect: (reason: Socket.DisconnectReason) => void; serverResponse: (data: string) => void; + faulted: (data: string) => void; } interface Message { @@ -55,6 +56,7 @@ class PodSocketClient { connect: this.onConnect.bind(this), disconnect: this.onDisconnect.bind(this), serverResponse: this.onData.bind(this), + faulted: this.onFault.bind(this), } as const; this.setPodData = setPodData; } @@ -121,6 +123,11 @@ class PodSocketClient { console.log("server says", data); } + private onFault(data: string): void { + console.error("Server faulted with message:", data); + this.addMessage(data, State.Faulted); + } + private addMessage(response: string, newState: State): void { const timestamp = new Date(); const newMessage = { diff --git a/pod-operation/src/state_machine.rs b/pod-operation/src/state_machine.rs index 7093f070..60931c1c 100644 --- a/pod-operation/src/state_machine.rs +++ b/pod-operation/src/state_machine.rs @@ -195,11 +195,6 @@ impl StateMachine { 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(); @@ -221,6 +216,11 @@ impl StateMachine { } if self.downstream_pressure_transducer.read_pressure() < MIN_PRESSURE { + self.io + .of("/control-station") + .unwrap() + .emit("fault", "Low pressure detected.") + .ok(); return State::Faulted; } let default_readings = self.lim_temperature_port.read_lim_temps(); @@ -230,10 +230,20 @@ impl StateMachine { .chain(alternative_readings.iter()) .any(|&reading| reading > LIM_TEMP_THRESHOLD) { + self.io + .of("/control-station") + .unwrap() + .emit("fault", "High temperature detected.") + .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.") + .ok(); return State::Faulted; } From 0b684ed018bd09b372cd71e0da5640dc624a0977 Mon Sep 17 00:00:00 2001 From: ryescholin Date: Sat, 1 Jun 2024 03:32:33 -0700 Subject: [PATCH 2/4] chk --- control-station/src/services/PodSocketClient.ts | 10 +++++----- pod-operation/src/state_machine.rs | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/control-station/src/services/PodSocketClient.ts b/control-station/src/services/PodSocketClient.ts index e2fbd754..ef579c66 100644 --- a/control-station/src/services/PodSocketClient.ts +++ b/control-station/src/services/PodSocketClient.ts @@ -9,14 +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: string) => void; - faulted: (data: string) => void; + fault: (data: string) => void; } interface Message { @@ -56,7 +56,7 @@ class PodSocketClient { connect: this.onConnect.bind(this), disconnect: this.onDisconnect.bind(this), serverResponse: this.onData.bind(this), - faulted: this.onFault.bind(this), + fault: this.onFault.bind(this), } as const; this.setPodData = setPodData; } @@ -124,8 +124,8 @@ class PodSocketClient { } private onFault(data: string): void { - console.error("Server faulted with message:", data); - this.addMessage(data, State.Faulted); + console.error("Server fault with message:", data); + this.addMessage(data, State.fault); } private addMessage(response: string, newState: State): void { diff --git a/pod-operation/src/state_machine.rs b/pod-operation/src/state_machine.rs index 60931c1c..d2161478 100644 --- a/pod-operation/src/state_machine.rs +++ b/pod-operation/src/state_machine.rs @@ -219,7 +219,7 @@ impl StateMachine { self.io .of("/control-station") .unwrap() - .emit("fault", "Low pressure detected.") + .emit("fault", ("Low pressure detected. Currently {}, should be above 126 PSI.", self.downstream_pressure_transducer.read_pressure())) .ok(); return State::Faulted; } @@ -233,7 +233,7 @@ impl StateMachine { self.io .of("/control-station") .unwrap() - .emit("fault", "High temperature detected.") + .emit("fault", ("High temperature detected, currently {}, should be below {} C.", reading, LIM_TEMP_THRESHOLD)) .ok(); return State::Faulted; } @@ -242,7 +242,7 @@ impl StateMachine { self.io .of("/control-station") .unwrap() - .emit("fault", "End of track detected.") + .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; } From 00e0f8f005ad70dddd54c3838023f97e7abff011 Mon Sep 17 00:00:00 2001 From: ryescholin Date: Sat, 1 Jun 2024 03:55:09 -0700 Subject: [PATCH 3/4] chk --- pod-operation/src/state_machine.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pod-operation/src/state_machine.rs b/pod-operation/src/state_machine.rs index da4fa5fd..5ffda6f9 100644 --- a/pod-operation/src/state_machine.rs +++ b/pod-operation/src/state_machine.rs @@ -256,7 +256,7 @@ impl StateMachine { self.io .of("/control-station") .unwrap() - .emit("fault", ("High temperature detected, currently {}, should be below {} C.", reading, LIM_TEMP_THRESHOLD)) + .emit("fault", ("High temperature detected, should be below {} C.", LIM_TEMP_THRESHOLD)) .ok(); return State::Faulted; } From 0f49aa76a0cb7ab55187251434ea4b606167b119 Mon Sep 17 00:00:00 2001 From: ryescholin Date: Sat, 1 Jun 2024 04:02:27 -0700 Subject: [PATCH 4/4] chk --- pod-operation/src/state_machine.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pod-operation/src/state_machine.rs b/pod-operation/src/state_machine.rs index 5ffda6f9..b34b0b03 100644 --- a/pod-operation/src/state_machine.rs +++ b/pod-operation/src/state_machine.rs @@ -242,7 +242,13 @@ impl StateMachine { self.io .of("/control-station") .unwrap() - .emit("fault", ("Low pressure detected. Currently {}, should be above 126 PSI.", self.downstream_pressure_transducer.read_pressure())) + .emit( + "fault", + ( + "Low pressure detected. Currently {}, should be above 126 PSI.", + self.downstream_pressure_transducer.read_pressure(), + ), + ) .ok(); return State::Faulted; } @@ -256,7 +262,13 @@ impl StateMachine { self.io .of("/control-station") .unwrap() - .emit("fault", ("High temperature detected, should be below {} C.", LIM_TEMP_THRESHOLD)) + .emit( + "fault", + ( + "High temperature detected, should be below {} C.", + LIM_TEMP_THRESHOLD, + ), + ) .ok(); return State::Faulted; }