text stringlengths 0 93.6k |
|---|
self.ser.close() |
return |
def _closeSer(self): |
""" just disconnects the serial port """ |
self.ser.close() |
return |
def _openSer(self): |
""" opens the port again """ |
self.ser.open() |
return |
def _drive(self, roomba_mm_sec, roomba_radius_mm, turn_dir='CCW'): |
""" implements the drive command as specified |
the turn_dir should be either 'CW' or 'CCW' for |
clockwise or counterclockwise - this is only |
used if roomba_radius_mm == 0 (or rounds down to 0) |
other drive-related calls are available |
""" |
# first, they should be ints |
# in case they're being generated mathematically |
if type(roomba_mm_sec) != type(42): |
roomba_mm_sec = int(roomba_mm_sec) |
if type(roomba_radius_mm) != type(42): |
roomba_radius_mm = int(roomba_radius_mm) |
# we check that the inputs are within limits |
# if not, we cap them there |
if roomba_mm_sec < -500: |
roomba_mm_sec = -500 |
if roomba_mm_sec > 500: |
roomba_mm_sec = 500 |
# if the radius is beyond the limits, we go straight |
# it doesn't really seem to go straight, however... |
if roomba_radius_mm < -2000: |
roomba_radius_mm = 32768 |
if roomba_radius_mm > 2000: |
roomba_radius_mm = 32768 |
# get the two bytes from the velocity |
# these come back as numbers, so we will chr them |
velHighVal, velLowVal = _toTwosComplement2Bytes( roomba_mm_sec ) |
# get the two bytes from the radius in the same way |
# note the special cases |
if roomba_radius_mm == 0: |
if turn_dir == 'CW': |
roomba_radius_mm = -1 |
else: # default is 'CCW' (turning left) |
roomba_radius_mm = 1 |
radiusHighVal, radiusLowVal = _toTwosComplement2Bytes( roomba_radius_mm ) |
#print 'bytes are', velHighVal, velLowVal, radiusHighVal, radiusLowVal |
# send these bytes and set the stored velocities |
self._write( DRIVE ) |
self._write( chr(velHighVal) ) |
self._write( chr(velLowVal) ) |
self._write( chr(radiusHighVal) ) |
self._write( chr(radiusLowVal) ) |
def setLEDs(self, power_color, power_intensity, play, advance ): |
""" The setLEDs method sets each of the three LEDs, from left to right: |
the power LED, the play LED, and the status LED. |
The power LED at the left can display colors from green (0) to red (255) |
and its intensity can be specified, as well. Hence, power_color and |
power_intensity are values from 0 to 255. The other two LED inputs |
should either be 0 (off) or 1 (on). |
""" |
# make sure we're within range... |
if advance != 0: advance = 1 |
if play != 0: play = 1 |
try: |
power = int(power_intensity) |
powercolor = int(power_color) |
except TypeError: |
power = 128 |
powercolor = 128 |
print 'Type excpetion caught in setAbsoluteLEDs in roomba.py' |
print 'Your power_color or power_intensity was not of type int.' |
if power < 0: power = 0 |
if power > 255: power = 255 |
if powercolor < 0: powercolor = 0 |
if powercolor > 255: powercolor = 255 |
# create the first byte |
#firstByteVal = (status << 4) | (spot << 3) | (clean << 2) | (max << 1) | dirtdetect |
firstByteVal = (advance << 3) | (play << 1) |
# send these as bytes |
# print 'bytes are', firstByteVal, powercolor, power |
self._write( LEDS ) |
self._write( chr(firstByteVal) ) |
self._write( chr(powercolor) ) |
self._write( chr(power) ) |
return |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.