コード例 #1
0
def run():
    global direction_command, turn_command, SmoothMode, steadyMode
    moving_threading = threading.Thread(
        target=move_thread)  #Define a thread for moving
    moving_threading.setDaemon(
        True
    )  #'True' means it is a front thread,it would close when the mainloop() closes
    moving_threading.start()  #Thread starts

    info_threading = threading.Thread(
        target=info_send_client)  #Define a thread for communication
    info_threading.setDaemon(
        True
    )  #'True' means it is a front thread,it would close when the mainloop() closes
    info_threading.start()  #Thread starts

    #info_threading=threading.Thread(target=FPV_thread)    #Define a thread for FPV and OpenCV
    #info_threading.setDaemon(True)                        #'True' means it is a front thread,it would close when the mainloop() closes
    #info_threading.start()                                #Thread starts

    ws_R = 0
    ws_G = 0
    ws_B = 0

    Y_pitch = 300
    Y_pitch_MAX = 600
    Y_pitch_MIN = 100

    while True:
        data = ''
        data = str(tcpCliSock.recv(BUFSIZ).decode())
        if not data:
            continue
        elif 'forward' == data:
            direction_command = 'forward'
        elif 'backward' == data:
            direction_command = 'backward'
        elif 'DS' in data:
            direction_command = 'stand'

        elif 'left' == data:
            turn_command = 'left'
        elif 'right' == data:
            turn_command = 'right'
        elif 'leftside' == data:
            turn_command = 'left'
        elif 'rightside' == data:
            turn_command = 'right'
        elif 'TS' in data:
            turn_command = 'no'

        elif 'headup' == data:
            move.look_up()
        elif 'headdown' == data:
            move.look_down()
        elif 'headhome' == data:
            move.look_home()

        elif 'headleft' == data:
            move.look_left()
        elif 'headright' == data:
            move.look_right()

        elif 'wsR' in data:
            try:
                set_R = data.split()
                ws_R = int(set_R[1])
                LED.colorWipe(Color(ws_R, ws_G, ws_B))
            except:
                pass
        elif 'wsG' in data:
            try:
                set_G = data.split()
                ws_G = int(set_G[1])
                LED.colorWipe(Color(ws_R, ws_G, ws_B))
            except:
                pass
        elif 'wsB' in data:
            try:
                set_B = data.split()
                ws_B = int(set_B[1])
                LED.colorWipe(Color(ws_R, ws_G, ws_B))
            except:
                pass

        elif 'FindColor' in data:
            LED.breath_status_set(1)
            fpv.FindColor(1)
            tcpCliSock.send(('FindColor').encode())

        elif 'WatchDog' in data:
            LED.breath_status_set(1)
            fpv.WatchDog(1)
            tcpCliSock.send(('WatchDog').encode())

        elif 'steady' in data:
            LED.breath_status_set(1)
            LED.breath_color_set('blue')
            steadyMode = 1
            tcpCliSock.send(('steady').encode())

        elif 'funEnd' in data:
            LED.breath_status_set(0)
            fpv.FindColor(0)
            fpv.WatchDog(0)
            steadyMode = 0
            tcpCliSock.send(('FunEnd').encode())

        elif 'Smooth_on' in data:
            SmoothMode = 1
            tcpCliSock.send(('Smooth_on').encode())

        elif 'Smooth_off' in data:
            SmoothMode = 0
            tcpCliSock.send(('Smooth_off').encode())

        elif 'Switch_1_on' in data:
            switch.switch(1, 1)
            tcpCliSock.send(('Switch_1_on').encode())

        elif 'Switch_1_off' in data:
            switch.switch(1, 0)
            tcpCliSock.send(('Switch_1_off').encode())

        elif 'Switch_2_on' in data:
            switch.switch(2, 1)
            tcpCliSock.send(('Switch_2_on').encode())

        elif 'Switch_2_off' in data:
            switch.switch(2, 0)
            tcpCliSock.send(('Switch_2_off').encode())

        elif 'Switch_3_on' in data:
            switch.switch(3, 1)
            tcpCliSock.send(('Switch_3_on').encode())

        elif 'Switch_3_off' in data:
            switch.switch(3, 0)
            tcpCliSock.send(('Switch_3_off').encode())

        elif 'CVFL' in data:  #2 start
            if not FPV.FindLineMode:
                FPV.FindLineMode = 1
                tcpCliSock.send(('CVFL_on').encode())
            else:
                # move.motorStop()
                # FPV.cvFindLineOff()
                FPV.FindLineMode = 0
                tcpCliSock.send(('CVFL_off').encode())

        elif 'Render' in data:
            if FPV.frameRender:
                FPV.frameRender = 0
            else:
                FPV.frameRender = 1

        elif 'WBswitch' in data:
            if FPV.lineColorSet == 255:
                FPV.lineColorSet = 0
            else:
                FPV.lineColorSet = 255

        elif 'lip1' in data:
            try:
                set_lip1 = data.split()
                lip1_set = int(set_lip1[1])
                FPV.linePos_1 = lip1_set
            except:
                pass

        elif 'lip2' in data:
            try:
                set_lip2 = data.split()
                lip2_set = int(set_lip2[1])
                FPV.linePos_2 = lip2_set
            except:
                pass

        elif 'err' in data:  #2 end
            try:
                set_err = data.split()
                err_set = int(set_err[1])
                FPV.findLineError = err_set
            except:
                pass

        elif 'setEC' in data:  #Z
            ECset = data.split()
            try:
                fpv.setExpCom(int(ECset[1]))
            except:
                pass

        elif 'defEC' in data:  #Z
            fpv.defaultExpCom()

        else:
            pass
コード例 #2
0
def run():
    global direction_command, turn_command, SmoothMode, steadyMode
    moving_threading = threading.Thread(
        target=move_thread)  #Define a thread for moving
    moving_threading.setDaemon(
        True
    )  #'True' means it is a front thread,it would close when the mainloop() closes
    moving_threading.start()  #Thread starts

    info_threading = threading.Thread(
        target=info_send_client)  #Define a thread for information sending
    info_threading.setDaemon(
        True
    )  #'True' means it is a front thread,it would close when the mainloop() closes
    info_threading.start()  #Thread starts

    ws_R = 0
    ws_G = 0
    ws_B = 0

    Y_pitch = 300
    Y_pitch_MAX = 600
    Y_pitch_MIN = 100

    while True:
        data = ''
        data = str(tcpCliSock.recv(BUFSIZ).decode())
        if not data:
            continue
        elif 'forward' == data:
            direction_command = 'forward'
        elif 'backward' == data:
            direction_command = 'backward'
        elif 'DS' in data:
            direction_command = 'stand'

        elif 'left' == data:
            turn_command = 'left'
        elif 'right' == data:
            turn_command = 'right'
        elif 'leftside' == data:
            turn_command = 'left'
        elif 'rightside' == data:
            turn_command = 'right'
        elif 'TS' in data:
            turn_command = 'no'

        elif 'headup' == data:
            move.look_up()
        elif 'headdown' == data:
            move.look_down()
        elif 'headhome' == data:
            move.look_home()

        elif 'headleft' == data:
            move.look_left()
        elif 'headright' == data:
            move.look_right()

        elif 'wsR' in data:
            try:
                set_R = data.split()
                ws_R = int(set_R[1])
                LED.colorWipe(Color(ws_R, ws_G, ws_B))
            except:
                pass
        elif 'wsG' in data:
            try:
                set_G = data.split()
                ws_G = int(set_G[1])
                LED.colorWipe(Color(ws_R, ws_G, ws_B))
            except:
                pass
        elif 'wsB' in data:
            try:
                set_B = data.split()
                ws_B = int(set_B[1])
                LED.colorWipe(Color(ws_R, ws_G, ws_B))
            except:
                pass

        elif 'steady' in data:
            LED.breath_status_set(1)
            LED.breath_color_set('blue')
            steadyMode = 1
            tcpCliSock.send(('steady').encode())

        elif 'funEnd' in data:
            LED.breath_status_set(0)
            steadyMode = 0
            tcpCliSock.send(('FunEnd').encode())

        elif 'Smooth_on' in data:
            SmoothMode = 1
            tcpCliSock.send(('Smooth_on').encode())

        elif 'Smooth_off' in data:
            SmoothMode = 0
            tcpCliSock.send(('Smooth_off').encode())

        elif 'Switch_1_on' in data:
            switch.switch(1, 1)
            tcpCliSock.send(('Switch_1_on').encode())

        elif 'Switch_1_off' in data:
            switch.switch(1, 0)
            tcpCliSock.send(('Switch_1_off').encode())

        elif 'Switch_2_on' in data:
            switch.switch(2, 1)
            tcpCliSock.send(('Switch_2_on').encode())

        elif 'Switch_2_off' in data:
            switch.switch(2, 0)
            tcpCliSock.send(('Switch_2_off').encode())

        elif 'Switch_3_on' in data:
            switch.switch(3, 1)
            tcpCliSock.send(('Switch_3_on').encode())

        elif 'Switch_3_off' in data:
            switch.switch(3, 0)
            tcpCliSock.send(('Switch_3_off').encode())

        else:
            pass
コード例 #3
0
 def FindColor(self, invar):
     global FindColorMode
     FindColorMode = invar
     if not FindColorMode:
         move.look_home()