sbgisen / vesc

VESC Interface for ROS
Apache License 2.0
47 stars 34 forks source link

Handling of TACHOMETER value overflow #45

Closed nyxrobotics closed 1 year ago

nyxrobotics commented 2 years ago

Abstract

The TACHOMETER value is converted to double, which results in an incorrect value during overflow.

https://github.com/sbgisen/vesc/blob/3d25c6a61d7cd14c673efe7412cbccd8afb7cad5/vesc_driver/src/vesc_packet.cpp#L276-L283

How to Reproduce the Bug

If the motor continues to rotate until TACHOMETER overflows, the return value of getPosition jumps

Suggestion

Calculate the difference from the previous value and cast the value to double. The difference shall not exceed the maximum value of int.

int tachometer = (int)readBuffer(TACHOMETER, 4);
static int tachometer_last = tachometer ;
current_pose += (double)(tachometer - tachometer_last);
tachometer_last = tachometer;