Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to write generic sdo params #49

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading