我想通过 USB 使用 Python 3 连接到 LEGO Mindstorms NXT 机器人,但是当我尝试连接时出现 BrickNotFoundError。
这是我尝试运行的脚本:
#!/usr/bin/env python
import nxt.locator
from nxt.motor import *
#nxt.locator.make_config()
def spin_around(b):
m_left = Motor(b, PORT_B)
m_left.turn(100, 360)
m_right = Motor(b, PORT_C)
m_right.turn(-100, 360)
b = nxt.locator.find_one_brick(debug = True)
#spin_around(b)
在 python 3.6 上运行此程序,在 Windows 10 中,通过 USB 电缆将 NXT 机器人连接到计算机,提供以下堆栈跟踪:
Host: AB:CD:EF:GH:IJ:KL Name: BRUCE Strict: True
USB: True BT: False Fantom: True FUSB: False FBT: True
Fantom module unavailable, not searching there
Traceback (most recent call last):
File "C:\Users\George\Downloads\nxt\examples\spin.py", line 14, in <module>
b = nxt.locator.find_one_brick(debug = True)
File "C:\Users\George\AppData\Local\Programs\Python\Python36-32\lib\site-packages\nxt\locator.py", line 138, in find_one_brick
raise BrickNotFoundError
nxt.locator.BrickNotFoundError
我已经下载了 pyusb 和 usblib,并且已经解决了一些涉及找不到 usb 模块的错误。然而,机器人显然已经连接到电脑上,LEGO NXT 官方软件可以成功识别和编程机器人。
我不知道下一步该做什么。欢迎就如何解决此错误提出任何建议...
请您参考如下方法:
您必须导入 nxt.usbsock 而不是 nxt.locator 并且您必须导入 nxt。 代码如下:
import nxt
import nxt.usbsock
from nxt.motor import *
#nxt.locator.make_config()
def spin_around(b):
m_left = Motor(b, PORT_B)
m_left.turn(100, 360)
m_right = Motor(b, PORT_C)
m_right.turn(-100, 360)
b = nxt.locator.find_one_brick(debug = True)
