Пример #1
0
def stream_data(ser, ref, maxVal):
    while True:
        readingList = []
        count = 0
        while (count < maxVal):
            try:
                (l, r, _) = ser.readline().strip('\x00\r\n').strip().split(',')
                print l, r
                readingList.append((int(l), int(r)))
            except:
                continue

            count += 1
            #readingList = zip(readingList, [0] * len(readingList))
        
        scaled = factory.scale([factory.retSimilarity(readingList, ref, 1), \
                                factory.retSimilarity(readingList, ref, 2), \
                                factory.retSimilarity(readingList, ref, 3)])

        print factory.classify(scaled)

        yield 'data: %s\n\n' %  factory.classify(scaled)

        ser.flushInput()
Пример #2
0
def stream_data(ser, ref, maxVal):
    while True:
        readingList = []
        count = 0
        while (count < maxVal):
            try:
                (l, r, _) = ser.readline().strip('\x00\r\n').strip().split(',')
                print l, r
                readingList.append((int(l), int(r)))
            except:
                continue

            count += 1
            #readingList = zip(readingList, [0] * len(readingList))

        scaled = factory.scale([factory.retSimilarity(readingList, ref, 1), \
                                factory.retSimilarity(readingList, ref, 2), \
                                factory.retSimilarity(readingList, ref, 3)])

        print factory.classify(scaled)

        yield 'data: %s\n\n' % factory.classify(scaled)

        ser.flushInput()
Пример #3
0
while True:
    readingList = []
    count = 0

    while (count < a.maxVal):
        try:
            (l, r, _) = ser.readline().strip('\x00\r\n').strip().split(',')
            readingList.append((int(l), int(r)))
        except:
            continue

        count += 1

    scaled = factory.scale([factory.retSimilarity(readingList, ref, 1), \
                            factory.retSimilarity(readingList, ref, 2), \
                            factory.retSimilarity(readingList, ref, 3), \
                            factory.retSimilarity(readingList, ref, 4)])

    direction = factory.classify(scaled)
    print direction

    # Write to output serial port which provides input to corresponding wheel.
    if direction == "UP" or direction == "STRAIGHT":
        ser2.write(b'1')
    elif "RIGHT" in direction:
        ser2.write(b'2')
    elif "LEFT" in direction:
        ser2.write(b'3')
    elif direction == "BLINK" or direction == "DOWN":
        ser2.write(b'4')
    while True:
        clock.tick(10)

        readingList = []
        count = 0

        while (count < int(a.maxVal)):
            try:
                arr = ser.readline().strip('\x00\r\n').strip().split(',')
                readingList.append((float(arr[0]), float(arr[1])))
            except:
                continue
            count = count + 1
        # Calculate similarity, scale and classify.
        scaled = factory.scale([factory.retSimilarity(readingList, ref, 1), \
                                factory.retSimilarity(readingList, ref, 2), \
                                factory.retSimilarity(readingList, ref, 3), \
                                factory.retSimilarity(readingList, ref, 4)])
        direction = factory.classify(scaled)

        # Decrease or increase the vertical/horizontal position based on the
        # direction of the eyes.
        if direction == "STRAIGHT":
            pass
        elif direction == "UP" and dirs != 0:
            dirs = 2
        elif direction == "RIGHT" and dirs != 3:
            dirs = 1
        elif direction == "DOWN" and dirs != 2:
            dirs = 0
        elif direction == "LEFT" and dirs != 1:
            dirs = 3