text
stringlengths 1
93.6k
|
|---|
lowerbits = byte & 127
|
if topbit == 1:
|
return lowerbits - (1 << 7)
|
else:
|
return lowerbits
|
def _twosComplementInt2bytes( highByte, lowByte ):
|
""" returns an int which has the same value
|
as the twosComplement value stored in
|
the two bytes passed in
|
the output range should be -32768 to 32767
|
chars or ints can be input, both will be
|
truncated to 8 bits
|
"""
|
# take everything except the top bit
|
topbit = _bitOfByte( 7, highByte )
|
lowerbits = highByte & 127
|
unsignedInt = lowerbits << 8 | (lowByte & 0xFF)
|
if topbit == 1:
|
# with sufficient thought, I've convinced
|
# myself of this... we'll see, I suppose.
|
return unsignedInt - (1 << 15)
|
else:
|
return unsignedInt
|
def _toTwosComplement2Bytes( value ):
|
""" returns two bytes (ints) in high, low order
|
whose bits form the input value when interpreted in
|
two's complement
|
"""
|
# if positive or zero, it's OK
|
if value >= 0:
|
eqBitVal = value
|
# if it's negative, I think it is this
|
else:
|
eqBitVal = (1<<16) + value
|
return ( (eqBitVal >> 8) & 0xFF, eqBitVal & 0xFF )
|
#
|
# this class represents a snapshot of the robot's data
|
#
|
class SensorFrame:
|
""" the sensorFrame class is really a struct whose
|
fields are filled in by sensorStatus
|
"""
|
def __init__(self):
|
""" constructor -- set all fields to 0
|
"""
|
self.casterDrop = 0
|
self.leftWheelDrop = 0
|
self.rightWheelDrop = 0
|
self.leftBump = 0
|
self.rightBump = 0
|
self.wallSensor = 0
|
self.leftCliff = 0
|
self.frontLeftCliff = 0
|
self.frontRightCliff = 0
|
self.rightCliff = 0
|
self.virtualWall = 0
|
self.driveLeft = 0
|
self.driveRight = 0
|
self.mainBrush = 0
|
self.vacuum = 0
|
self.sideBrush = 0
|
self.leftDirt = 0
|
self.rightDirt = 0
|
self.remoteControlCommand = 0
|
self.powerButton = 0
|
self.spotButton = 0
|
self.cleanButton = 0
|
self.maxButton = 0
|
self.distance = 0
|
self.rawAngle = 0
|
self.angleInRadians = 0
|
self.chargingState = 0
|
self.voltage = 0
|
self.current = 0
|
self.temperature = 0
|
self.charge = 0
|
self.capacity = 0
|
self.lightBumpLeft = 0
|
self.lightBumpFrontLeft = 0
|
self.lightCenterLeft = 0
|
self.lightCenterRight = 0
|
self.lightBumpFrontRight = 0
|
self.lightBumpRight = 0
|
self.dirt = 0
|
def __str__(self):
|
""" returns a string with the information
|
from this SensorFrame
|
"""
|
# there's probably a more efficient way to do this...
|
# perhaps just making it all + instead of the separate
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.