Nxt-python-doc

From Earlham Cluster Department

Jump to: navigation, search

Back to Robotics Main Page


Largely a work in-progress, please add/edit as you learn the details. Note that this page is documenting the NXT-Python v1.1 release (http://code.google.com/p/nxt-python/), not the NXT_Python v0.7 release which appears to have gone dormant (note hyphen vs underscore).

Contents

nxt.locator

The function of this module is to locate NXT brick(s). Returns an nxt.bluesock.BlueSock object for robots connected by Bluetooth and a nxt.usbsock.USBSock object for robot connected by USB, and throws nxt.locator.BrickNotFoundError if none can be found.

import nxt.locator 
sock = nxt.locator.find_one_brick() 
brick = sock.connect()
if hasattr(brick, 'host'):
 print brick.host
else:
 print "brick.host is not defined for USB connections"
sock.close()

nxt.motor

import nxt.locator
import nxt.motor
from time import sleep
sock = nxt.locator.find_one_brick()
brick = sock.connect()
motor_a = nxt.motor.Motor(brick, nxt.motor.PORT_A)
print "Initial Position:", motor_a.get_output_state()[7]
motor_a.update( 127, 360, True ) # Turn 360 degrees at full power and brake
motor_a.update( -127, 360 ) # Turn -360 degrees at full power and coast
sleep( 3 ) # update is non-blocking when braking is false, must wait for finish
print "Final Position:", motor_a.get_output_state()[7]
sock.close()

nxt.sensor

See the Sensors page for code snippets illustrating sensor use.

nxt.compass

Scripts

Located in $DISTRIBUTION/scripts.

Server Mode and nxt.server

Personal tools
Namespaces
Variants
Actions
websites
wiki
this semester
Toolbox