Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Max_servo_head_tests.py #1

Merged
merged 1 commit into from
May 9, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 61 additions & 13 deletions Max_servo_head_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
from random import randint
import time


eyes_up_down_pin = 1
head_left_right_pin = 8 # was 3
head_up_down_pin = 0 # was 4
eyes_left_right_pin = 3 # was 0
jaw_pin = 2

##############################
## Let's seed the random number generator
## which we will use down the road for random actions
Expand All @@ -27,9 +34,17 @@
print("Attaching parts to services")
print("=====================================")

runtime = Runtime.getInstance()
#rpi = Runtime.start('rpi', 'RasPi')
rpi = Runtime.createAndStart('rpi', 'RasPi')
rpi = Runtime.start('rpi', 'RasPi')

# start local speech so we can say things
mouth = Runtime.start('mouth', 'LocalSpeech')
mouth.speakBlocking('Hello, I have a mouth ! I like having a mouth. I can use it to say things')

mouth.speakBlocking('I wish I had a brain - wait, making a brain')
brain = Runtime.start('brain', 'ProgramAB')
mouth.speakBlocking('I wish I had an ear - wait, making an ear')
ear = Runtime.start('ear', 'WebkitSpeechRecognition')

# Setup the Adafruit 16 Channel I2C Servo driver
#This is based on the PCA9685 I2C
Expand All @@ -38,14 +53,15 @@
#then we attach the servoboard service to the service RasPi using
#I2C bus "1" at I2C Address "0x40" which is a Hex Address.
#servoboard = Runtime.start('servoboard', 'Adafruit16CServoDriver')
servoboard = Runtime.createAndStart('servoboard', 'Adafruit16CServoDriver')
mouth.speakBlocking('I am about to start a servoboard and a bunch of servos')
servoboard = Runtime.start('servoboard', 'Adafruit16CServoDriver')
servoboard.attach('rpi','1','0x40')
EYESUD = Runtime.createAndStart('EYESUD', 'Servo')
HEADLR = Runtime.createAndStart('HEADLR', 'Servo')
EYESUD = Runtime.start('EYESUD', 'Servo')
HEADLR = Runtime.start('HEADLR', 'Servo')
python = Runtime.start('python', 'Python')
HEADUD = Runtime.createAndStart('HEADUD', 'Servo')
EYESLR = Runtime.createAndStart('EYESLR', 'Servo')
JAW = Runtime.createAndStart('JAW', 'Servo')
HEADUD = Runtime.start('HEADUD', 'Servo')
EYESLR = Runtime.start('EYESLR', 'Servo')
JAW = Runtime.start('JAW', 'Servo')


##############################################################
Expand All @@ -55,12 +71,15 @@
print("=====================================")
print("Attaching servos to servoboard pins")
print("=====================================")
mouth.speakBlocking('now I am attaching the servos to the servoboard')
EYESUD.attach(servoboard, eyes_up_down_pin)
HEADLR.attach(servoboard, head_left_right_pin)
HEADUD.attach(servoboard, head_up_down_pin)
EYESLR.attach(servoboard, eyes_left_right_pin)
JAW.attach(servoboard, jaw_pin)


EYESUD.attach(servoboard,1)
HEADLR.attach(servoboard,3)
HEADUD.attach(servoboard,4)
EYESLR.attach(servoboard,0)
JAW.attach(servoboard,2)
mouth.speakBlocking('now I am configuring the servos but really this should occur before attaching')

##############################################################
## creating client connections connections ####
Expand Down Expand Up @@ -118,44 +137,69 @@
JAW.setAutoDisable(True)

def lookRight():
mouth.speak("I'm looking right")
EYESLR.moveTo(120)
HEADLR.moveTo(160)
def lookLeft():
mouth.speak("I'm looking left")
EYESLR.moveTo(60)
HEADLR.moveTo(10)
def lookForward():
mouth.speak("I'm looking forward")
EYESLR.rest()
HEADLR.rest()
HEADUD.rest()
def lookUp():
mouth.speak("I'm looking up")
EYESUD.moveTo(60)
HEADUD.moveTo(10)
def lookDown():
mouth.speak("I'm looking down")
EYESUD.moveTo(140)
HEADUD.moveTo(140)
def headLeft():
HEADLR.moveTo(30)
HEADLR.moveTo(10)
def headRight():
HEADLR.moveTo(145)
HEADLR.moveTo(160)
def headForward():
HEADLR.moveTo(85)
def jawopen():
JAW.moveTo(90)
EYESLR.rest()
HEADLR.rest()
HEADUD.rest()
def jawclose():
JAW.moveTo(52)
EYESLR.rest()
HEADLR.rest()
HEADUD.rest()

print("time.sleeping 5 seconds before we start")
time.sleep(5)
print("Looking right")
mouth.speakBlocking('Looking right')
lookRight()
time.sleep(2)
print("Looking left")
mouth.speakBlocking('Looking left')
lookLeft()
time.sleep(2)
print("Resetting eyes to middle")
mouth.speakBlocking('Resetting eyes to middle')
lookForward()
time.sleep(2)
print("looking up")
mouth.speakBlocking('looking up')
lookUp()
time.sleep(2)
print("looking down")
mouth.speakBlocking('looking down')
lookDown()
time.sleep(2)
print("looking straight forward")
mouth.speakBlocking('looking straight forward')
lookForward()
time.sleep(2)
#print("turning head right from my point of view")
Expand All @@ -168,12 +212,16 @@ def jawclose():
#headForward()
#time.sleep(7)
print("opening jaw")
mouth.speakBlocking('opening jaw')
jawopen()
time.sleep(5)
print("closing jaw")
mouth.speakBlocking('closing jaw')
jawclose()
print("+++++++++++++++++++++")
print("All tests completed")
print("+++++++++++++++++++++")

print("Ain't I just amazing!!!")
mouth.speakBlocking("Aint I just amazing!")