Exemple #1
0
    def __programThread(self):
        printf("Interpreter| ##### STARTING PROGRAM #####\n")

        fpsTimer = FpsTimer(fps=30)

        # Main program loop - where events are checked and run
        while not self.isExiting():
            # Maintain constant FPS using an FPSTimer
            fpsTimer.wait()
            if not fpsTimer.ready(): continue

            # currRunning keeps track of what was run, so the GUI can draw it
            self.currRunning = {"event": -1, "command": -1}

            # Check every event, in order of the list
            exitCommand = False  # If the interpreter reached an "ExitProgram" command
            for index, event in enumerate(self.events):
                if self.isExiting(): break
                if not event.isActive(): continue

                # If the event has been activated, run the commandList
                self.currRunning["event"] = self.events.index(event)
                exitCommand = self.interpretCommandList(event.commandList)
                if exitCommand: break
            if exitCommand: break

        self.events = []
        printf("Interpreter| Interpreter Thread Ended")
        self.mainThread = None
    def __programThread(self):
        printf("Interpreter| ##### STARTING PROGRAM #####\n")

        fpsTimer = FpsTimer(fps=30)

        # Main program loop - where events are checked and run
        while not self.isExiting():
            # Maintain constant FPS using an FPSTimer
            fpsTimer.wait()
            if not fpsTimer.ready(): continue


            # currRunning keeps track of what was run, so the GUI can draw it
            self.currRunning = {"event": -1, "command": -1}



            # Check every event, in order of the list
            exitCommand = False  # If the interpreter reached an "ExitProgram" command
            for index, event in enumerate(self.events):
                if self.isExiting(): break
                if not event.isActive(): continue

                # If the event has been activated, run the commandList
                self.currRunning["event"] = self.events.index(event)
                exitCommand = self.interpretCommandList(event.commandList)
                if exitCommand: break
            if exitCommand: break


        self.events     = []
        printf("Interpreter| Interpreter Thread Ended")
        self.mainThread = None
    def __programThread(self):
        printf("\n\n\n ##### STARTING PROGRAM #####\n")


        fpsTimer = FpsTimer(fps=30)

        # Main program loop - where events are checked and run
        while not self.isExiting():
            # Maintain constant FPS using an FPSTimer
            fpsTimer.wait()
            if not fpsTimer.ready(): continue


            # currRunning keeps track of what was run, so the GUI can draw it
            self.currRunning = {}


            # Check every event, in order of the list
            for index, event in enumerate(self.events):
                if self.isExiting(): break
                if not event.isActive(): continue

                # If the event has been activated, run the commandList
                self.__interpretEvent(event)


        # Check if a DestroyEvent exists, if so, run it's commandList
        destroyEvent = list(filter(lambda event: type(event) == Events.DestroyEvent, self.events))

        if len(destroyEvent):
            # Make sure the robot, vision, and interpreter can respond before running the destroy event
            self.setExiting(False)
            self.__interpretEvent(destroyEvent[0])

            # Set the robot, vision, and interpreter back to non-responsive mode after running the destroy event
            self.setExiting(True)

        self.mainThread = None
        self.events     = []
        self.setExiting(False)
Exemple #4
0
    def __videoThread(self):
        """"
            A main thread that focuses soley on grabbing frames from a camera, limited only by self.fps
            Thread is created at startThread, which can be called by setPaused
            Thread is ended only at endThread
        """


        self.frameList = []

        fpsTimer = FpsTimer(self.fps)
        printf("Video| Starting videoStream thread.")

        while self.running:
            fpsTimer.wait()
            if not fpsTimer.ready():       continue
            if self.setCamera is not None: self.__setNewCamera(self.setCamera)
            if self.paused:                continue
            if self.cap is None:           continue


            # Get a new frame
            ret, newFrame = self.cap.read()

            if not ret:  # If a frame was not successfully returned
                printf("Video| ERROR: while reading frame from Cam. Setting camera again...")
                self.__setNewCamera(self.cameraID)
                cv2.waitKey(1000)
                continue


            # Do frame related work
            with self.frameLock:
                self.frame = newFrame

                # Add a frame to the frameList that records the 5 latest frames for Vision uses
                self.frameList.insert(0, self.frame.copy())

                while len(self.frameList) > 10:
                    del self.frameList[-1]

                # Keep track of new frames by counting them. (100 is an arbitrary number)
                if self.frameCount >= 100:
                    self.frameCount = 0
                else:
                    self.frameCount += 1


            # Run any work functions that must be run. Expect no results. Work should be run before filters.
            if len(self.workList) > 0:
                # print("Work: ", self.workList)
                with self.workLock:
                    for workFunc in self.workList:
                        workFunc(self.frame)



            # Run any filters that must be run, save the results in self.filterFrame
            if len(self.filterList) > 0:
                # print("Filters: ", self.filterList)
                with self.filterLock:
                    filterFrame = self.frame.copy()
                    for filterFunc in self.filterList:
                        filterFrame = filterFunc(filterFrame)

                    # Draw FPS on the screen
                    fps = str(int(round(fpsTimer.currentFPS, 0)))
                    cv2.putText(filterFrame, fps, (10, 20),  cv2.FONT_HERSHEY_PLAIN, 1.25, (255, 255, 255), 2)

                    self.filterFrame = filterFrame
            else:
                self.filterFrame = self.frame

        if self.cap is not None:
            self.cap.release()
        self.mainThread = None
    def __videoThread(self):
        """"
            A main thread that focuses soley on grabbing frames from a camera, limited only by self.fps
            Thread is created at startThread, which can be called by setPaused
            Thread is ended only at endThread
        """

        self.frameList = []

        fpsTimer = FpsTimer(self.fps)
        printf("Video| Starting videoStream thread.")

        while self.running:
            fpsTimer.wait()
            if not fpsTimer.ready(): continue
            if self.setCamera is not None: self.__setNewCamera(self.setCamera)
            if self.cap is None: continue

            # Get a new frame
            ret, newFrame = self.cap.read()

            if not ret:  # If a frame was not successfully returned
                printf(
                    "Video| ERROR: while reading frame from Cam. Setting camera again..."
                )
                self.__setNewCamera(self.cameraID)
                cv2.waitKey(1000)
                continue

            # Do frame related work
            with self.frameLock:
                self.frame = newFrame

                # Add a frame to the frameList that records the 5 latest frames for Vision uses
                self.frameList.insert(0, self.frame.copy())

                while len(self.frameList) > 10:
                    del self.frameList[-1]

                # Keep track of new frames by counting them. (100 is an arbitrary number)
                if self.frameCount >= 100:
                    self.frameCount = 0
                else:
                    self.frameCount += 1

            # Run any work functions that must be run. Expect no results. Work should be run before filters.
            if len(self.workList) > 0:
                # print("Work: ", self.workList)
                with self.workLock:
                    for workFunc in self.workList:
                        workFunc(self.frame)

            # Run any filters that must be run, save the results in self.filterFrame
            if len(self.filterList) > 0:
                # print("Filters: ", self.filterList)
                with self.filterLock:
                    filterFrame = self.frame.copy()
                    for filterFunc in self.filterList:
                        filterFrame = filterFunc(filterFrame)

                    # Draw FPS on the screen
                    fps = str(int(round(fpsTimer.currentFPS, 0)))
                    cv2.putText(filterFrame, fps, (10, 20),
                                cv2.FONT_HERSHEY_PLAIN, 1.25, (255, 255, 255),
                                2)

                    self.filterFrame = filterFrame
            else:
                self.filterFrame = self.frame

        # if self.cap is not None:
        #     self.cap.release()
        self.mainThread = None