EtherCatInterfaceElmo
as an example.EtherCATInterfaceBase
.int64_t getPosition()
is recommended to avoid overflow problems (see below)The position is often sent as a 32 bit signed integer (~4*e+9 different values). With a high-resolution encoder, this value can easily overflow.
To avoid this problem use a method implementation like this:
int64_t EtherCATInterfaceElmo::getPosition(int driveNumber) { int32_t rawPos = ll_getPositionActualValue(driveNumber); int32_t diff = rawPos - drives[driveNumber].prevRawPos; drives[driveNumber].prevRawPos = rawPos; drives[driveNumber].absPos += static_cast<int64_t>(diff); return drives[driveNumber].absPos + static_cast<int64_t>(drives[driveNumber].posOffset); }