Пример #1
0
def blinkLids():
    while (blinking):
        picoh.move(picoh.LIDBLINK, 0)
        sleep(0.2)
        picoh.move(picoh.LIDBLINK, 10)
        # wait for a random amount of time for realistic blinking
        sleep(randint(0, 4))
Пример #2
0
def randomTurn():
    global moving
    while True:
        if moving:
            # Move Picoh's HEADTURN motor to a random position between 3 and 7.
            picoh.move(picoh.HEADTURN, randint(3, 7))

            # wait for a random amount of time before moving again. 
            picoh.wait(random() * 4)
Пример #3
0
def randomNod():
    global moving
    while True:
        if moving:

            # Move Picoh's HEADNOD motor to a random position between 4 and 7.
            picoh.move(picoh.HEADNOD, randint(4, 7))

            # wait for a random amount of time before moving again. 
            picoh.wait(random() * 4)
Пример #4
0
def randomLook():
    global moving 
    while True:
        # if moving is True. 
        if moving:
            # Look in a random direction.
            picoh.move(picoh.EYETILT, randint(2, 8))
            picoh.move(picoh.EYETURN, randint(2, 8))

            # Wait for between 0 and 5 seconds. 
            picoh.wait(random() * 5)
Пример #5
0
def blinkLids():
    global blinking
    
    # While True - Loop forever.
    while True:
        # if blinking is True.
        if blinking:
            # for the numbers 10 to 0 set the lidblink position. 
            for x in range(10, 0, -1):
                picoh.move(picoh.LIDBLINK,x)
                picoh.wait(0.01)
                
            # for the numbers 0 to 10 set the lidblink position.
            for x in range(0, 10):
                picoh.move(picoh.LIDBLINK,x)
                picoh.wait(0.01)

            # wait for a random amount of time for realistic blinking
            picoh.wait(random() * 6)
Пример #6
0
def message_listener(client):
    global RECEIVED_MESSAGES
    pythoncom.CoInitialize()  #fix to Picoh speech issue

    while True:
        message = client.receive_message()
        RECEIVED_MESSAGES += 1
        print("Message received")
        # print( "    Data: «{}»".format(message.data) )
        # print( "    Properties: {}".format(message.custom_properties))
        # print( "    Total calls received: {}".format(RECEIVED_MESSAGES))
        print(message.data.decode('utf-8'))

        picoh.say(message.data.decode('utf-8'))
        picoh.setEyeShape("Heart")
        picoh.move(picoh.HEADTURN, randint(3, 7))
        picoh.move(picoh.HEADNOD, randint(4, 7))
        picoh.baseColour(random() * 10, random() * 10, random() * 10)
        picoh.wait(1)
        picoh.setEyeShape("Eyeball")
Пример #7
0
def xy(event):
    # Get the coordinates of where the mouse movement happened. 
    xm, ym = event.x, event.y

    # Scale the coordniate so it is between 0-10. Divide by 60 as window is 600 x 600. 
    xm = xm/60
    ym = ym/60

    # Use the scaled position to set Picoh's motor and pupil positions and base colour. 
    picoh.move(picoh.HEADTURN,xm)
    picoh.move(picoh.HEADNOD,ym)
    picoh.move(picoh.EYETURN,xm)
    picoh.move(picoh.EYETILT,ym)
    picoh.setBaseColour(10-ym,ym,xm)
Пример #8
0
def handleInput():
    global moving
    while True:

        picoh.say("Hello picoh here, what shall I look up on wolfram alpha?")

        text = input("Question:\n")
        picoh.say(text)
        picoh.setBaseColour(10, 5, 0)

        # Stop the random movement.
        moving = False

        # Look forward and up.
        picoh.move(picoh.HEADTURN, 5)
        picoh.move(picoh.EYETILT, 7)
        picoh.move(picoh.HEADNOD, 9)

        # get a random phrase from set 2 in the speech database.
        picoh.say(picoh.getPhrase(set=2))

        # Try the call to a webservice to get a response from WolframAlpha.
        try:
            # Start random movement again
            moving = True
            res = wolfclient.query(text)
            ans = next(res.results).text

            # replace response text | with .
            ans = ans.replace("|", ".")
            picoh.say(ans)

            # set base to green.
            picoh.setBaseColour(0, 10, 0)

        # If no answer can be found then say answer not available and set base to red.
        except:
            print('Answer not available')
            picoh.say("Answer not available")
            picoh.setBaseColour(10, 0, 0)

        picoh.move(picoh.HEADTURN, 5)
Пример #9
0
def handleInputWiki():
    global moving
    while True:

        picoh.say(
            "Hello picoh here, what would you like the wiki definition for?")

        # Put up a text box and wait for user to type the word they want to define.
        text = input("Define:\n")

        # Say the word they have typed.
        picoh.say(text)
        picoh.setBaseColour(10, 5, 0)

        # Stop the random movement
        moving = False

        # Look forward and up.
        picoh.move(picoh.HEADTURN, 5)
        picoh.move(picoh.EYETILT, 7)
        picoh.move(picoh.HEADNOD, 9)

        # get a random phrase from set 2 in the speech database.
        picoh.say(picoh.getPhrase(set=2))

        # Try the call to a webservice to get a response from Wikipedia.
        # Request the first sentence of the definition.
        try:
            # Start random movement again
            moving = True
            res = wikipedia.summary(text, sentences=1)
            picoh.say(res)
            picoh.setBaseColour(0, 10, 0)

        except:
            # If no answer can be found then say answer not available and set base to red.
            print('Answer not available')
            picoh.say("Answer not available")
            picoh.setBaseColour(10, 0, 0)
            picoh.move(picoh.HEADTURN, 5)
Пример #10
0
def sel():
    global button, stage, lipMaxRaw, lipMinRaw

    if stage == 2:
        root.destroy()

        picoh.reset()

        picoh.wait(1)

        picoh.close()

        sys.exit()

    if stage == 1:
        ResetRangeToRawMin()
        label.config(text="All done!")
        stage = 2
        button.config(text="Close")

    if stage == 0:
        selection = "Value = " + str(var.get())
        label.config(
            text=
            "Slowly move the slider to the right, stop when the bottom lip pops the top lip into a smile."
        )

        button.config(text="Set Smile Point")

        ResetRangeToRawCentre()
        stage = 1

        # Set headnod to 5
        picoh.move(picoh.HEADNOD, 10)
        # Move bottom lip to 4
        picoh.move(picoh.BOTTOMLIP, 4)

        # Wait 250ms
        picoh.wait(0.25)

        # Move bottom lip to 6
        picoh.move(picoh.BOTTOMLIP, 6)
Пример #11
0
picoh.wait(0.2)

picoh.say("Commencing hardware tests")

picoh.say("Base to red")
picoh.setBaseColour(10, 0, 0)

picoh.say("Base to green")
picoh.setBaseColour(0, 10, 0)

picoh.say("Base to blue")
picoh.setBaseColour(0, 0, 10)

picoh.say("Matrix off")
picoh.move(picoh.LIDBLINK, 0)
picoh.setEyeShape("Full")

picoh.say("Matrix on")
picoh.move(picoh.LIDBLINK, 10)

picoh.say("Eyes to angry")
picoh.setEyeShape("Angry")

picoh.say("Reset Eyes")
picoh.setEyeShape("Eyeball")

picoh.say("HeadTurn motor 0 to 10")

for x in range(0, 10):
Пример #12
0
from picoh import picoh

picoh._revertMotorDefsFile()

import tkinter as Tk

from lxml import etree

global button, stage, lipMinRaw, lipMaxRaw, tempMin, tempMax
import sys

stage = 0

picoh.move(picoh.HEADNOD, 8)

# Move bottom lip to 4
picoh.move(picoh.BOTTOMLIP, 4)

# Wait 250ms
picoh.wait(0.25)

# Move bottom lip to 8
picoh.move(picoh.BOTTOMLIP, 8)

# Get min and max positions.
lipMinRaw = picoh.motorMins[picoh.BOTTOMLIP]
lipMaxRaw = picoh.motorMaxs[picoh.BOTTOMLIP]
lipRange = lipMaxRaw - lipMinRaw

# Extend Ranges
Пример #13
0
import random

# Run 'say -v?' in Terminal to list options for voices. speechSpeed is 90 +.

picoh.reset()

picoh.say("Hi it is great to be here, i am finally running on a mac, wow")

picoh.wait(2)

picoh.setVoice("Karen")

picoh.setSpeechSpeed(150)

picoh.move(picoh.HEADTURN, random.randint(3, 6))

picoh.say("hello i am Karen")

picoh.setVoice("Alex")

picoh.setSpeechSpeed(90)

picoh.move(picoh.HEADTURN, random.randint(2, 6))

picoh.say("hello i am Alex slow")

picoh.setVoice("Oliver")

picoh.move(picoh.HEADTURN, random.randint(1, 6))
Пример #14
0
# this is called on a separate thread to blink the eyes while running
def blinkLids():
    while (blinking):
        picoh.move(picoh.LIDBLINK, 0)
        sleep(0.2)
        picoh.move(picoh.LIDBLINK, 10)
        # wait for a random amount of time for realistic blinking
        sleep(randint(0, 4))


# start up sequence resets to mid position, sets the eyes to blue then goes to sleep
picoh.reset()
picoh.baseColour(0, 0, 10)
sleep(1.0)
picoh.baseColour(0, 0, 0)
picoh.move(picoh.HEADNOD, 0)
picoh.move(picoh.LIDBLINK, 0)
sleep(2.0)
# close to turn the motors off
picoh.close()

while (True):
    # get seconds and minutes into strings
    s = strftime("%S", localtime())
    m = strftime("%M", localtime())
    # set this to False for testing to make picoh speak continuously
    everyQuarterHour = True
    if ((everyQuarterHour == False) or
        ((everyQuarterHour == True) and
         (m == "00" or m == "15" or m == "30" or m == "45") and m != lastm)):
        lastm = m
Пример #15
0
picoh.reset()
'''
The picoh.move() function needs at least 2 arguments: movement name and desired position.

picoh.HEADTURN
picoh.HEADNOD
picoh.EYETURN
picoh.EYETILT
picoh.BOTTOMLIP
picoh.LIDBLINK

position can be any number 0-10.

'''
# Move the HEADTURN motor to 2.
picoh.move(picoh.HEADTURN, 2)
picoh.say("head turn to 2")
# Move the HEADTURN motor to 5.
picoh.move(picoh.HEADTURN, 5)
picoh.say("head turn to 5")

# Move the HEADNOD motor to 9.
picoh.move(picoh.HEADNOD, 9)
picoh.say("head nod to 9")
# Move the HEADNOD motor to 5.
picoh.move(picoh.HEADNOD, 5)
picoh.say("head nod to 5")
'''
The picoh.move() function can also take an optional third arguement 'spd'
to change the speed of the movement. If unspecified speed defaults to 5. 
'''
Пример #16
0
# Example of how to use the play sound function and change the base colour of Picoh.

from picoh import picoh
import random

picoh.reset()
picoh.wait(1)
picoh.close()
picoh.move(picoh.LIDBLINK, 0)

picoh.setEyeShape('Heart')
picoh.setEyeBrightness(0)
picoh.playSound('fanfare', untilDone=False)
picoh.wait(1.5)

picoh.move(picoh.LIDBLINK, 5)
picoh.setEyeBrightness(5)

picoh.wait(1)

picoh.move(picoh.LIDBLINK, 10)
picoh.setEyeBrightness(10)
picoh.wait(2)
picoh.setEyeBrightness(7)
picoh.wait(4)

picoh.playSound('ohbot', untilDone=False)

picoh.setEyeShape('Glasses')
for x in range(0, 40):
    picoh.setBaseColour(random.randrange(0, 10), random.randrange(0, 10),
Пример #17
0
picoh.baseColour(0, 0, 10)
sleep(1.0)
picoh.baseColour(0, 0, 0)

# Start a thread for the blinking.
blinking = True
t = threading.Thread(target=blinkLids, args=())
t.start()

sleep(2.0)

picoh.say(
    "The picoh pi library now supports e speak meaning i can speak different languages and in different voices"
)

picoh.move(picoh.HEADTURN, 4)
picoh.wait(0.2)
picoh.move(picoh.HEADTURN, 6)
picoh.wait(0.2)

# Set the voice to English female medium speed.

picoh.setVoice("-ven+f2 -s150")
picoh.baseColour(3, 10, 2)
picoh.say("you can even change voice mid program")

# Set the voice to French female.

picoh.setVoice("-vfr+f2")
picoh.say("bonjour")
Пример #18
0
from picoh import picoh
# Reset picoh's motors and wait a second for them to move to rest positions.
picoh.reset()
picoh.wait(1)

# Set Picoh's eye shape.
picoh.setEyeShape("Eyeball")

# Say a phrase.
picoh.say("Hello my name is Picoh. Good to meet you")

# Move the HEADTURN and EYETURN to position 3.
picoh.move(picoh.HEADTURN, 3)
picoh.move(picoh.EYETURN, 3)

picoh.wait(1)

# Move the HEADTURN and EYETURN to position 7.
picoh.move(picoh.HEADTURN, 7)
picoh.move(picoh.EYETURN, 7)

# Set the base to red:3/10 green: 4/10 and blue 2/10.
picoh.setBaseColour(3, 4, 2)

picoh.wait(1)

# Change the base to orange
picoh.setBaseColour(10, 3, 0)

# Set the eyeshape to SunGlasses
picoh.setEyeShape("SunGlasses")
Пример #19
0
    # For each face detected.
    for (x, y, w, h) in faces:

        # Draw a rectangle around the face.
        cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)

        # Work out the size of the face.
        faceSize = int((w + h) / 2)

        # Scale the x and y position of the face so that it is between 0 - 10.
        faceX = (x + (w / 2)) / width * 10
        faceY = (y + (h / 2)) / height * 10

    # Display the resulting frame
    cv2.imshow('Video', frame)

    # Move picoh to the position of the face detected.
    picoh.move(picoh.HEADTURN, 10 - faceX, 10)
    picoh.move(picoh.HEADNOD, 10 - faceY, 10)

    picoh.move(picoh.EYETURN, 10 - faceX, 10)
    picoh.move(picoh.EYETILT, 10 - faceY, 10)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()