text stringlengths 0 93.6k |
|---|
slist[12] = highVal |
slist[13] = lowVal |
# bytes 14, 15: angle |
highVal, lowVal = _toTwosComplement2Bytes( self.rawAngle ) |
slist[14] = highVal |
slist[15] = lowVal |
# Third Frame |
# byte 16: charging state |
slist[16] = self.chargingState |
# bytes 17, 18: voltage |
slist[17] = (self.voltage >> 8) & 0xFF |
slist[18] = self.voltage & 0xFF |
# bytes 19, 20: current |
highVal, lowVal = _toTwosComplement2Bytes( self.current ) |
slist[19] = highVal |
slist[20] = lowVal |
# byte 21: temperature |
slist[21] = self.temperature |
# bytes 22, 23: charge |
slist[22] = (self.charge >> 8) & 0xFF |
slist[23] = self.charge & 0xFF |
# bytes 24, 25: capacity |
slist[24] = (self.capacity >> 8) & 0xFF |
slist[25] = self.capacity & 0xFF |
# convert to a string |
s = ''.join([ chr(x) for x in slist ]) |
return s |
# |
# the robot class |
# |
class Create: |
""" the Create class is an abstraction of the iRobot Create's |
SCI interface, including communication and a bit |
of processing of the strings passed back and forth |
when you create an object of type Create, the code |
will try to open a connection to it - so, it will fail |
if it's not attached! |
""" |
# to do: check if we can start in other modes... |
def __init__(self, PORT, BAUD_RATE=115200, startingMode=SAFE_MODE): |
""" the constructor which tries to open the |
connection to the robot at port PORT |
""" |
_debug = False |
# to do: find the shortest safe serial timeout value... |
# to do: use the timeout to do more error checking than |
# is currently done... |
# |
# the -1 here is because windows starts counting from 1 |
# in the hardware control panel, but not in pyserial, it seems |
# if PORT is the string 'simulated' (or any string for the moment) |
# we use our SRSerial class |
print 'PORT is', PORT |
if type(PORT) == type('string'): |
if PORT == 'sim': |
print 'In simulated mode...' |
self.ser = 'sim'; # SRSerial('mapSquare.txt') |
else: |
# for Mac/Linux - use whole port name |
# print 'In Mac/Linux mode...' |
self.ser = serial.Serial(PORT, baudrate=BAUD_RATE, timeout=0.5) |
# otherwise, we try to open the numeric serial port... |
else: |
# print 'In Windows mode...' |
self.ser = serial.Serial(PORT-1, baudrate=BAUD_RATE, timeout=0.5) |
# did the serial port actually open? |
if self.ser != 'sim' and self.ser.isOpen(): |
print 'Serial port did open, presumably to a roomba...' |
else: |
print 'Serial port did NOT open, check the' |
print ' - port number' |
print ' - physical connection' |
print ' - baud rate of the roomba (it\'s _possible_, if unlikely,' |
print ' that it might be set to 19200 instead' |
print ' of the default 57600 - removing and' |
print ' reinstalling the battery should reset it.' |
# our OI mode |
self.sciMode = OFF_MODE |
# our sensor dictionary, currently empty |
self.sensord = {} |
# here are the variables that constitute the robot's |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.