From f3bc84885fd1de435c794f641a8fc9e9304d15e3 Mon Sep 17 00:00:00 2001 From: Benjamin Bolte Date: Fri, 1 Nov 2024 11:15:10 -0700 Subject: [PATCH] add serde dependency --- actuator/robstride/Cargo.toml | 2 ++ actuator/robstride/src/lib.rs | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/actuator/robstride/Cargo.toml b/actuator/robstride/Cargo.toml index de93d0e..e729836 100644 --- a/actuator/robstride/Cargo.toml +++ b/actuator/robstride/Cargo.toml @@ -24,6 +24,8 @@ nix = "^0.26.2" log = "^0.4.22" serialport = { version = "^4.2.0", optional = true } clap = { version = "4.3", features = ["derive"] } +serde = "^1.0" +serde_yaml = "^0.9" [target.'cfg(any(target_os = "macos", target_os = "linux"))'.dependencies] serialport = "^4.2.0" diff --git a/actuator/robstride/src/lib.rs b/actuator/robstride/src/lib.rs index a944b84..d82512e 100644 --- a/actuator/robstride/src/lib.rs +++ b/actuator/robstride/src/lib.rs @@ -1,5 +1,6 @@ use log::{error, info}; use nix; +use serde::{Deserialize, Serialize}; use serialport::TTYPort; use std::collections::{HashMap, HashSet}; use std::io::{Read, Write}; @@ -26,7 +27,7 @@ pub const BAUD_RATE: nix::sys::termios::BaudRate = nix::sys::termios::BaudRate:: #[cfg(target_os = "macos")] pub const BAUD_RATE: nix::sys::termios::BaudRate = nix::sys::termios::BaudRate::B115200; -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub struct MotorConfig { pub p_min: f32, pub p_max: f32, @@ -141,7 +142,7 @@ lazy_static! { } #[repr(u8)] -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum CanComMode { AnnounceDevId = 0, MotorCtrl, @@ -169,7 +170,7 @@ pub enum CanComMode { } #[repr(u8)] -#[derive(Copy, Clone, Debug, Default)] +#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] pub enum MotorMode { #[default] Reset = 0, @@ -178,7 +179,7 @@ pub enum MotorMode { Brake, } -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)] pub enum RunMode { UnsetMode = -1, MitMode = 0, @@ -189,7 +190,7 @@ pub enum RunMode { CspPositionMode = 5, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct ExId { pub id: u8, pub data: u16, @@ -197,14 +198,14 @@ pub struct ExId { pub res: u8, } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct CanPack { pub ex_id: ExId, pub len: u8, pub data: Vec, } -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct MotorFeedback { pub can_id: u8, pub position: f32, @@ -214,7 +215,7 @@ pub struct MotorFeedback { pub faults: u16, } -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default, Clone, Serialize, Deserialize)] pub struct MotorFeedbackRaw { pub can_id: u8, pub pos_int: u16, @@ -402,7 +403,7 @@ fn unpack_raw_feedback(pack: &CanPack) -> MotorFeedbackRaw { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum MotorType { Type00, Type01, @@ -438,7 +439,7 @@ pub fn motor_type_from_str(s: &str) -> Result { } } -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub struct MotorControlParams { pub position: f32, pub velocity: f32,