예제 #1
0
class Controller(object):
    def __init__(self):
        self.rcData = RCData()
        self.cam = CameraData()
        self.cmdManager = CommandManager()
        self.actionManager = ActionManager()
        self.heightController = heightControl(self.rcData)
        #self.recog = Recognition(self.cam)
        self.symbolList = []
        self.currentCommand = None
        self.board = MultiWii('/dev/ttyUSB0')

        #self.loadActions()
        #self.loadCommands()
        #self.loadSymbols()
        self.Load.loadAction()
        self.Load.loadCommands()
        self.Load.loadSymbols()

        time.sleep(1)

    def start(self):  #starten van de threading en processen
        self.commandThread = threading.Thread(target=self.commandHandler)
        self.symbolThread = threading.Thread(target=self.compareSymbols)
        self.symbolThread.start()
        self.commandThread.start()

        self.distance.start()
        self.cam.start()

        while True:
            self.board.sendCMD(8, MultiWii.SEND_RAW_RC, self.rcData.toArray())
            time.sleep(0.1)

    def compareSymbols(self):  #vergelijken van images
        while self.recog.processedImage is None:
            pass
        oldTimestamp = None
        while True:
            if oldTimestamp != self.recog.timestamp:
                oldTimestamp = self.recog.timestamp
                diffs = [
                    self.recog.compareImage(self.recog.processedImage,
                                            symbol.image)
                    for symbol in self.symbolList
                ]
                filteredDiffs = [diff for diff in diffs if diff is not None]
                index = diffs.index(min(filteredDiffs))
                detectedSymbol = self.symbolList[index]
                self.currentCommand = detectedSymbol.command

    def commandHandler(self):  #afhandeling van commando's.
        while self.currentCommand is None:
            pass

        previousCommand = None
        commandThread = None
        while True:
            if self.currentCommand != previousCommand:
                previousCommand = self.currentCommand
                if commandThread is not None:
                    self.cmdManager.stopCommand()
                    while commandThread.isAlive():
                        pass
                commandThread = threading.Thread(
                    target=self.cmdManager.execute,
                    args=(self.currentCommand, ))
                commandThread.start()
예제 #2
0
class Controller(object):
    def __init__(self):
        self.rcData = RCData()
        self.cam = CameraData()
        self.cmdManager = CommandManager()
        self.actionManager = ActionManager()
        self.heightController = heightControl(self.rcData)
        #self.recog = Recognition(self.cam)
        self.symbolList = []
        self.currentCommand = None
        self.board = MultiWii('/dev/ttyUSB0')

        #self.loadActions()
        #self.loadCommands()
        #self.loadSymbols()
        self.Load.loadAction()
        self.Load.loadCommands()
        self.Load.loadSymbols()

        time.sleep(1)
    
    def start(self): #starten van de threading en processen
        self.commandThread = threading.Thread(target = self.commandHandler)
        self.symbolThread = threading.Thread(target = self.compareSymbols)
        self.symbolThread.start()
        self.commandThread.start()

        self.distance.start()
        self.cam.start()

        while True:
            self.board.sendCMD(8, MultiWii.SEND_RAW_RC, self.rcData.toArray())
            time.sleep(0.1)
            
        
    def compareSymbols(self): #vergelijken van images
        while self.recog.processedImage is None:
            pass
        oldTimestamp = None
        while True:
            if oldTimestamp != self.recog.timestamp:
                oldTimestamp = self.recog.timestamp
                diffs = [self.recog.compareImage(self.recog.processedImage, symbol.image) for symbol in self.symbolList]
                filteredDiffs = [diff for diff in diffs if diff is not None]
                index = diffs.index(min(filteredDiffs))
                detectedSymbol = self.symbolList[index]
                self.currentCommand = detectedSymbol.command
            
    def commandHandler(self): #afhandeling van commando's. 
        while self.currentCommand is None: pass
        
        previousCommand = None
        commandThread = None
        while True:
            if self.currentCommand != previousCommand:
                previousCommand = self.currentCommand
                if commandThread is not None:
                    self.cmdManager.stopCommand()
                    while commandThread.isAlive():
                        pass
                commandThread = threading.Thread(target = self.cmdManager.execute, args = (self.currentCommand,))
                commandThread.start()