Fixed encoder overflow

This commit is contained in:
Konstantin Lampalzer 2021-09-05 11:11:53 +01:00
parent 3e7df14da8
commit 74f0f42d2f

View file

@ -44,7 +44,11 @@ class Encoder(object):
if port <= 0 or port > MOTOR_COUNT:
raise IndexError("Invalid encoder port specified!")
return Encoder.read_raw(port) - encoder_start_values[port]
diff = Encoder.read_raw(port) - encoder_start_values[port]
if diff > 2 ** 31:
diff -= 2 ** 32
return diff
@staticmethod
def clear(port: int):