Skip to content

Commit

Permalink
Added message and timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
vrushang1234 committed Jun 1, 2024
1 parent b2c1337 commit 1777ed5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 79 deletions.
48 changes: 24 additions & 24 deletions pod-operation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,39 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {

let (layer, io) = SocketIo::new_layer();

// let signal_light = SignalLight::new();
// tokio::spawn(demo::blink(signal_light));
let signal_light = SignalLight::new();
tokio::spawn(demo::blink(signal_light));

// let upstream_pressure_transducer = PressureTransducer::upstream();
// tokio::spawn(demo::read_pressure_transducer(upstream_pressure_transducer));
let upstream_pressure_transducer = PressureTransducer::upstream();
tokio::spawn(demo::read_pressure_transducer(upstream_pressure_transducer));

// let downstream_pressure_transducer = PressureTransducer::downstream();
// tokio::spawn(demo::read_pressure_transducer(
// downstream_pressure_transducer,
// ));
let downstream_pressure_transducer = PressureTransducer::downstream();
tokio::spawn(demo::read_pressure_transducer(
downstream_pressure_transducer,
));

// let ads1015 = LimTemperature::new(ads1x1x::SlaveAddr::Default);
// tokio::spawn(demo::read_ads1015(ads1015));
let ads1015 = LimTemperature::new(ads1x1x::SlaveAddr::Default);
tokio::spawn(demo::read_ads1015(ads1015));

// let wheel_encoder = WheelEncoder::new();
// tokio::spawn(demo::read_wheel_encoder(wheel_encoder));
let wheel_encoder = WheelEncoder::new();
tokio::spawn(demo::read_wheel_encoder(wheel_encoder));

// let gyro: Gyroscope = Gyroscope::new();
// tokio::spawn(demo::read_gyroscope(gyro));
// let brakes = Brakes::new();
// tokio::spawn(demo::brake(brakes));
let gyro: Gyroscope = Gyroscope::new();
tokio::spawn(demo::read_gyroscope(gyro));
let brakes = Brakes::new();
tokio::spawn(demo::brake(brakes));

// let high_voltage_system = HighVoltageSystem::new();
// tokio::spawn(demo::high_voltage_system(high_voltage_system));
let high_voltage_system = HighVoltageSystem::new();
tokio::spawn(demo::high_voltage_system(high_voltage_system));

// let lidar = Lidar::new();
// tokio::spawn(demo::read_lidar(lidar));
let lidar = Lidar::new();
tokio::spawn(demo::read_lidar(lidar));

// let limcurrent = LimCurrent::new(ads1x1x::SlaveAddr::Default);
// tokio::spawn(demo::read_lim_current(limcurrent));
let limcurrent = LimCurrent::new(ads1x1x::SlaveAddr::Default);
tokio::spawn(demo::read_lim_current(limcurrent));

// let inverter_board = InverterBoard::new();
// tokio::spawn(demo::inverter_control(inverter_board));
let inverter_board = InverterBoard::new();
tokio::spawn(demo::inverter_control(inverter_board));

let mut state_machine = StateMachine::new(io);
tokio::spawn(async move {
Expand Down
110 changes: 55 additions & 55 deletions pod-operation/src/state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ pub struct StateMachine {
enter_actions: EnumMap<State, fn(&mut Self)>,
state_transitions: EnumMap<State, Option<StateTransition>>,
io: SocketIo,
// brakes: Brakes,
// signal_light: SignalLight,
// wheel_encoder: WheelEncoder,
// //upstream_pressure_transducer: PressureTransducer,
// downstream_pressure_transducer: PressureTransducer,
// lim_temperature_port: LimTemperature,
// lim_temperature_starboard: LimTemperature,
// high_voltage_system: HighVoltageSystem,
// lidar: Lidar,
brakes: Brakes,
signal_light: SignalLight,
wheel_encoder: WheelEncoder,
//upstream_pressure_transducer: PressureTransducer,
downstream_pressure_transducer: PressureTransducer,
lim_temperature_port: LimTemperature,
lim_temperature_starboard: LimTemperature,
high_voltage_system: HighVoltageSystem,
lidar: Lidar,
}

impl StateMachine {
Expand Down Expand Up @@ -94,17 +94,17 @@ impl StateMachine {
enter_actions,
state_transitions,
io,
// brakes: Brakes::new(),
// signal_light: SignalLight::new(),
// wheel_encoder: WheelEncoder::new(),
// //upstream_pressure_transducer: PressureTransducer::upstream(),
// downstream_pressure_transducer: PressureTransducer::downstream(),
// lim_temperature_port: LimTemperature::new(ads1x1x::SlaveAddr::Default),
// lim_temperature_starboard: LimTemperature::new(ads1x1x::SlaveAddr::Alternative(
// false, true,
// )),
// high_voltage_system: HighVoltageSystem::new(),
// lidar: Lidar::new(),
brakes: Brakes::new(),
signal_light: SignalLight::new(),
wheel_encoder: WheelEncoder::new(),
//upstream_pressure_transducer: PressureTransducer::upstream(),
downstream_pressure_transducer: PressureTransducer::downstream(),
lim_temperature_port: LimTemperature::new(ads1x1x::SlaveAddr::Default),
lim_temperature_starboard: LimTemperature::new(ads1x1x::SlaveAddr::Alternative(
false, true,
)),
high_voltage_system: HighVoltageSystem::new(),
lidar: Lidar::new(),
}
}

Expand Down Expand Up @@ -164,33 +164,33 @@ impl StateMachine {

fn _enter_init(&mut self) {
info!("Entering Init state");
// self.signal_light.disable();
self.signal_light.disable();
}

fn _enter_load(&mut self) {
info!("Entering Load state");
// self.brakes.disengage();
// self.signal_light.disable();
self.brakes.disengage();
self.signal_light.disable();
}

fn _enter_running(&mut self) {
info!("Entering Running state");
// self.high_voltage_system.enable(); // Enable high voltage system -- may move later
// self.signal_light.enable();
// self.brakes.disengage();
self.high_voltage_system.enable(); // Enable high voltage system -- may move later
self.signal_light.enable();
self.brakes.disengage();
}

fn _enter_stopped(&mut self) {
info!("Entering Stopped state");
// self.signal_light.disable();
// self.brakes.engage();
self.signal_light.disable();
self.brakes.engage();
}

fn _enter_halted(&mut self) {
info!("Entering Halted state");
// self.signal_light.disable();
// self.brakes.engage();
// self.high_voltage_system.disable();
self.signal_light.disable();
self.brakes.engage();
self.high_voltage_system.disable();
}

fn _enter_faulted(&mut self) {
Expand All @@ -200,9 +200,9 @@ impl StateMachine {
.unwrap()
.emit("fault", "123")
.ok();
// self.signal_light.disable();
// self.brakes.engage();
// self.high_voltage_system.disable();
self.signal_light.disable();
self.brakes.engage();
self.high_voltage_system.disable();
}

/// Perform operations when the pod is loading
Expand All @@ -215,27 +215,27 @@ impl StateMachine {
/// Perform operations when the pod is running
fn _running_periodic(&mut self) -> State {
info!("Rolling Running state");
// let encoder_value = self.wheel_encoder.measure().expect("wheel encoder faulted"); // Read the encoder value
// if encoder_value > STOP_THRESHOLD {
// return State::Stopped;
// }

// if self.downstream_pressure_transducer.read_pressure() < MIN_PRESSURE {
// return State::Faulted;
// }
// let default_readings = self.lim_temperature_port.read_lim_temps();
// let alternative_readings = self.lim_temperature_starboard.read_lim_temps();
// if default_readings
// .iter()
// .chain(alternative_readings.iter())
// .any(|&reading| reading > LIM_TEMP_THRESHOLD)
// {
// return State::Faulted;
// }
// // Last 20% of the track, as indicated by braking
// if self.lidar.read_distance() < END_OF_TRACK {
// return State::Faulted;
// }
let encoder_value = self.wheel_encoder.measure().expect("wheel encoder faulted"); // Read the encoder value
if encoder_value > STOP_THRESHOLD {
return State::Stopped;
}

if self.downstream_pressure_transducer.read_pressure() < MIN_PRESSURE {
return State::Faulted;
}
let default_readings = self.lim_temperature_port.read_lim_temps();
let alternative_readings = self.lim_temperature_starboard.read_lim_temps();
if default_readings
.iter()
.chain(alternative_readings.iter())
.any(|&reading| reading > LIM_TEMP_THRESHOLD)
{
return State::Faulted;
}
// Last 20% of the track, as indicated by braking
if self.lidar.read_distance() < END_OF_TRACK {
return State::Faulted;
}

State::Running
}
Expand Down

0 comments on commit 1777ed5

Please sign in to comment.