-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create inverter board abstraction to send velocity and throttle to Ra…
…spberry Pi Pico (#83) * Add inverter board abstraction * InverterBoard refactoring - Extract arguments to Uart::with_path to constants - Simplify send_control to use format! rather than string concatenation
- Loading branch information
1 parent
b5bed4a
commit eadf30a
Showing
4 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use rppal::uart::{Parity, Uart}; | ||
|
||
const SERIAL_PATH: &str = "/dev/tty/ACM0"; | ||
const BAUD_RATE: u32 = 9600; | ||
const PARITY: Parity = Parity::None; | ||
const DATA_BITS: u8 = 8; | ||
const STOP_BITS: u8 = 1; | ||
|
||
pub struct InverterBoard { | ||
uart: Uart, | ||
} | ||
|
||
impl InverterBoard { | ||
pub fn new() -> Self { | ||
let uart = Uart::with_path(SERIAL_PATH, BAUD_RATE, PARITY, DATA_BITS, STOP_BITS).unwrap(); | ||
Self { uart } | ||
} | ||
|
||
/// Combine velocity and throttle into a space-separated string message and then send it over to | ||
/// the Pico as bytes. | ||
pub fn send_control(&mut self, velocity: f32, throttle: f32) { | ||
let message = format!("{velocity} {throttle}\n"); | ||
self.uart.write(message.as_bytes()).unwrap(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters