Esempio n. 1
0
def main():
    create_library.make_functions_for_the_create_robot()
    create_library.connect_to_arduino()
    time.sleep(1.0)
    while True:
        if create_library.read_chr() == 's':
            break
    create_library.start() 
    create_library.full()

    drone = bebop.Bebop(8080, True)
    drone._send_string('send_to_drone_true')

    pixy.pixy_init()

    #drone.connect()
    #drone.takeoff()
    start_logging()

    time.sleep(1)
    #drone.move_seconds('forward', 10, 2)
    create_library.drive_direct(50, 50) 
    desired = CENTER
    pid_loop(drone, CENTER, BLOCKS)

    drone.land()
    drone.disconnect()
Esempio n. 2
0
 def render(self,lisenPort,mocapClientIP,pluginClientIP):
     
     from pixy import BlockArray,pixy_init
     if self._serverThred:
         self._serverThred.render(lisenPort,mocapClientIP,pluginClientIP)
               
     ###
     # Initialize Pixy Interpreter thread #
     pixy_init()
     self.blocks = BlockArray(100)
     self.start()
Esempio n. 3
0
 def __init__(self):
     if not pixy.pixy_init() == 0:
         print("Error opening camera")
     pixy.pixy_cam_set_auto_white_balance(10)
     pixy.pixy_cam_set_auto_exposure_compensation(100)
     self._hog = cv2.HOGDescriptor()
     self._hog.setSVMDetector(cv2.HOGDescriptor_getDefaultPeopleDetector())
Esempio n. 4
0
def main():
    print("Pixy Python " + VERSION)

    # Create directory to save images
    if not os.path.exists(IMAGES_DIR):
        os.mkdir(IMAGES_DIR)

    # Create a directory for this session
    image_dir = IMAGES_DIR + "/" + str(
        datetime.now().strftime("%Y%m%d_%H%M%S"))
    os.mkdir(image_dir)
    print("Saving images to " + image_dir)
    print("Press Q to quit.")

    pixy.pixy_init()  # Initialize Pixy interface
    pixy.pixy_command("stop")  # Stop default program

    # Allocate memory to store image from camera
    data = pixy.byteArray(SUB_WIDTH * SUB_HEIGHT)

    # Allocate numpy matrix to display
    frame = np.zeros((FRAME_HEIGHT, FRAME_WIDTH, 1), dtype=np.uint8)
    frame_cnt = 0

    while True:
        get_subframe(data, frame, 0, 0)
        get_subframe(data, frame, 320, 0)
        get_subframe(data, frame, 0, 200)
        get_subframe(data, frame, 320, 200)

        # Show image
        cv2.imshow('pixy', frame)

        # Save image to file. Use bitmap format because it's lossless and easy to read back/analyze.
        if frame_cnt < MAX_SAVED_IMAGES_COUNT:
            cv2.imwrite(image_dir + '/{:06d}.bmp'.format(frame_cnt), frame)
        frame_cnt = frame_cnt + 1

        # Check user request to exit
        if cv2.waitKey(1) == ord('q'):
            break

        # Sleep 20ms. Camera can only sample at 50fps max.
        time.sleep(.02)

    cv2.destroyAllWindows()
    pixy.pixy_close()
Esempio n. 5
0
def main(ecv):
    pixy.pixy_init()
    pixy.pixy_command("stop")

    # Get current exposure values
    print("Current exposure setting:")
    print_exposure()

    # Set exposure value
    gain = ecv & 0xFF
    comp = (ecv >> 8) & 0xFFFF
    pixy.pixy_cam_set_exposure_compensation(gain, comp)

    # Confirm exposure value
    print("")
    print("Exposure set to:")
    print_exposure()

    # Close connection
    pixy.pixy_close()
Esempio n. 6
0
def setup():
    """
    One time setup. Inialize pixy and set sigint handler
    """
    global blocks
    pixy_init_status = pixy.pixy_init()
    if pixy_init_status != 0:
        print 'Error: pixy_init() [%d] ' % pixy_init_status
        pixy.pixy_error(pixy_init_status)
        return
    else:
        print "Pixy setup OK"
    blocks = pixy.BlockArray(BLOCK_BUFFER_SIZE)
    signal.signal(signal.SIGINT, handle_SIGINT)
Esempio n. 7
0
def pid(desired_point, kP=0):
    '''
    :type desired_point: Point
    :type kP: float
    '''


    pixy.pixy_init()

    while True:
        block = get_block()
        actual_point = Point(block[0].x, block[0].y)

        x_error = desired_point.x - actual_point.x
        direction = 'right'
        if x_error < 0:
            direction = 'left'

        x_speed = math.floor(x_error * kP * 30)
        print ('D: ', desired_point.x, desired_point.y)
        print ('A: ', actual_point.x, actual_point.y)
        print(direction, x_speed)
        time.sleep(.5)
        round
Esempio n. 8
0
def setup():
    """
    One time setup. Inialize pixy and set sigint handler
    """
    pixy_init_status = pixy.pixy_init()
    if pixy_init_status != 0:
        print 'Error: pixy_init() [%d] ' % pixy_init_status
        pixy.pixy_error(pixy_init_status)
        return
    else:
        print "Pixy setup OK"
    signal.signal(signal.SIGINT, handle_SIGINT)
    pixy.pixy_cam_set_brightness(BRIGHTNESS)
    pixy.pixy_rcs_set_position(PIXY_RCS_PAN_CHANNEL, PIXY_RCS_CENTER_POS)

    if chatty:
        sayNow("I may not be the fastest but I have style")
        #say("SLEEP 2")
        time.sleep(2)
Esempio n. 9
0
def setup():
        global blocks
	# Serial.begin(9600)
	pixy_init_status = pixy.pixy_init()
	if pixy_init_status != 0:
                print 'Error: pixy_init() [%d] ' % pixy_init_status
                pixy_error(pixy_init_status)
                return
        else:
                print "Pixy setup OK"
	rr.set_motors(0, 0, 0, 0)
	blocks = pixy.BlockArray(BLOCK_BUFFER_SIZE)
	signal.signal(signal.SIGINT, handle_SIGINT)
	rr.set_led1(1)
	time.sleep(0.1)
	rr.set_led1(0)
	rr.set_led2(1)
	time.sleep(0.1)
	rr.set_led2(0)
Esempio n. 10
0
def initialize_pixy():
    pixy.pixy_init()
    return True
Esempio n. 11
0
XSHAPE.append(CENTER[0])
XSHAPE.append(V2[0])

YSHAPE.append(V1[1])
YSHAPE.append(CENTER[1])
YSHAPE.append(V2[1])

# Draw count variable
holdCount = 0

# Set servo channels
servo1 = 0
servo2 = 15

# Initialize Pixy Interpreter thread
pixy.pixy_init()
blocks = pixy.Block()

# Initialize the PWM device using the default address
pwm = PWM(0x40)

# Uncomment for debugging mode
# pwm = PWM(0x40, debug = True)

# Define suitable pulse ranges
servo1Min = 10.0
servo1Max = 600.0
servo2Max = 600.0
servo2Min = 10.0

# Set open loop pulses
Esempio n. 12
0
            amount_received = 0
            dataBuffer = ""
            while amount_received < amount_expected:
                
                dataBuffer = dataBuffer + connection.recv(amount_expected - amount_received)
                amount_received += len(dataBuffer)
                
                if amount_received == amount_expected:
                    unpacked_data = unpacker.unpack_from(dataBuffer, 0)
                    queue.put(unpacked_data[0])
                    # dont know if this is needed
                    queue.task_done()

###
# Initialize Pixy Interpreter thread #
pixy_init()
blocks = BlockArray(100)
frame = 0
##
# inisilise clasification
clasification = dict()
clasifiedTag = 0
maxPoints = 20
pointDataSize = 6

MOCAP_CLASSIFY_DATA = 2222
server_cmd = 1001

###
# Setup data stream
CMD_PASS = 1001
from ctypes import *
from PiStorms import PiStorms
from mindsensors_i2c import mindsensors_i2c
from mindsensors import ABSIMU
psm = PiStorms()
absimu = ABSIMU()


#print screen
def p(row, text):
    psm.screen.termPrintAt(row, text)


blockSize = 20  # Correct number

pixy_init()


class Finder(object):
    def __init__(self, driver, SubsumptionPixy, grabber):
        self.driver = driver
        self.SubsumptionPixy = SubsumptionPixy
        self.grabber = grabber

        self.blockFound = False

    def turn(self):
        data = self.SubsumptionPixy.findBlocks()

        for block in data:
            # print "X: " + str(block.x)