Skip to content

Commit

Permalink
Set WheelEncoder's faulted value when fault occurs
Browse files Browse the repository at this point in the history
  • Loading branch information
taesungh committed Jun 1, 2024
1 parent f16c7af commit 2ec760c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
5 changes: 1 addition & 4 deletions pod-operation/src/components/wheel_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ impl WheelEncoder {
let inc = state - self.last_state;

if inc == EncoderDiff::Undersampling {
self.faulted = true;
return Err("Wheel encoder faulted");
}

Expand Down Expand Up @@ -147,10 +148,6 @@ impl WheelEncoder {
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: 4 additions & 5 deletions pod-operation/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use serde_json::json;
use socketioxide::extract::AckSender;
use socketioxide::{extract::SocketRef, SocketIo};
use tokio::sync::Mutex;

use tracing::info;
use tracing::{error, info};

use crate::components::brakes::Brakes;
use crate::components::gyro::Gyroscope;
Expand Down Expand Up @@ -138,8 +137,7 @@ impl StateMachine {
match encoder.measure() {
Ok(value) => value,
Err(e) => {
info!("Wheel encoder error: {:?}", e);
encoder.faulted();
error!("Wheel encoder error: {:?}", e);
continue;
}
}
Expand Down Expand Up @@ -261,7 +259,8 @@ 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() {
if encoder_value.faulted() {
error!("Wheel encoder faulted");
self.io
.of("/control-station")
.unwrap()
Expand Down

0 comments on commit 2ec760c

Please sign in to comment.