sbgisen / vesc

VESC Interface for ROS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Handling of TACHOMETER value overflow

nyxrobotics opened this issue · comments

Abstract

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

/**
* @brief Gets the current position
* @return The current position
**/
double VescPacketValues::getPosition() const
{
return readBuffer(TACHOMETER, 4);
}

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;