Skip to content

Commit

Permalink
add serde dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Nov 1, 2024
1 parent 196ebee commit f3bc848
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 2 additions & 0 deletions actuator/robstride/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 11 additions & 10 deletions actuator/robstride/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -189,22 +190,22 @@ pub enum RunMode {
CspPositionMode = 5,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExId {
pub id: u8,
pub data: u16,
pub mode: CanComMode,
pub res: u8,
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CanPack {
pub ex_id: ExId,
pub len: u8,
pub data: Vec<u8>,
}

#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub struct MotorFeedback {
pub can_id: u8,
pub position: f32,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -438,7 +439,7 @@ pub fn motor_type_from_str(s: &str) -> Result<MotorType, std::io::Error> {
}
}

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct MotorControlParams {
pub position: f32,
pub velocity: f32,
Expand Down

0 comments on commit f3bc848

Please sign in to comment.