Skip to content

Commit

Permalink
slight progress...
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Oct 10, 2024
1 parent 76ddfad commit dbcc8f0
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions actuator/rust/robstride/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,50 @@ impl Motors {
self.read_all_pending_responses()
}

fn read_name(&mut self, motor_id: u8) -> Result<String, std::io::Error> {
let mut pack = CanPack {
ex_id: ExId {
id: motor_id,
data: CAN_ID_BROADCAST as u16,
mode: CanComMode::ParaRead,
res: 0,
},
len: 8,
data: vec![0; 8],
};

let index: u16 = 0x1001;
pack.data[..2].copy_from_slice(&index.to_le_bytes());
tx_pack(&mut self.port, &pack)?;

match rx_unpack(&mut self.port) {
Ok(pack) => {
let name = pack
.data
.iter()
.map(|&byte| byte as char)
.collect::<String>();
Ok(name)
}
Err(_) => Err(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to read motor name",
)),
}
}

pub fn read_names(&mut self) -> Result<HashMap<u8, String>, std::io::Error> {
let motor_ids = self.motor_configs.keys().cloned().collect::<Vec<u8>>();
let mut names = HashMap::new();

for id in motor_ids {
let name = self.read_name(id)?;
names.insert(id, name);
}

Ok(names)
}

pub fn send_can_timeout(&mut self, timeout: u32) -> Result<(), std::io::Error> {
// Note: This doesn't work, need to debug with Robstride.

Expand Down Expand Up @@ -778,6 +822,9 @@ impl MotorsSupervisor {
motors.send_can_timeout((sleep_duration.lock().unwrap().as_micros() * 2) as u32);
let _ = motors.send_start();

let names = motors.read_names();
println!("Names: {:?}", names);

while *running.lock().unwrap() {
if *paused.lock().unwrap() {
std::thread::sleep(Duration::from_millis(100));
Expand Down

0 comments on commit dbcc8f0

Please sign in to comment.