Nxt-python-doc
Jump to navigation
Jump to 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).
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.
- Status: incomplete as of 2010-02-14
- Objects
nxt.bluesock.BlueSock- The object returned byfind_one_brick()when a brick is found on a Bluetooth connection [defined in nxt.bluesock]nxt.usbsock.USBSock- The object returned byfind_one_brick()when a brick is found on a USB connection [defined in nxt.usbsock]nxt.brick.Brick- The object returned by theconnect()method [defined in nxt.brick]
- Methods
connect()- Try to connect to the brick.close()- Close connection to brick.host- Returns the address of the brick (if connected via Bluetooth connection)- generator object
find_bricks()next()- Find the next brick in the sequence, returns the same thing asfind_one_brick().
find_one_brick()find_bricks(host=None, name=None)- Find all the bricks in the area, returns a generator objectfind_bricks.
- Example
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
- Port Constants
PORT_APORT_BPORT_CPORT_ALL
- Mode Constants
MODE_IDLEMODE_MOTOR_ONMODE_BRAKEMODE_REGULATED
- Regulation Constants
REGULATION_IDLEREGULATION_MOTOR_SPEEDREGULATION_MOTOR_SYNC
- Run State Constants
RUN_STATE_IDLERUN_STATE_RAMP_UPRUN_STATE_RUNNINGRUN_STATE_RAMP_DOWN
- Objects
nxt.motor.Motor- The object returned byMotor(brick, port)- Class Methods
- _debug_out(self, message)
- set_output_state(self)
- get_output_state(self)
- reset_position(self, relative)
- run(self, power=100, regulated=1)
- stop(self, braking=1)
- update(self, power, tacho_limit, braking=False, max_retries=-1)
- Methods
- Example
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.
- Status: incomplete as of 2010-02-14
- Objects
- Methods
- Example
nxt.compass
- This code is a start on a compass class, it is not finished.
Scripts
Located in $DISTRIBUTION/scripts.
- nxt_filer
- nxt_push
- nxt_test