Skip to content

Commit

Permalink
fix vactual and xtarget readout
Browse files Browse the repository at this point in the history
  • Loading branch information
hacknus committed Apr 23, 2024
1 parent 0c2670e commit 57d3cfd
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,13 +610,14 @@ impl<SPI, CS, EN, E> Tmc5160<SPI, CS, EN>

/// get the current velocity
pub fn get_velocity(&mut self) -> Result<f32, Error<E>> {
self.read_register(Registers::VACTUAL).map(|target| {
if (target.data & 0b100000000000000000000000) == 0b100000000000000000000000 {
((16777216 - target.data as i32) as f64 / self._step_count as f64) as f32
} else {
((target.data as i32) as f64 / self._step_count as f64) as f32
}
})
// self.read_register(Registers::VACTUAL).map(|target| {
// if (target.data & 0b100000000000000000000000) == 0b100000000000000000000000 {
// ((16777216 - target.data as i32) as f64 / self._step_count as f64) as f32
// } else {
// ((target.data as i32) as f64 / self._step_count as f64) as f32
// }
// })
self.read_register(Registers::VACTUAL).map(|val| (val.data as i32) as f32 / self._step_count)
}

/// get the set maximum velocity (VMAX)
Expand All @@ -626,6 +627,6 @@ impl<SPI, CS, EN, E> Tmc5160<SPI, CS, EN>

/// get the current target position (XTARGET)
pub fn get_target(&mut self) -> Result<f32, Error<E>> {
self.read_register(Registers::XTARGET).map(|packet| packet.data as f32 / self._step_count)
self.read_register(Registers::XTARGET).map(|val| (val.data as i32) as f32 / self._step_count)
}
}

0 comments on commit 57d3cfd

Please sign in to comment.