Difference between revisions of "Robotics-2010"

From Earlham CS Department
Jump to navigation Jump to search
(Ubuntu)
(Lab 6)
 
(23 intermediate revisions by 6 users not shown)
Line 1: Line 1:
= NXT-Python Documentation =
+
= Resources for CS282 - Robotics =
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).
+
== Hardware ==
 +
* [[change-NXT-settings|How to change the name of your NXT]]
  
=== nxt.locator ===  
+
== Software Stack ==
The function of this module is to locate NXT brick(s). Returns an <code>nxt.bluesock.BlueSock</code> object for robots connected by Bluetooth and a <code>nxt.usbsock.USBSock</code> object for robot connected by USB, and throws <code>nxt.locator.BrickNotFoundError</code> if none can be found.
+
* [http://cs.earlham.edu/~charliep/courses/cs282/packages/ Software Packages (nxt-python, etc)]
 +
* [[nxt-python-iso|Ubuntu with Brad's Live ISO]]
 +
* [[nxt-python-osx|OSX]]
  
* Status: incomplete as of 2010-02-14
+
== Python ==
 +
* [[nxt-python-doc|NXT-Python Documentation]]
 +
* [[nxt-python-hints|Programming Hints]]
 +
* [[nxt-python-threads|Thread Notes]]
  
* Objects
+
== Sensor Notes ==
** <code>nxt.bluesock.BlueSock</code> - The object returned by <code>find_one_brick()</code> when a brick is found on a Bluetooth connection [defined in nxt.bluesock]
+
* [[bots-hitechnic-compass|HiTechnic Compass]]
** <code>nxt.usbsock.USBSock</code> - The object returned by <code>find_one_brick()</code>when a brick is found on a USB connection [defined in nxt.usbsock]
 
** <code>nxt.brick.Brick</code> - The object returned by the <code>connect()</code> method [defined in nxt.brick]
 
  
* Methods
+
== Non-local Resources ==
** <code>connect()</code> - Try to connect to the brick.
+
* Bluetooth - NXT [http://vikram.eggwall.com/computers/nxt-bluetooth-setup.html setup notes]
** <code>close()</code> - Close connection to brick.
 
** <code>host</code> - Returns the address of the brick (if connected via Bluetooth connection)
 
** generator object <code>find_bricks()</code>
 
*** <code>next()</code> - Find the next brick in the sequence, returns the same thing as <code>find_one_brick()</code>.  
 
** <code>find_one_brick()</code>
 
** <code>find_bricks(host=None, name=None)</code> - Find all the bricks in the area, returns a generator object <code>find_bricks</code>.  
 
  
* Example
+
= Lab 6 =
import nxt.locator
+
* [http://cs.earlham.edu/~charliep/courses/cs282/mapping.pdf The Official Assignment]
sock = nxt.locator.find_one_brick()
+
* [[robotics-lab6-tasks|Task Analysis - Original]]
brick = sock.connect()
+
* [[Robotics-lab6-newversion|Task Analysis - Second Go 'Round]]
if hasattr(brick, 'host'):
+
* [http://github.com/Sleemanmunk/Magnetic-Mapping Software Repository]
  print brick.host
+
* [http://cs.earlham.edu/~carrick/courses/cs282/lab6/visualization Visualization]
else:
 
  print "brick.host is not defined for USB connections"
 
sock.close()
 
 
 
=== nxt.motor ===
 
 
 
* Port Constants
 
** <code>PORT_A</code>
 
** <code>PORT_B</code>
 
** <code>PORT_C</code>
 
** <code>PORT_ALL</code>
 
 
 
* Mode Constants
 
** <code>MODE_IDLE</code>
 
** <code>MODE_MOTOR_ON</code>
 
** <code>MODE_BRAKE</code>
 
** <code>MODE_REGULATED</code>
 
 
 
* Regulation Constants
 
** <code>REGULATION_IDLE</code>
 
** <code>REGULATION_MOTOR_SPEED</code>
 
** <code>REGULATION_MOTOR_SYNC</code>
 
 
 
* Run State Constants
 
** <code>RUN_STATE_IDLE</code>
 
** <code>RUN_STATE_RAMP_UP</code>
 
** <code>RUN_STATE_RUNNING</code>
 
** <code>RUN_STATE_RAMP_DOWN</code>
 
 
 
* Objects
 
** <code>nxt.motor.Motor</code> - The object returned by <code>Motor(brick, port)</code>
 
** 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.
 
** [http://www.hitechnic.com/cgi-bin/commerce.cgi?preadd=action&key=NMC1034 Compass Sensor hardware info]
 
** URL to compass.py in source control (hint)
 
 
 
=== Scripts ===
 
Located in <code>$DISTRIBUTION/scripts</code>.
 
* nxt_filer
 
* nxt_push
 
* nxt_test
 
 
 
=== Setup ===
 
==== Ubuntu ====
 
# Download [http://cs.earlham.edu/~carrick/courses/cs282/nxt.tgz Brad's installation kit] and untar it anywhere you want.
 
# In your editor of choice, modify the install.sh script to connect to your brick instead of Brad's
 
# Open a terminal, navigate to the folder with your newly untarred files and type
 
sudo ./install
 
If your computer supports bluetooth, set up your connection to your robot
 
# Turn on your brick.
 
# Navigate through the menu to enable bluetooth
 
#* Ensure that your device is set to "findable"
 
# Click the bluetooth symbol at the top of your computer's screen, next to the envelope.
 
# Select "Set up new device"
 
# Select your robot
 
# You will be prompted to input a passkey into your robot
 
#* Use the small grey button to delete characters and the large orange button to select characters
 
#* Select the checkmark to submit your passkey
 
#* Work quickly! You have about a minute before the passkey kicks you out and makes you start over!
 
#* You will be notified on-screen if your passkey was successful
 
# After your passkey is accepted, try running query.py
 
 
 
=== Server Mode and nxt.server ===
 

Latest revision as of 19:48, 15 April 2010