我想使用光电鼠标来测量机器人在X和Y方向上的位移。我在树莓派上使用Ubuntu mate 18.04并编写了以下python代码:
mouse = file('/dev/input/mouse0')
while True:
status, dx, dy = tuple(ord(c) for c in mouse.read(3))
def to_signed(n):
return n - ((0x80 & n) << 1)
dx = to_signed(dx)
dy = to_signed(dy)
print "%#02x %d %d" % (status, dx, dy)
但是这些位移值取决于速度。我只想要ment值,它与加速度无关。