Ejemplo n.º 1
0
 def __init__(self):
     self.__x = 0
     self.__y = 0
     self.__z = 0
     self.__direction = DIR_POS_X
     self.__current_frame = 0
     self.__cs = cubestate.CubeState('/dev/cu.SLAB_USBtoUART', exp_time=1)
Ejemplo n.º 2
0
        cs.update(coords=pattern)
        cs.send()
        pattern = shift_pattern_down(pattern)
        pattern.extend(gen_random_top_z())
        sleep(delay)


def gen_random_top_z():
    pattern = []
    for i in range(4):
        new_coord = (randint(0, 3), randint(0, 3), 3)
        while new_coord in pattern:
            new_coord = (randint(0, 3), randint(0, 3), 3)
        pattern.append(new_coord)
    return pattern


def shift_pattern_down(pattern):
    shifted_pattern = []
    for coord in pattern:
        x, y, z = coord
        z -= 1
        if z >= 0:
            shifted_pattern.append((x, y, z))
    return shifted_pattern


if __name__ == '__main__':
    cs = cubestate.CubeState('/dev/cu.SLAB_USBtoUART', exp_time=-1)
    run(cs, .15)
Ejemplo n.º 3
0
import cubestate
import serial
import numpy as np
from random import randint
from time import sleep
DELAY = .01
cs = cubestate.CubeState(DELAY, '/dev/cu.SLAB_USBtoUART')

runs = 0
while True:
    if (runs % 4 == 0):
        x = randint(0, 3)
        y = randint(0, 3)
        z = 3

    cs.update(x, y, z)
    cs.send()

    x += 1
    y += 1
    z += 1

    x = x % 4
    y = y % 4
    z = z % 4
    sleep(DELAY)
    runs += 1
Ejemplo n.º 4
0
import cubestate
import serial
import numpy as np
from time import sleep
cs = cubestate.CubeState(1, '/dev/ttyUSB1')

leds = []

for x in range(0, 4):
    for y in range(0, 4):
        for z in range(0, 4):
            leds.append((x, y, z))
while True:
    cs.update(pos_list=leds)
    print(cs.send())
    input()
Ejemplo n.º 5
0
        while True:
            ret,frame = cap.read()
            frame = cv2.flip(frame, 1)#horizontal flip

            hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

            #apply threshold
            green_mask = cv2.inRange(hsv, lower_green, upper_green)
            
            green_box = bounding_box_for_largest_cnt(frame, green_mask, True)
           
            if green_box is not False:
                cv2.drawContours(frame, [green_box], 0, (0, 0, 255), 1)
                cs.update(coords=z(get_z()))
                cs.send()
    
            #figure out bounding box and draw on frame
            cv2.imshow('frame', frame)

            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
            sleep(delay)
    except KeyboardInterrupt:
        pass
    cap.release()
    cv2.destroyAllWindows()

if __name__ == "__main__":
    cs = cubestate.CubeState("/dev/ttyUSB0", exp_time=-1)
    run(cs, .033)
Ejemplo n.º 6
0
import cubestate
import raindrop
import corner
import vision

PRINTER = 1
VISION = 2
CORNER_PATTERN = 3
RAINDROP_PATTERN = 4
QUIT = 5

cs = cubestate.CubeState('/dev/ttyUSB0', exp_time=-1)

def loop():
    while True:
        choice = menu()

        if choice == PRINTER:
            while True:
                try:
                    cs.printf(input("enter string (^C to quit): "), .4)
                except KeyboardInterrupt:
                    break
        elif choice == VISION:
            vision.run(cs, .03)

        elif choice == CORNER_PATTERN:
            try:
                corner.run(cs)
            except KeyboardInterrupt:
                pass