Skip to content

Commit

Permalink
Add inverter board abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
samderanova committed May 27, 2024
1 parent 242c454 commit 15cf281
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pod-operation/src/components/inverter_board.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use rppal::uart::{Parity, Uart};
pub struct InverterBoard {
uart: Uart,
}

impl InverterBoard {
pub fn new() -> Self {
let uart = Uart::with_path("/dev/ttyACM0", 9600, Parity::None, 8, 1).unwrap();
Self { uart }
}

pub fn send_control(&mut self, velocity: f32, throttle: f32) {
let vel_str = velocity.to_string();
let throttle_str = throttle.to_string();
let data = vel_str + " " + &throttle_str + "\n";
self.uart.write(data.as_bytes()).unwrap();
}
}
1 change: 1 addition & 0 deletions pod-operation/src/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub mod brakes;
pub mod gyro;
pub mod high_voltage_system;
pub mod inverter_board;
pub mod lim_current;
pub mod lim_temperature;
pub mod pressure_transducer;
Expand Down
8 changes: 8 additions & 0 deletions pod-operation/src/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use tracing::info;
use crate::components::brakes::Brakes;
use crate::components::gyro::Gyroscope;
use crate::components::high_voltage_system::HighVoltageSystem;
use crate::components::inverter_board::InverterBoard;
use crate::components::lim_current::LimCurrent;
use crate::components::lim_temperature::LimTemperature;
use crate::components::pressure_transducer::PressureTransducer;
Expand Down Expand Up @@ -121,3 +122,10 @@ pub async fn high_voltage_system(mut high_voltage_system: HighVoltageSystem) {
i += 1;
}
}

pub async fn inverter_control(mut inverter_control: InverterBoard) {
loop {
inverter_control.send_control(0.0, 1.0);
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
}
}
4 changes: 4 additions & 0 deletions pod-operation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod state_machine;
use crate::components::brakes::Brakes;
use crate::components::gyro::Gyroscope;
use crate::components::high_voltage_system::HighVoltageSystem;
use crate::components::inverter_board::InverterBoard;
use crate::components::lim_current::LimCurrent;
use crate::components::lim_temperature::LimTemperature;
use crate::components::pressure_transducer::PressureTransducer;
Expand Down Expand Up @@ -56,6 +57,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
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 app = axum::Router::new().layer(layer);

info!("Starting server on port 5000");
Expand Down

0 comments on commit 15cf281

Please sign in to comment.