Python nxt mindstorms connection issues

1k views Asked by At

I want to connect to a LEGO Mindstorms NXT robot using Python 3 via USB, however I am getting a BrickNotFoundError when I attempt to connect.

Here is the script I am attempting to run:

#!/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)

Running this on python 3.6, in Windows 10, with an NXT Robot connected to the computer via USB cable, gives the following stack trace:

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

I have downloaded pyusb & usblib and already resolved several errors involving not finding usb modules. However, the robot is clearly connected to the computer as the official LEGO NXT software can recognise and program the robot successfully.

I am at a loss as to what to do next. Any suggestions for how to resolve this error welcome...

1

There are 1 answers

0
strutsur On

You must import nxt.usbsock instead of nxt.locator plus you must import nxt. The code will be the following:

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)