コード例 #1
0
def main(argv):
    ohbot.reset()
    ohbot.move(2, 7, 1)  # eyes
    ohbot.wait(0.5)

    while 1:
        head_tracking_move()
コード例 #2
0
def moveLoop():

    while True:

        ohbot.move(randint(0, 2), randint(0, 9))

        ohbot.wait(randint(0, 3))
コード例 #3
0
def randomTurn():
    global moving
    while True:
        if moving:
            # Move Ohbot's HEADTURN motor to a random position between 3 and 7.
            ohbot.move(ohbot.HEADTURN, randint(3, 7))

            # wait for a random amount of time before moving again.
            ohbot.wait(random() * 4)
コード例 #4
0
def randomNod():
    global moving
    while True:
        if moving:
            # Move Ohbot's HEADNOD motor to a random position between 4 and 7.
            ohbot.move(ohbot.HEADNOD, randint(4, 7))

            # wait for a random amount of time before moving again.
            ohbot.wait(random() * 4)
コード例 #5
0
def blinking():
    while True:
        ohbot.move(ohbot.LIDBLINK, 0, 10)

        ohbot.wait(random() / 3)

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

        ohbot.wait(randint(0, 6))
コード例 #6
0
def randomLook():
    global moving
    while True:
        # if moving is True.
        if moving:
            # Look in a random direction.
            ohbot.move(ohbot.EYETILT, randint(2, 8))
            ohbot.move(ohbot.EYETURN, randint(2, 8))

            # Wait for between 0 and 5 seconds.
            ohbot.wait(random() * 5)
コード例 #7
0
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)
コード例 #8
0
def doEmo():
    ohbot.wait(1.2543763625714643)
    ohbot.move(2, 2, 9)
    ohbot.wait(1.2543763625714643)
    ohbot.move(2, 5, 9)
    ohbot.wait(1.4261171080663775)
    ohbot.move(2, 6, 1)
    ohbot.wait(1.4261171080663775)
    ohbot.move(2, 5, 1)
コード例 #9
0
ファイル: lipsSpeak.py プロジェクト: GalMoore/ToiBot1
def speak():

    sentence = ""

    f = open('/home/gal/toibot_ws/src/ToiBot1/src/motors/lips_speak.txt', 'r')
    out = f.readlines()
    count = 0
    for line in out:
        if count == 0:
            sentence = str(line)

    f.close()

    print(str(sentence))

    words = sentence.split()
    while i < len(words):
        ohbot.move(4, 7, 1)  # TOPLIP
        ohbot.wait(0.5)
        ohbot.move(4, 2, 1)  # TOPLIP
コード例 #10
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):
                ohbot.move(ohbot.LIDBLINK, x)
                ohbot.wait(0.01)

            # for the numbers 0 to 10 set the lidblink position.
            for x in range(0, 10):
                ohbot.move(ohbot.LIDBLINK, x)
                ohbot.wait(0.01)

            # wait for a random amount of time for realistic blinking
            ohbot.wait(random() * 6)
コード例 #11
0
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")

# Set the voice to Spanish female.
コード例 #12
0
# 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)

    
コード例 #13
0
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)
コード例 #14
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)
コード例 #15
0
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. 
'''

# Move HEADTURN motor to position 0 at speed 1.
ohbot.move(ohbot.HEADTURN, 0, spd=1)
ohbot.say("Head turn to 0, speed 1")

# Wait for motor to move
ohbot.wait(2)

# Move HEADTURN motor to position 10 at speed 1.
ohbot.move(ohbot.HEADTURN, 10, spd=1)
ohbot.say("Head turn to 10, speed 1")

# Wait for motor to move
ohbot.wait(1)

# Move HEADTURN motor to position 0 at speed 10.
ohbot.move(ohbot.HEADTURN, 0, spd=10)
ohbot.say("Head turn to 0, speed 10")

# Wait for motor to move
ohbot.wait(0.5)
コード例 #16
0
def on_closing():
    ohbot.reset()
    ohbot.wait(1)
    ohbot.close()
    win.destroy()
コード例 #17
0
ohbot.setVoice("-r-4")
ohbot.say("Do you wanna ride? See yourself going by.")
# American
ohbot.setVoice("-vzira")
ohbot.say("The other side of the sky.")
# Default voice
ohbot.setVoice("")
ohbot.say("I got a silver machine.")

# Switch to espeak-ng - some of the voice attributes aren't supported
ohbot.setSynthesizer("espeak-ng")

# Female Portugese loud
ohbot.setVoice("-vpt+m1 -a200")
ohbot.say("I got a silver machine.")
ohbot.wait(1)
# Male US
ohbot.setVoice("-ven-us+m2")
ohbot.say("I got a silver machine.")
ohbot.wait(1)
# Female Spanish high pitch
ohbot.setVoice("-ves-la+f3 -p90")
ohbot.say("I got a silver machine.")
ohbot.wait(1)
# Male Chinese speed fast
ohbot.setVoice("-vzh+m2 -s260")
ohbot.say("I got a silver machine.")
ohbot.wait(1)

# Switch to espeak
ohbot.setSynthesizer("espeak")
コード例 #18
0
def doNod():
    ohbot.wait(0.5861804837892748)
    ohbot.wait(0.07375042173905144)
    ohbot.wait(0.4978153467385975)
    ohbot.wait(0.07835982309774225)
    ohbot.wait(0.5992221766297934)
    ohbot.wait(0.19820425842370093)
    ohbot.move(0, 4)
    ohbot.wait(2.456810924182153)
    ohbot.wait(0.6414933000935639)
コード例 #19
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
コード例 #20
0
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):
コード例 #21
0
# 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)
コード例 #22
0
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))