Ejemplo n.º 1
0
def main():
    print('Initializing HAT')
    hat.servo_enable(1, False)
    hat.servo_enable(2, False)
    hat.light_mode(hat.WS2812)
    hat.light_type(hat.GRBW)
    print('Initializing camera')
    with picamera.PiCamera() as camera:
        camera.resolution = (WIDTH, HEIGHT)
        camera.framerate = FRAMERATE
        camera.vflip = VFLIP  # flips image rightside up, as needed
        camera.hflip = HFLIP  # flips image left-right, as needed
        sleep(1)  # camera warm-up time
        print('Initializing websockets server on port %d' % WS_PORT)
        WebSocketWSGIHandler.http_version = '1.1'
        websocket_server = make_server(
            '',
            WS_PORT,
            server_class=WSGIServer,
            handler_class=WebSocketWSGIRequestHandler,
            app=WebSocketWSGIApplication(handler_cls=StreamingWebSocket))
        websocket_server.initialize_websockets_manager()
        websocket_thread = Thread(target=websocket_server.serve_forever)
        print('Initializing HTTP server on port %d' % HTTP_PORT)
        http_server = StreamingHttpServer()
        http_thread = Thread(target=http_server.serve_forever)
        print('Initializing broadcast thread')
        output = BroadcastOutput(camera)
        broadcast_thread = BroadcastThread(output.converter, websocket_server)
        print('Starting recording')
        camera.start_recording(output, 'yuv')
        try:
            print('Starting websockets thread')
            websocket_thread.start()
            print('Starting HTTP server thread')
            http_thread.start()
            print('Starting broadcast thread')
            broadcast_thread.start()
            while True:
                camera.wait_recording(1)
        except KeyboardInterrupt:
            pass
        finally:
            print('Stopping recording')
            camera.stop_recording()
            print('Waiting for broadcast thread to finish')
            broadcast_thread.join()
            print('Shutting down HTTP server')
            http_server.shutdown()
            print('Shutting down websockets server')
            websocket_server.shutdown()
            print('Waiting for HTTP server thread to finish')
            http_thread.join()
            print('Disabling servos')
            hat.servo_enable(1, False)
            hat.servo_enable(2, False)
            hat.clear()
            hat.show()
            print('Waiting for websockets thread to finish')
            websocket_thread.join()
Ejemplo n.º 2
0
def test_lights():
    pantilthat.light_mode(pantilthat.WS2812)
    pantilthat.light_type(pantilthat.GRBW)

    r, g, b, w = 0, 0, 0, 0

    try:
        while True:
            pantilthat.set_all(0, 0, 0, 0)
            pantilthat.show()
            time.sleep(0.5)
            pantilthat.set_all(100, 0, 0, 0)
            pantilthat.show()
            time.sleep(0.5)
            pantilthat.set_all(0, 100, 0, 0)
            pantilthat.show()
            time.sleep(0.5)
            pantilthat.set_all(0, 0, 100, 0)
            pantilthat.show()
            time.sleep(0.5)
            pantilthat.set_all(100, 100, 0, 0)
            pantilthat.show()
            time.sleep(0.5)
            pantilthat.set_all(0, 100, 100, 0)
            pantilthat.show()
            time.sleep(0.5)
            pantilthat.set_all(100, 0, 100, 0)
            pantilthat.show()
            time.sleep(0.5)
            pantilthat.set_all(100, 100, 100, 0)
            time.sleep(0.5)
            pantilthat.show()
    except KeyboardInterrupt:
        pantilthat.clear()
        pantilthat.show()
Ejemplo n.º 3
0
            pth.pan(panAngle)

        # if the tilt angle is within the range, tilt
        if in_range(tiltAngle, servoRange[0]+20, servoRange[1] ):
            pth.tilt(tiltAngle-20)
        time.sleep(0.1)
# check to see if this is the main body of execution
if __name__ == "__main__":
    # construct the argument parser and parse the arguments
    ap = argparse.ArgumentParser()
    ap.add_argument("-m", "--model", type=str, required=True,
        help="path to openvino model for face detection")
    args = vars(ap.parse_args())

    #set up lights:
    pth.light_mode(pth.WS2812)
    pth.light_type(pth.RGB)
    pth.set_all(0,0,255)
    pth.show()
    # start a manager for managing process-safe variables
    with Manager() as manager:
        # enable the servos
        pth.servo_enable(1, True)
        pth.servo_enable(2, True)
 
        # set integer values for the object center (x, y)-coordinates
        centerX = manager.Value("i", 0)
        centerY = manager.Value("i", 0)
 
        # set integer values for the object's (x, y)-coordinates
        objX = manager.Value("i", 0)
Ejemplo n.º 4
0
import colorsys
import picamera
import time
import pantilthat
import datetime
from time import sleep

# Initialise PanTilt Hat
a = 0 # intitial pan position (center)
b = -20 # intitial tilt position (center)
r = 0 # neopixel red off
g = 0 # neopixel green off
b = 0 # neopixel blue off
w = 0 # neopixel white off

pantilthat.light_mode(pantilthat.WS2812)
pantilthat.light_type(pantilthat.GRBW)
pantilthat.pan(a)    
pantilthat.tilt(b)
pantilthat.set_all(r, g, b, w)
pantilthat.show()

# Initialise Camera
camera = picamera.PiCamera()
win_size = (500, 40, 640, 480)
x = 0 # set zoom to zero
y = 0 # set zoom to zero
video = (1920, 1088)
photo = (2592, 1944)
framerate = 30
rotate = 180
Ejemplo n.º 5
0
#!/usr/bin/env python

import math
import time

import pantilthat

pantilthat.light_mode(pantilthat.PWM)

while True:
    b = (math.sin(time.time() * 2) + 1) / 2
    b = int(b * 255.0)
    t = round(time.time() * 1000) / 1000
    a = round(math.sin(t) * 90)
    pantilthat.pan(int(a))
    pantilthat.tilt(int(a))
    pantilthat.brightness(b)
    print(a)
    time.sleep(0.04)
Ejemplo n.º 6
0
 elif (command == 'get_tilt'):
     print(pantilthat.get_tilt());
 elif( command == 'light_type' and len(list)>=2):
     if( list[1] == 'RGB' ):
         pantilthat.light_type(pantilthat.RGB);
     elif( list[1] == 'GRB' ):
         pantilthat.light_type(pantilthat.GRB);
     elif( list[1] == 'RGBW' ):
         pantilthat.light_type(pantilthat.RGBW);
     elif( list[1] == 'GRBW' ):
         pantilthat.light_type(pantilthat.GRBW);
     else:
         print('error: light_type requires parameter RBB, GRB, RGBW or GRBW'); 
 elif( command == 'light_mode' and len(list)>=2):
     if( list[1] == 'PWM' ):
         pantilthat.light_mode(pantilthat.PWM);
     elif( list[1] == 'WS2812' ):
         pantilthat.light_mode(pantilthat.WS2812);
     else:
         print('error: light_mode requires parameter PWM or WS2812'); 
 elif (command == 'brightness' and len(list)>=2):
     pantilthat.brightness(float(list[1]));
 elif( command == 'set_all' and len(list)==4):
         pantilthat.set_all(int(list[1]), int(list[2]), int(list[3]));
 elif( command == 'set_all' and len(list)==5):
         print("setting three colours and white");
         pantilthat.set_all(int(list[1]), int(list[2]), int(list[3]), int(list[4]));
 elif( command == 'set_pixel' and len(list)==5):
         pantilthat.set_pixel(int(list[1]), int(list[2]), int(list[3]), int(list[4]));
 elif( command == 'set_pixel' and len(list)==6):
         pantilthat.set_pixel(int(list[1]), int(list[2]), int(list[3]), int(list[4]), int(list[5]));