Closed nyxrobotics closed 1 year ago
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
If the motor continues to rotate until TACHOMETER overflows, the return value of getPosition jumps
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;
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.