Robotics-2010: Difference between revisions
Jump to navigation
Jump to search
Minor additions to nxt.locator beginning for nxt.motor |
motor example |
||
| Line 24: | Line 24: | ||
import nxt.locator | import nxt.locator | ||
sock = nxt.locator.find_one_brick() | sock = nxt.locator.find_one_brick() | ||
brick = sock.connect() | brick = sock.connect() | ||
print brick.host | if hasattr(brick, 'host'): | ||
brick.close() | print brick.host | ||
else: | |||
print "brick.host is not defined for USB connections" | |||
sock.close() | |||
=== nxt.motor === | === nxt.motor === | ||
| Line 67: | Line 70: | ||
* Example | * 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 === | === nxt.sensor === | ||
Revision as of 04:09, 22 February 2010
NXT-Python Documentation
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
- Status: incomplete as of 2010-02-14
- Objects
- Methods
- Example
nxt.compass
- Status: incomplete as of 2010-02-14
- Objects
- CompassSensor
- Methods
- CompassSensor(bot,port)
- get_sample() returns a value between zero and 180 depending on the heading of the sensor. There is a one-to-two ratio between degrees from due North and get_sample() values. At the moment this generally returns an error.
- Methods to add
- begin_calibration() tells the sensor to go into calibration mode.
- end_calibration() tells the sensor to leave calibration mode
- Example
compass = UltrasonicSensor(bot, PORT_1) #declare the sensor plugged into port 1 "compass" heading = compass.get_sample()*2 # get the current heading in degrees from due north
- Notes
- The sensor gives errors and fails to register almost all of the time. The reasoning for this is under investigation.
- Compass Sensor hardware info
- URL to compass.py in source control (hint)
Scripts
Located in $DISTRIBUTION/scripts.
- nxt_filer
- nxt_push
- nxt_test