def Run(command):
    #api.Walk(True)
    #print("Running...")
    #move foward
    if (command == 1):
        api.PlayAction(15)
        print('Sit')
        command = 0
        #api.WalkMove(0)
        #api.Walk(True)
        #api.WalkMove(20)
    #move back
    elif (command == 0):
        api.PlayAction(8)
        print('Stand up')
        command = 1
        #print("supposed to move backwards")
    #move right
    elif (command == 8):
        api.WalkMove(0)
        api.WalkTurn(20)
    #move left
    elif (command == 9):
        api.WalkMove(0)
        api.WalkTurn(-20)
    elif (command == 5):
        api.WalkMove(0)
    Run(command)
Ejemplo n.º 2
0
def Run(command):
    thresh = 5
    while (True):
        if (command == 1):
            api.PlayAction(52)
            buzzer = Buzzer()
            buzzer.play(4)
            print('Plank')
            command = 0
            thresh = 5
        elif (command == 0):

            api.PlayAction(55)
            print('Crawl')
            cry = random.randint(1, thresh)
            thresh -= 1
            print(cry)
            if (cry == 1):
                command = 2
                print('Cry')
            FB = api.passAccelData(1)
            print(FB)
            if (FB > 440 or FB < 350):
                command = 4

        elif (command == 2):
            FB = api.passAccelData(1)
            print('crying: ')
            print(FB)
            buzzer = Buzzer()
            buzzer.play(1)
            if (FB > 420 or FB < 360):
                command = 3

        elif (command == 3):
            api.PlayAction(52)
            FB = api.passAccelData(1)
            buzzer = Buzzer()
            buzzer.play(2)
            while (FB > 420 or FB < 360):
                buzzer = Buzzer()
                buzzer.play(3)
                FB = api.passAccelData(1)
                print(FB)

            command = 1

        elif (command == 4):

            for i in range(0, 10):
                buzzer = Buzzer()
                buzzer.play(1)
                print('Sorry...')
            command = 3
Ejemplo n.º 3
0
 def emotion_ready(self):
     if api.Initialize():
         print("Initialized")
         api.PlayAction(3)
         time.sleep(3)
     else:
         print("Initialization failed")
         sys.exit(1)
Ejemplo n.º 4
0
    def posture_emotion(self, emotion_class, emotion_level):
	api_map = {'happy1': 3, 'sad1': 3, 'fear1': 3, 'anger1': 3, 'surprise1': 3, 'happy3': 4, 'happy2': 5, 'anger2': 6, 'anger3': 7, 'fear3': 11,
                   'fear2': 12, 'surprise2': 13, 'surprise3': 14, 'sad2': 17, 'sad3': 18}

	emotion_level = emotion_level+1
        if emotion_level > 1:
	    api.PlayAction(api_map[emotion_class + repr(emotion_level)])
	else:
            print("There are only two levels, use 1, or 2")    
Ejemplo n.º 5
0
    def show_emotion(self, emotion_class, emotion_level):
        api_map = {'happy1': 3, 'sad1': 3, 'fear1': 3, 'anger1': 3, 'surprise1': 3, 'happy3': 4, 'happy2': 5, 'anger2': 6, 'anger3': 7, 'fear3': 11,
                   'fear2': 12, 'surprise2': 13, 'surprise3': 14, 'sad2': 17, 'sad3': 18}


        emotionDisplay.main(emotion_class, emotion_level)
	if emotion_level > 1:
            sound.sound_activate(emotion_class, emotion_level)
	api.PlayAction(api_map[emotion_class + repr(emotion_level)])
def Main():
    command = 1
    #api.ServoShutdown()
    try:
        if api.Initialize():
            print("Initalized")
            command = 1
        else:
            print("Intialization failed")
        #api.ServoShutdown()
        api.PlayAction(8)
        print('Stand up')
        #value = int(input("Turn head to"))
        #api.SetMotorValue(20, value)
        Run(command)
    except (KeyboardInterrupt):
        api.ServoShutdown()
        sys.exit()
    except ():
        api.ServoShutdown()
        sys.exit()
Ejemplo n.º 7
0
def Run(X,Y,Distance):
        global Walk, sit, HeadMoved,i,j
        #api.Walk(True)
        print("Running...")
        command = 0
	z=5
	# declaring servos limmits
	#headRightLim=667
	#headLeftLim=364
	#headUpLim=612
	#headDownLim=433
	
	headRightLim=600
        headLeftLim=420
        headUpLim=612
        headDownLim=433
        
        
	pan = api.GetMotorValue(19)
	tilt= api.GetMotorValue(20)
	
	# check when to call the walk functions
        if ((pan<headRightLim) and (pan>headLeftLim)):
		print "head move"
	elif (pan>headRightLim):
		# call walk to the left till you reach pan = 512 (need while loop)
#		while (pan != 512):
			print "walk to the left"
	elif (pan<headLeftLim):
		# call walk to the right till you reach pan = 512 (need while loop)
#		while (pan != 512):
                        print "walk to the left"
	if (abs(X)>=100): p=9
	elif (abs(X)<100 and abs(X) >70): p = 7
	elif (abs(X)<= 70 and abs(X)> 50): p= 5
	else: p=2
	if (abs(Y)>=100): j=5
        elif (abs(Y)<100 and abs(Y) >70): j = 4
        elif (abs(Y)<= 70 and abs(Y)> 50): j= 3
        else: j=2
	print ('p = ',p, 'j= ',j)
	if HeadMoved == 0:
	   i= int(round(X/10))
	   if (X>50) and (667 > pan):
		for I in range(1,z):
			api.SetMotorValue(19,pan+p)
	   elif (X<-50) and (364 < pan):
		for I in range(1,abs(z)):
			api.SetMotorValue(19,pan-p)
	   if (Y>50) and ( 612 > tilt):
                for I in range(1,z):
                        api.SetMotorValue(20,tilt+j)
           elif (Y<-50) and (433 < tilt):
                for I in range(1,abs(z)):
                        api.SetMotorValue(20,tilt-j)
	print Distance
	if (Distance < 150) and (Walk == False):
		api.Walk(True)
		speed = int((150-Distance)/2)
		if speed > 10: speed = 10
		print ('Speed = ',speed)
		api.WalkMove(speed)
		Walk = True
		sit = 0
		HeadMoved = 1
		print('Walk=======>')
	elif(Distance > 150) and (Walk == True)  :
		#api.WalkMove(2)
		#api.Walk(False)
		Walk=False	
		if (sit == 0):
			api.Walk(False)
			api.PlayAction(15)
			sit = 1
			print ( 'Sitting+++++++++')
	if (Walk == True):
		if (X>50):
                         api.WalkTurn(p)
                         #api.WalkMove(Distance)
			 print('Trun Right')
                elif (X<-50):
                         api.WalkTurn(-p)
                         print('Trun Left')
                else :
                        api.WalkTurn(0)
                        print ('No Trun')

        print("pan",pan)

        print("tilt",tilt)