switched to a state instead of change architecture
southbridge currently hangs, embassy does not make such things easy to diagnose
This commit is contained in:
parent
b131ad8957
commit
cc18f76e55
1 changed files with 134 additions and 154 deletions
|
|
@ -1,7 +1,7 @@
|
|||
//! Data types shared between the northbridge and southbridge for serial communications
|
||||
#![no_std]
|
||||
|
||||
use nalgebra::Vector3;
|
||||
use nalgebra::{SimdPartialOrd, Vector3};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const BAUDRATE: u32 = 115200;
|
||||
|
|
@ -20,9 +20,34 @@ pub enum Command {
|
|||
Disable,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct RobotState {
|
||||
/// forward. clockwise
|
||||
pub drive: (f32,f32),
|
||||
/// RGB led brightness
|
||||
pub underglow: Vector3<u8>,
|
||||
}
|
||||
|
||||
impl RobotState {
|
||||
/// limit exertion to factor of full output (0 to 1)
|
||||
pub fn brownout(self, factor: f32) -> Self {
|
||||
Self {
|
||||
drive: (
|
||||
self.drive.0.clamp(-factor, factor),
|
||||
self.drive.1.clamp(-factor, factor),
|
||||
),
|
||||
underglow: self.underglow.simd_min(Vector3::repeat((factor * u8::MAX as f32) as u8))
|
||||
}
|
||||
}
|
||||
|
||||
/// Safe command to send in uncertian states
|
||||
pub fn stopped() -> Self {
|
||||
Self { drive: (0.0, 0.0), underglow: Vector3::new(100, 0, 0) }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Response {
|
||||
pub enabled: bool,
|
||||
pub sensor_data: Option<SensorData>,
|
||||
pub uptime_micros: u64,
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue