如何从USB光学鼠标获取位置值

时间:2019-08-08 08:13:35

标签: raspberry-pi mouse ros ubuntu-18.04

我想使用光电鼠标来测量机器人在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值,它与加速度无关。

0 个答案:

没有答案