# import the ohbot module

from ohbot import ohbot

# Reset Ohbot

ohbot.reset()

# Move turn ohbot's head and eyes. 
ohbot.move(1,2)
ohbot.move(3,1)

# Wait a few seconds for the motors to move

ohbot.wait(2)

# Move head back to the centre and say "Hello World"
ohbot.move(1,5,1)
ohbot.say("Hello World")

# Slowly increase the brightness of the eyes.

for x in range(0,10):

    ohbot.eyeColour(x,x,x)
    ohbot.wait(0.1)

    ohbot.eyeColour(0,0,0)
    ohbot.wait(0.2)

    
Exemple #2
0
                # 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 ohbot to the position of the face detected.
            ohbot.move(ohbot.HEADTURN, 10 - faceX, 10)
            ohbot.move(ohbot.HEADNOD, 10 - faceY, 10)

            # Uncomment this to move the eyes too
            #ohbot.move(ohbot.EYETURN,10-faceX,10)
            #ohbot.move(ohbot.EYETILT,10-faceY,10)

            # Quit on q key
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break
        else:
            print("no frame")

    # When everything is done, release the capture
    video_capture.release()
    cv2.destroyAllWindows()
#!/usr/bin/python3
import sys
from ohbot import ohbot
import time
import os
print("picking this emotion:", sys.argv[1])
first_arg = int(sys.argv[1])

if first_arg==0:
	print("reseting ohbot")
	ohbot.reset()

if first_arg==1:
	print("smiling")

	ohbot.move(ohbot.BOTTOMLIP,8,1)
	time.sleep(1)
	ohbot.move(ohbot.BOTTOMLIP,5,1)

if first_arg==2:
	print("blinking")
	ohbot.move(ohbot.LIDBLINK,4,1)
	time.sleep(0.4)
	ohbot.move(ohbot.LIDBLINK,10,1)

if first_arg==3:
	print("raise eyebrows")
	for i in range(3):
		ohbot.move(ohbot.LIDBLINK,4,5)
		time.sleep(0.2)
		ohbot.move(ohbot.LIDBLINK,9,5)
Exemple #4
0
#this is called on a separate thread to blink the eyes while running
def blinkLids():
    while (blinking):
        ohbot.move(ohbot.LIDBLINK, 0)
        sleep(0.2)
        ohbot.move(ohbot.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
ohbot.reset()
ohbot.setEyeColour(0, 0, 10)
sleep(1.0)
ohbot.setEyeColour(0, 0, 0)
ohbot.move(ohbot.HEADNOD, 0)
ohbot.move(ohbot.LIDBLINK, 0)
sleep(2.0)
#close to turn the motors off
ohbot.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 Ohbot 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
ohbot.reset()
'''
The ohbot.move() function needs at least 2 arguments: movement name and desired position.

ohbot.HEADTURN
ohbot.HEADNOD
ohbot.EYETURN
ohbot.EYETILT
ohbot.BOTTOMLIP
ohbot.LIDBLINK

position can be any number 0-10.

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

# Move the HEADNOD motor to 9.
ohbot.move(ohbot.HEADNOD, 9)
ohbot.say("head nod to 9")
# Move the HEADNOD motor to 5.
ohbot.move(ohbot.HEADNOD, 5)
ohbot.say("head nod to 5")
'''
The ohbot.move() function can also take an optional third arguement 'spd'
to change the speed of the movement. If unspecified speed defaults to 5. 
'''
# Example of how to use the play sound function and change the eye colour of Ohbot.

from ohbot import ohbot
import random

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

ohbot.playSound('fanfare', untilDone=False)
ohbot.wait(1.5)

ohbot.move(ohbot.LIDBLINK, 5)

ohbot.wait(1)

ohbot.move(ohbot.LIDBLINK, 10)
ohbot.wait(4)

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

for x in range(0, 40):
    ohbot.setEyeColour(random.randrange(0, 10), random.randrange(0, 10),
                       random.randrange(0, 10))
    ohbot.wait(0.05)

ohbot.setEyeColour(0, 0, 0)
ohbot.wait(0.5)

ohbot.playSound('smash', untilDone=False)
import random

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

ohbot.reset()

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

ohbot.wait(2)

ohbot.setVoice("Karen")

ohbot.setSpeechSpeed(150)

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

ohbot.say("hello i am Karen")

ohbot.setVoice("Alex")

ohbot.setSpeechSpeed(90)

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

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

ohbot.setVoice("Oliver")

ohbot.move(ohbot.HEADTURN, random.randint(1, 6))
Exemple #8
0
ohbot.say("Commencing hardware tests")

ohbot.say("Eyes to red")
ohbot.setEyeColour(10, 0, 0, True)

ohbot.say("Eyes to green")
ohbot.setEyeColour(0, 10, 0, True)

ohbot.say("Eyes to blue")
ohbot.setEyeColour(0, 0, 10, True)

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

for x in range(0, 10):

    ohbot.move(ohbot.HEADTURN, x)
    ohbot.wait(0.2)

ohbot.move(ohbot.HEADTURN, 5)

ohbot.say("HeadNod motor 0 to 10")

for x in range(0, 10):

    ohbot.move(ohbot.HEADNOD, x)
    ohbot.wait(0.2)

ohbot.move(ohbot.HEADNOD, 5)

ohbot.say("Commencing random movement")
from ohbot import ohbot

## Example program for using sensors with ohbot.
## Tilt sensor - a3
## Light sensor - a4

ohbot.reset()
while True:

    val1 = ohbot.readSensor(4)

    val2 = ohbot.readSensor(3)

    ohbot.eyeColour(val2, 10 - val2, 0, True)
    ohbot.move(ohbot.HEADTURN, val2)
    print(val2)
    if val1 > 2:
        ohbot.say("put me down")

    if val2 < 2:
        ohbot.say("who turned out the lights")

    ohbot.wait(0.1)
Exemple #10
0
def get_steven_to_talk():
    """Run the Ohbot routine
    Returns:
        Boolean True or False depending on whether run successfully or not
    """

    try:
        # Reset Ohbot

        ohbot.reset()

        # Switch the speech synthesizer to epseak
        ohbot.setSynthesizer("espeak")

        # Set the voice to english West Midlands accent medium speed.

        ohbot.setVoice("-ven+f2 -s130")

        # Set eyes to red
        ohbot.eyeColour(10, 0, 0)

        ohbot.wait(0.5)

        # Say something
        ohbot.say("Good Evening", True, False, False, 0)
        ohbot.wait(0.5)
        #ohbot.say("Who have we got here",True, False, False,0)
        #ohbot.wait(0.5)
        ohbot.say("I'm the late great Mary Webb ", True, False, False, 0)
        ohbot.wait(0.5)
        ohbot.say("I love children ", True, False, False, 0)
        ohbot.wait(0.5)
        ohbot.say("For supper", True, False, False, 0)
        ohbot.wait(0.5)
        #ohbot.say("Woooahhhh woooahhha",True, False, False,0)
        #ohbot.wait(0.5)
        # Wait a few seconds for the motors to move

        ohbot.wait(2)

        # Move head left to right
        ohbot.move(ohbot.HEADTURN, 4, 1)
        ohbot.wait(0.5)
        ohbot.move(ohbot.HEADTURN, 6, 1)
        ohbot.wait(0.5)
        ohbot.move(ohbot.HEADTURN, 5, 1)
        ohbot.wait(0.5)
        ohbot.eyeColour(0, 10, 0)
        ohbot.wait(0.5)
        ohbot.move(ohbot.HEADNOD, 7, 1)
        ohbot.wait(0.5)
        ohbot.move(ohbot.HEADNOD, 1, 1)
        ohbot.wait(0.5)
        ohbot.move(ohbot.EYETURN, 9, 1)
        ohbot.wait(0.5)
        ohbot.move(ohbot.EYETURN, 1, 1)
        ohbot.wait(0.5)
        ohbot.move(ohbot.EYETURN, 5, 1)
        ohbot.wait(0.5)
        ohbot.say("Take one sweet.", True, False, False, 0)
        ohbot.wait(0.5)
        ohbot.say("At your own risk", True, False, False, 0)
        ohbot.wait(0.5)
        ohbot.say("Don't forget to brush your teeth", True, False, False, 0)
        ohbot.wait(0.5)
        ohbot.say("Happy Halloween", True, False, False, 0)
        ohbot.wait(0.5)
        ohbot.reset()
        # close ohbot at the end.
        ohbot.wait(0.5)
        ohbot.close()
        ohbot.wait(0.5)
        return True
    except:
        return False
Exemple #11
0
def doLips():
    ohbot.wait(0.05)
    ohbot.move(4, 5)
    ohbot.move(5, 5)
    ohbot.wait(0.5861804837892748)
    ohbot.move(4, 5)
    ohbot.move(5, 5)
    ohbot.wait(0.07375042173905144)
    ohbot.move(4, 9)
    ohbot.move(5, 9)
    ohbot.wait(0.4978153467385975)
    ohbot.move(4, 5)
    ohbot.move(5, 5)
    ohbot.wait(0.07835982309774225)
    ohbot.move(4, 9)
    ohbot.move(5, 9)
    ohbot.wait(0.5992221766297934)
    ohbot.move(4, 5)
    ohbot.move(5, 5)
    ohbot.wait(0.19820425842370093)
    ohbot.move(4, 9)
    ohbot.move(5, 9)
    ohbot.wait(2.456810924182153)
    ohbot.move(4, 5)
    ohbot.move(5, 5)
    ohbot.wait(0.6414933000935639)
Exemple #12
0
def moveLoop():
    while True:
        ohbot.move(randint(0, 2), randint(0, 9))

        ohbot.wait(randint(0, 3))
Exemple #13
0
def head_tracking_move():

    detlatX = 0
    detlatY = 0
    faceArea = 0
    f = open('/home/gal/toibot_ws/src/ToiBot1/src/motors/headTracking.txt',
             'r')
    out = f.readlines()
    count = 0
    for line in out:
        if count == 0:
            detlatX = int(line)
        if count == 1:
            detlatY = int(line)
        if count == 2:
            faceArea = int(line)
        count = count + 1

    #print(str(detlatX) +', '+ str(detlatY) )

    f.close()

    global currentStateX
    global currentStateY

    print('faceArea' + str(faceArea))
    if faceArea > 20000:
        threshold = 150
    elif faceArea > 10000:
        threshold = 100
    else:
        threshold = 75

    waiting = 2

    if detlatX == 100000:
        print('init ')
        ohbot.move(1, 5, 1)
        currentStateX = 5
    elif abs(detlatX) < threshold:
        print('dont move ')
    elif detlatX > threshold:
        print('my right ' + str(currentStateX))
        currentStateX = currentStateX + 1
        ohbot.move(1, currentStateX, 1)
    elif detlatX < -threshold:
        currentStateX = currentStateX - 1
        ohbot.move(1, currentStateX, 1)

    if detlatY == 100000 or abs(detlatY) < threshold:
        #print('dont move')
        ohbot.move(0, 5, 1)
        currentStateY = 5
        ohbot.wait(waiting)
    elif detlatY > threshold:
        currentStateY = currentStateY + 1
        ohbot.move(0, currentStateY, 1)
        ohbot.wait(waiting)
    elif detlatY < -threshold:
        currentStateY = currentStateY - 1
        ohbot.move(0, currentStateY, 1)
        ohbot.wait(waiting)

    ohbot.move(3, 8, 1)
    ohbot.wait(2)
    ohbot.move(3, 2, 1)
Exemple #14
0
ohbot.eyeColour(0, 0, 10)
sleep(1.0)
ohbot.eyeColour(0, 0, 0)

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

sleep(2.0)

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

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

# Set the voice to English female medium speed.

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

# Set the voice to French female.

ohbot.setVoice("-vfr+f2")
ohbot.say("bonjour")