diff --git a/script/setup/Layout.py b/script/setup/Layout.py index 9a15175..8153c45 100644 --- a/script/setup/Layout.py +++ b/script/setup/Layout.py @@ -1,8 +1,18 @@ +################################################################################################### +#DEFINITIONS +################################################################################################### + PLATE_SIZE = 480 BLOCK_ROI_TOLERANCE = 12 #mm LED_TOLERANCE = 8 #mm Distance between LEDs = 18mm PUCK_SIZE = 65 +DET_UNIPUCK = "unipuck" +DET_MINISPINE = "minispine" +DET_ERROR = "error" +DET_EMPTY = "empty" + +#Layout table puck_layout = ( #Num Elm A0 Index A1 Uni Mini Center Angle Xuni Yuni Xmini=Xc Ymini==Yc (1 , 'A', 0 , 1, 0.00 , 57.00 , 75.00 , 66.00 , 0.00 , 0.00 , 57.00 , 0.00 , 75.00 ), @@ -37,26 +47,29 @@ puck_layout = ( (30, 'F', 300, 5, 30.00, 111.90, 129.90, 120.90, 330.00, -55.95 , 96.91 , -64.95 , 112.5 ), ) - +################################################################################################### +#Puck class +################################################################################################### class Puck: - def __init__(self, number, block, index, angle, center, led_uni, led_mini): - self.number = number + def __init__(self, id, block, index, angle, center, led_uni, led_mini): + self.id = id self.block = block self.index = index self.angle = angle self.center = center self.led_uni = led_uni self.led_mini = led_mini + self.detect = None def __str__(self): - return "Number: " + str(self.number) + "\nBlock: " + str(self.block) + "\nIndex: " + str(self.index) + "\nAngle: " + str(self.angle) + \ + return "Number: " + str(self.id) + "\nBlock: " + str(self.block) + "\nIndex: " + str(self.index) + "\nAngle: " + str(self.angle) + \ "\nCenter: " + str(self.center) + "\nLed Unipuck: " + str(self.led_uni) + "\nLed Minispine: " + str(self.led_mini) def match(self, x, y): if math.hypot(x-self.led_uni[0], y-self.led_uni[1]) <= LED_TOLERANCE: - return "unipuck" + return DET_UNIPUCK if math.hypot(x-self.led_mini[0], y-self.led_mini[1]) <= LED_TOLERANCE: - return "minispine" + return DET_MINISPINE return None @@ -71,9 +84,9 @@ for p in(puck_layout): if puck.block not in (_block_ids): _block_ids.append(puck.block) -def get_puck(number): +def get_puck(id): for p in _puck_list: - if number==p.number: + if id==p.id: return p return None @@ -85,6 +98,10 @@ def get_pucks(block = None): return ret +################################################################################################### +#Block class +################################################################################################### + class Block: def __init__(self, id, angle_range, x_range, y_range): self.id = id @@ -119,3 +136,25 @@ def get_block(id): def get_blocks(): return _block_list + + + +################################################################################################### +#Detection utilities +################################################################################################### + + +def detect_pucks(point_list, block_id=None): + for puck in get_pucks(id): + puck.detect = DET_ERROR + for point in point_list: + match = puck.match(point[0], point[1]) + if match is not None: + if match==DET_UNIPUCK: + puck.detect = DET_EMPTY if (puck.detect==DET_MINISPINE) else DET_UNIPUCK + elif match==DET_MINISPINE: + puck.detect = DET_EMPTY if (puck.detect==DET_UNIPUCK) else DET_MINISPINE + +detect_pucks(points) +for puck in get_pucks(): + print puck.id, puck.select