예제 #1
0
async def main_func():
    global recv_dict, send_dict, gs_list
    while 1:
        gs_list = fc.get_grayscale_list()

        if recv_dict['CD'][0] == 'on':
            if fc.is_on_edge(recv_dict['CD'][1], gs_list):
                fc.backward(20)
                time.sleep(0.5)
                fc.stop()

        if recv_dict['TL'][0] == 'on':
            if fc.get_line_status(recv_dict['TL'][1], gs_list) == 0:
                fc.forward(recv_dict['PW'])
            elif fc.get_line_status(recv_dict['TL'][1], gs_list) == -1:
                fc.turn_left(recv_dict['PW'])
            elif fc.get_line_status(recv_dict['TL'][1], gs_list) == 1:
                fc.turn_right(recv_dict['PW'])

        if recv_dict['OA'] == 'on':
            scan_list = fc.scan_step(35)
            if scan_list:
                tmp = scan_list[3:7]
                if tmp != [2, 2, 2, 2]:
                    fc.turn_right(recv_dict['PW'])
                else:
                    fc.forward(recv_dict['PW'])

        elif recv_dict['OF'] == 'on':
            scan_list = fc.scan_step(23)

            if scan_list != False:
                scan_list = [str(i) for i in scan_list]
                scan_list = "".join(scan_list)
                paths = scan_list.split("2")
                length_list = []
                for path in paths:
                    length_list.append(len(path))
                if max(length_list) == 0:
                    fc.stop()
                else:
                    i = length_list.index(max(length_list))
                    pos = scan_list.index(paths[i])
                    pos += (len(paths[i]) - 1) / 2
                    delta = len(scan_list) / 3
                    if pos < delta:
                        fc.turn_left(recv_dict['PW'])
                    elif pos > 2 * delta:
                        fc.turn_right(recv_dict['PW'])
                    else:
                        if scan_list[int(len(scan_list) / 2 - 1)] == "0":
                            fc.backward(recv_dict['PW'])
                        else:
                            fc.forward(recv_dict['PW'])

        elif recv_dict['RD'] == 'on':
            fc.scan_step(35)

        await asyncio.sleep(0.01)
예제 #2
0
def main():
    while True:
        scan_list = fc.scan_step(23)
        # print(scan_list)
        if not scan_list:
            continue

        scan_list = [str(i) for i in scan_list]
        scan_list = "".join(scan_list)
        paths = scan_list.split("2")
        length_list = []
        for path in paths:
            length_list.append(len(path))
        # print(length_list)
        if max(length_list) == 0:
            fc.stop() 
        else:
            i = length_list.index(max(length_list))
            pos = scan_list.index(paths[i])
            pos += (len(paths[i]) - 1) / 2
            # pos = int(pos)
            delta = len(scan_list) / 3
            # delta *= us_step/abs(us_step)
            if pos < delta:
                fc.turn_left(speed)
            elif pos > 2 * delta:
                fc.turn_right(speed)
            else:
                if scan_list[int(len(scan_list)/2-1)] == "0":
                    fc.backward(speed)
                else:
                    fc.forward(speed)
예제 #3
0
def main():
    time.sleep(5)

    while True:
        scan_list = fc.scan_step(buf)
        if not scan_list:
            continue
        tmp = scan_list[2:8]
        tmpL = scan_list[2:5]
        tmpR = scan_list[5:8]
        print(tmp)
        if tmp != [2, 2, 2, 2, 2, 2]:
            print("Back Off")
            fc.backward(pow)
            time.sleep(bak)

            if sum(tmpL) > sum(tmpR):
                print("Turn Left")
                fc.turn_left(pow * 2)
            else:
                print("Turn Right")
                fc.turn_right(pow * 2)

        else:
            fc.forward(pow)
예제 #4
0
def main():
    while True:
        scan_list = fc.scan_step(35)
        if not scan_list:
            continue

        tmp = scan_list[3:7]
        print(tmp)
        if tmp != [2, 2, 2, 2]:
            fc.turn_right(speed)
        else:
            fc.forward(speed)
예제 #5
0
def drive_n_stop(speed: int = 10):
    clear = True
    fc.forward(speed)
    while clear:
        scan_list = fc.scan_step()
        if not scan_list:
            continue

        ahead = scan_list[2:8]
        # coast clear full speed ahead
        if min(ahead) < 2:
            #print("Coast Clear")
            clear = False
            fc.stop()
예제 #6
0
def drive_n_stop(speed: int = 5):
    clear = True
    fc.forward(speed)

    while clear:
        # scan list returns false until a full 180 deg scan is performed.
        scan_list = fc.scan_step(35)
        if not scan_list:
            continue

        ahead = scan_list[2:8]
        if min(ahead) < 2:
            clear = False
            fc.stop()
예제 #7
0
def move_scan():
    
 #   speed = 10   # 30
#    speed1= Speed(10)
#    speed1.start()
    while True:
        scan_list = fc.scan_step(50)
        if not scan_list:
            continue

        tmp = scan_list[3:7]
        print(tmp)
        if tmp != [2,2,2,2]:
           # fc.backward(30)
            fc.turn_right(speed)
           # fc.stop()
        else:
            fc.forward(speed)
예제 #8
0
def main():

    reset_servo(-65)
    while True:
       #reset_servo(-65)
        scan_list = fc.scan_step(25)
        if not scan_list:
            continue

        tmp = scan_list[3:7]
        print(tmp)
        if tmp == [2,2,2,2]:        
            fc.forward(speed)
          #  reset_servo(-65)

        else:
            fc.stop()
            time.sleep(0.5)
            fc.backward(100)
            time.sleep(0.5)
            fc.stop()
            time.sleep(0.5)
            fc.turn_right(50)