Skip to content

Commit

Permalink
bug fix for enum
Browse files Browse the repository at this point in the history
  • Loading branch information
kaede committed Nov 24, 2023
1 parent 0f4c1ca commit 14c1e42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/control_table.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub enum DynamixelModel{
XM430_W350,
XC330_T181,
Xm430W350,
Xc330T181,
}

#[allow(dead_code)]
Expand Down Expand Up @@ -351,8 +351,8 @@ impl ControlTable {
ControlTable::PresentPWM => 0.113,
ControlTable::PresentCurrent => {
match model{
DynamixelModel::XM430_W350 => 2.69,
DynamixelModel::XC330_T181 => 1.0,
DynamixelModel::Xm430W350 => 2.69,
DynamixelModel::Xc330T181 => 1.0,
}
},
ControlTable::PresentVelocity => 0.229,
Expand Down Expand Up @@ -426,6 +426,6 @@ mod tests {
fn to_unit_xc330() {
let name = ControlTable::ModelNumber;
assert_eq!(name.to_unit(), 1.0);
assert_eq!(ControlTable::PresentPWM.to_unit(DynamixelModel::XC330_T181), 0.113);
assert_eq!(ControlTable::PresentPWM.to_unit(DynamixelModel::Xc330T181), 0.113);
}
}
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod packet_handler;
pub mod utils;
pub use control_data::*;
pub use control_table::ControlTable;
pub use control_table::DynamixelModel;
pub use packet_handler::CommunicationResult;
use packet_handler::MAX_PACKET_LEN;
pub use utils::DegRad;
Expand Down Expand Up @@ -75,7 +76,7 @@ impl<'a> DynamixelControl<'a> {
pub fn get_present_position(&mut self, id: u8) -> Result<f32, CommunicationResult> {
let result = self.read_4byte(id, ControlTable::PresentPosition);
match result {
Ok(v) => Ok((v as f32 * ControlTable::PresentPosition.to_unit()
Ok(v) => Ok((v as f32 * ControlTable::PresentPosition.to_unit(&DynamixelModel::Xc330T181)
- dxl_consts::f32::HOME_POSITION)
.pulse2deg()
.deg2rad()),
Expand All @@ -86,7 +87,7 @@ impl<'a> DynamixelControl<'a> {
/// current: A
pub fn set_goal_current(&mut self, id: u8, current: f32) -> Result<(), CommunicationResult> {
let data: u16 = u16::from_le_bytes(
((current / ControlTable::GoalCurrent.to_unit() * 1000.0) as i16).to_le_bytes(),
((current / ControlTable::GoalCurrent.to_unit(&DynamixelModel::Xc330T181) * 1000.0) as i16).to_le_bytes(),
);
let result = self.write_2byte(id, ControlTable::GoalCurrent, data);
// let result = self.send_2byte_write_packet(id, ControlTable::GoalCurrent, data);
Expand All @@ -103,6 +104,7 @@ mod tests {
use crate::packet_handler::CommunicationResult;
use crate::packet_handler::Packet;
use crate::ControlTable;
use crate::DynamixelModel;
use crate::DynamixelControl;
use crate::Instruction;
use core::cell::RefCell;
Expand Down

0 comments on commit 14c1e42

Please sign in to comment.