Skip to content

Commit

Permalink
Add ability to write generic sdo params (#49)
Browse files Browse the repository at this point in the history
* generic sdo logic

* bump version
  • Loading branch information
WT-MM authored Nov 12, 2024
1 parent 41c899a commit b26b958
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resolver = "2"

[workspace.package]

version = "0.2.5"
version = "0.2.6"
authors = ["Wesley Maa <[email protected]>", "Pawel Budzianowski <[email protected]>", "Benjamin Bolte <[email protected]>"]
edition = "2021"
description = "Actuator package"
Expand Down
18 changes: 9 additions & 9 deletions actuator/robstride/src/motor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,7 @@ impl Motors {
Ok(())
}

pub fn set_torque_limit(&mut self, motor_id: u8, torque_limit: f32) -> Result<(), std::io::Error> {
let config = *self.motor_configs.get(&motor_id).ok_or(std::io::Error::new(
std::io::ErrorKind::NotFound,
"Motor not found",
))?;

pub fn write_sdo_param(&mut self, motor_id: u8, index: u16, value: f32) -> Result<(), std::io::Error> {
let mut pack = CanPack {
ex_id: ExId {
id: motor_id,
Expand All @@ -373,13 +368,18 @@ impl Motors {
data: vec![0; 8],
};

let index: u16 = 0x700B;
pack.data[..2].copy_from_slice(&index.to_le_bytes());

let torque_limit_safe = torque_limit.clamp(config.t_min, config.t_max);
pack.data[4..8].copy_from_slice(&torque_limit_safe.to_le_bytes());
pack.data[4..8].copy_from_slice(&value.to_le_bytes());

self.send_command(&pack, true)?;
Ok(())
}

pub fn set_torque_limit(&mut self, motor_id: u8, torque_limit: f32) -> Result<(), std::io::Error> {
let index: u16 = 0x700B;
// optionally clamp to min/max
self.write_sdo_param(motor_id, index, torque_limit)?;
Ok(())
}

Expand Down

0 comments on commit b26b958

Please sign in to comment.