def systemInit(): #glo.MODE_SELECT select the workmodel #1: TrackTest 2: BallTest 3: TogetherRun if glo.MODE_SELECT == 1: glo.TheKobuki = Kobuki(glo.KOBUKI_COM) #glo.TheDobot = Dobot(glo.DOBOT_COM) glo.TheDirection = glo.PID(P=glo.TRACK_P, D=glo.TRACK_D) glo.TheThreadLock = threading.Lock() glo.TheTrackThread = TrackThread(1, "Track", 1) glo.TheTrackThread.start() elif glo.MODE_SELECT == 2: glo.TheKobuki = Kobuki(glo.KOBUKI_COM) glo.TheThreadLock = threading.Lock() glo.TheBallThread = BallThread(2, "Ball", 2) glo.TheBallThread.start() else: time.sleep(3) glo.TheKobuki = Kobuki(glo.KOBUKI_COM) glo.TheDobot = Dobot(glo.DOBOT_COM) glo.TheDirection = glo.PID(P=glo.TRACK_P, D=glo.TRACK_D) glo.TheThreadLock = threading.Lock() glo.TheTrackThread = TrackThread(1, "Track", 1) glo.TheTrackThread.start() glo.TheBallThread = BallThread(2, "Ball", 2) glo.TheBallThread.start() time.sleep(0.5)
def systemInit(): glo.TheKobuki = Kobuki(glo.KOBUKI_COM) #glo.TheDobot = Dobot(glo.DOBOT_COM) glo.TheDirection = glo.PID(P=glo.TRACK_P, D=glo.TRACK_D) glo.TheThreadLock = threading.Lock() glo.TheTrackThread = TrackThread(1, "Track", 1) glo.TheTrackThread.start()
def systemInit(): #glo.MODE_SELECT select the workmodel #1: TrackTest 2: BallTest 3: TogetherRun if glo.MODE_SELECT == 1: glo.TheKobuki = Kobuki(glo.KOBUKI_COM) #glo.TheDobot = Dobot(glo.DOBOT_COM) glo.TheDirection = glo.PID(P=glo.TRACK_P, D=glo.TRACK_D) glo.TheThreadLock = threading.Lock() glo.TheTrackThread = TrackThread(1, "Track", 1) glo.TheTrackThread.start() glo.TheStrategyThread = StrategyThread(3, "Strategy", 3) glo.TheStrategyThread.start() elif glo.MODE_SELECT == 2: pass else: pass
def exitThread(self): self.ballCam.release() def processBallImg(img,ball,para): ball.updateImg(img) ball.hsvFilter(tuple(para[0:3]),tuple(para[3:6])) ball.converToBinary(para[6]) ball.getCenter(contoursRange=tuple(para[7:9]), ksize=(para[9],para[9])) glo.TheThreadLock.acquire() glo.TheDistance,glo.TheHighFlag=ball.calculate(PickPosition=glo.PICK_POSITION,Height=glo.HEIGHT) glo.TheThreadLock.release() if glo.DEBUG_FLAG is True: ball.draw(calFlag=True) if __name__ == "__main__": #systemInit() glo.TheKobuki = Kobuki(glo.KOBUKI_COM) glo.TheThreadLock = threading.Lock() glo.TheBallThread=BallThread(2,"Ball",2) glo.TheBallThread.start() count = 0 while True: if glo.TheDistance is not None and glo.TheHighFlag is not None : if glo.TheDistance < glo.PICK_RANGE : glo.PICK_FLAG = True Control() #time.sleep(0.001) count += 1 if count > 100000: #count = 0 break glo.MAIN_STOP_FLAG = False