Skip to content

Commit

Permalink
this is messy but u can use if u want
Browse files Browse the repository at this point in the history
  • Loading branch information
ryescholin committed Jun 1, 2024
1 parent 9cc31bd commit 3b82054
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pod-operation/src/components/wheel_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub struct WheelEncoder {
last_state: EncoderState,
last_time: Instant,
velocity: f32,
faulted: bool,
}

impl WheelEncoder {
Expand Down Expand Up @@ -102,6 +103,7 @@ impl WheelEncoder {
pin_a,
pin_b,
velocity: 0.0,
faulted: false,
}
}

Expand Down Expand Up @@ -141,6 +143,14 @@ impl WheelEncoder {
f32::from(self.counter) * DISTANCE_PER_COUNT
}

pub fn faulted(&self) -> bool {
self.faulted
}

pub fn is_faulted(&self) -> bool {
self.faulted
}

fn read_state(&self) -> EncoderState {
encode_state(self.pin_a.read(), self.pin_b.read())
}
Expand Down
9 changes: 9 additions & 0 deletions pod-operation/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ impl StateMachine {
Ok(value) => value,
Err(e) => {
info!("Wheel encoder error: {:?}", e);
encoder.faulted();
continue;
}
}
Expand Down Expand Up @@ -260,6 +261,14 @@ impl StateMachine {
let encoder_value = self.wheel_encoder.lock().unwrap();
let distance = encoder_value.get_distance();
let velocity = encoder_value.get_velocity();
if encoder_value.is_faulted() {
self.io
.of("/control-station")
.unwrap()
.emit("fault", ("Wheel encoder faulted."))
.ok();
return State::Faulted;
}
drop(encoder_value);

let full_json = json!({
Expand Down

0 comments on commit 3b82054

Please sign in to comment.