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 Ohbot's motor and pupil positions and base colour. ohbot.move(ohbot.HEADTURN, xm) ohbot.move(ohbot.HEADNOD, ym) ohbot.move(ohbot.EYETURN, xm) ohbot.move(ohbot.EYETILT, ym) ohbot.setEyeColour(10 - ym, ym, xm)
def lookatPerson(face_rect, windowSize): window_width, window_height = windowSize[2], windowSize[3] if face_rect is not None: x, w, y, h = face_rect xm, ym = x + w, y + h if not (xm == 0 or ym == 0): xm = xm // (window_width // 10) ym = ym // (window_height // 10) print(xm, ym) ohbot.move(ohbot.HEADTURN, abs(10 - xm) + 1) ohbot.move(ohbot.HEADNOD, abs(10 - ym) + 1) ohbot.move(ohbot.EYETURN, xm) ohbot.move(ohbot.EYETILT, abs(10 - ym) + 1) ohbot.setEyeColour(10 - ym, ym, xm) ohbot.wait(0.1)
def handleInputWiki(): while True: text = input("Define:\n") ohbot.say(text) ohbot.setEyeColour(10,5,0,True) randIndex = randrange(0,len(connectingPhrases)) choice = connectingPhrases[randIndex] ohbot.move(ohbot.HEADTURN,5) ohbot.move(ohbot.EYETILT,7) ohbot.move(ohbot.HEADNOD,9) ohbot.say(choice) try: res = wikipedia.summary(text) ohbot.say(res) ohbot.setEyeColour(0,10,0,True) except: print('Answer not available') ohbot.say("Answer not available") ohbot.setEyeColour(10,0,0,True) ohbot.move(ohbot.HEADTURN,5)
def handleInput(): while True: text = input("Question:\n") ohbot.say(text) ohbot.setEyeColour(10,5,0,True) randIndex = randrange(0,len(connectingPhrases)) choice = connectingPhrases[randIndex] ohbot.move(ohbot.HEADTURN,5) ohbot.move(ohbot.EYETILT,7) ohbot.move(ohbot.HEADNOD,9) ohbot.say(choice) try: res = wolfclient.query(text) ans = next(res.results).text ans = ans.replace("|",".") ohbot.say(ans) ohbot.setEyeColour(0,10,0,True) except: print('Answer not available') ohbot.say("Answer not available") ohbot.setEyeColour(10,0,0,True) ohbot.move(ohbot.HEADTURN,5)
def handleInputWiki(text): if not text == None: ohbot.say("You ask this question to me " + text) ohbot.setEyeColour(10, 5, 0, True) randIndex = randrange(0, len(connectingPhrases)) choice = connectingPhrases[randIndex] ohbot.move(ohbot.HEADTURN, 5) ohbot.move(ohbot.EYETILT, 7) ohbot.move(ohbot.HEADNOD, 9) ohbot.say(choice) try: res = wikipedia.summary(text) ohbot.say(res) ohbot.setEyeColour(0, 10, 0, True) except: print('Answer not available') ohbot.say("Answer not available") ohbot.setEyeColour(10, 0, 0, True) ohbot.move(ohbot.HEADTURN, 5)
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.setEyeColour(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)
def eyeCol(): while True: # Set the base to a random rgb values between 0 and 10. ohbot.setEyeColour(random() * 10, random() * 10, random() * 10) # Wait between 10 and 20 seconds before changing again. ohbot.wait(randint(10, 20))
lastm = "" #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
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) ohbot.setEyeColour(10, 0, 0) for x in range(0, 14): ohbot.move(ohbot.EYETILT, 3) ohbot.wait(x / 100) ohbot.move(ohbot.EYETILT, 6) ohbot.wait(x / 100) # Spring, play on a sepereate thread using untilDone = False.
from ohbot import ohbot import random ohbot.reset() ohbot.wait(0.2) 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):
def cKey(event): ohbot.say("Hello humans", untilDone=False) ohbot.setEyeColour(3, 10, 3)
def bKey(event): ohbot.playSound('spring', untilDone=True) ohbot.say("What is going on ?", untilDone=False) ohbot.setEyeColour(10, 3, 3)
def aKey(event): ohbot.say("Hello I am Ohbot", untilDone=False) ohbot.setEyeColour(3, 3, 10)
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.setEyeColour(x, x, x) ohbot.wait(0.1) ohbot.setEyeColour(0, 0, 0) ohbot.wait(0.2) ohbot.move(1, 5, 1) ohbot.wait(1) ohbot.say("Now I am running in python you know", False) for x in range(0, 10): ohbot.move(3, x) ohbot.setEyeColour(x, 10 - x, x) ohbot.wait(0.3)