def handleSignal(signal): signal_type = signal['type'] if signal_type == 'start': print('start') driver.init() elif signal_type == 'shutdown': print('shutdown') driver.destroy() elif signal_type == 'load': payload = signal['payload'] if payload == 'load': print('start load balls') driver.loadBalls() driver.startLoadMotor() elif payload == 'unload': print('start unload balls') driver.unloadBalls() driver.startLoadMotor() elif payload == 'pause': print('pause load motor') driver.stopLoadMotor() else: print('wrong action {}'.format(payload)) elif signal_type == 'position': pos = signal['payload'] if type(pos) == int and 0 <= pos <= 9: print('move to position {}'.format(pos)) driver.changeUpDutyCycle(positionTypes[pos][1]) driver.changeDownDutyCycle(positionTypes[pos][1]) driver.movePWM(positionTypes[pos][0]) else: print('wrong position {}'.format(pos)) else: print('wrong signal type {}'.format(signal_type))
def reachPosition(position): if not(0 <= position <= 9): return 'out of bounds {}'.format(position) driver.changeUpDutyCycle(positionTypes[position][1]) driver.changeDownDutyCycle(positionTypes[position][1]) driver.movePWM(positionTypes[position][0]) return 'move to position %d' % position
def parseDataAndExecute(data): # 0xxxx postition:x # 100xx load load:0 unload:1 pause:2 # 1010x start:0 shutdown:1 if not data[0]: position = binary2Dec(booleanArray2Str(data[1:])) if not (0 <= position <= 9): print('out of bounds {}'.format(position)) return driver.changeUpDutyCycle(positionTypes[position][1]) driver.changeDownDutyCycle(positionTypes[position][1]) driver.movePWM(positionTypes[position][0]) print('move to position %d' % position) elif binary2Dec(booleanArray2Str(data[0:3])) == 4: loadType = binary2Dec(booleanArray2Str(data[3:])) if loadType == 0: driver.loadBalls() driver.startLoadMotor() print('start load balls') elif loadType == 1: driver.unloadBalls() driver.startLoadMotor() print('start unload balls') elif loadType == 2: driver.stopLoadMotor() print('pause load motor') else: print('bad action : {}'.format(loadType)) elif binary2Dec(booleanArray2Str(data[0:4])) == 10: if data[4]: print('shutdown') driver.destroy() else: print('start') driver.init()
def changPosition(position): print('change to position {}'.format(position)) driver.changeUpDutyCycle(positionTypes[position][1]) driver.changeDownDutyCycle(positionTypes[position][1]) driver.movePWM(positionTypes[position][0])
def changeUpDutyCycle(self): dc = int(self.upInput.get()) driver.changeUpDutyCycle(dc)