In [ ]:
import time
from poppy.creatures import PoppyHumanoid
from cherry import Cherry
from pypot.primitive.move import MoveRecorder, Move, MovePlayer
cherry = Cherry()
cherry.setup()
for m in cherry.robot.motors :
m.goal_position = 0.0
for m in cherry.robot.head :
m.compliant = False
for m in cherry.robot.arms :
m.compliant = True
cherry.robot.head_z.goal_position = 0.0
cherry.robot.head_y.goal_position = 0.0
In [ ]:
import time
import sys
from threading import Thread, RLock
import mp3play
class MP3Read(Thread):
"""Thread chargé simplement d'afficher un mot dans la console."""
def __init__(self, fname):
Thread.__init__(self)
self.filename = fname
def run(self):
mp3 = mp3play.load(self.filename)
mp3.play()
time.sleep(min(35, mp3.seconds()))
mp3.stop()
In [ ]:
#CHERRY EXTRAVERTI
import pygame
import time
import random
import sys
from threading import Thread, RLock
def get():
out = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
it = 0 #iterator
pygame.event.pump()
#Read input from the two joysticks
for i in range(0, j.get_numaxes()):
out[it] = j.get_axis(i)
it+=1
for i in range(0,j.get_numhats()):
out[it] = j.get_hat(i)
it+=1
#Read input from buttons
for i in range(0, j.get_numbuttons()):
out[it] = j.get_button(i)
it+=1
return out
verrou = RLock()
class GamePadRead(Thread):
"""Thread chargé simplement d'afficher un mot dans la console."""
def __init__(self, mot):
Thread.__init__(self)
self.mot = mot
self.running = False
self.zHead = cherry.robot.head_z.present_position
self.yHead = cherry.robot.head_y.present_position
def run(self):
"""Code à exécuter pendant l'exécution du thread."""
self.running = True
while self.running:
with verrou:
tab = get()
#Mouvement de tête avec le Hat
temp = tab[4][0]*2
if(-90<self.zHead+temp <90):
self.zHead += tab[4][0]*2
temp = tab[4][1]*(-2)
if(self.yHead+temp < 20):
self.yHead += temp
cherry.robot.head_z.goal_position = self.zHead
cherry.robot.head_y.goal_position = self.yHead
#Mouvement
if tab[5] == 1 :
cherry.robot.extra_arms_up.start()
time.sleep(0.5)
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase1.mp3')
threadMp3.start()
time.sleep(1)
cherry.robot.me_behave.start()
time.sleep(1.2)
cherry.robot.question_behave.start()
time.sleep(1.3)
cherry.robot.rest_position.start()
if tab[6] == 1 and tab[2] < -0.9 :
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase2.mp3')
threadMp3.start()
time.sleep(0.8)
cherry.robot.hug_behave.start()
time.sleep(1.7)
cherry.robot.me_behave.start()
time.sleep(1.3)
cherry.robot.rest_position.start()
elif tab[6] == 1:
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase2short.mp3')
threadMp3.start()
cherry.robot.hug_behave.start()
time.sleep(1.5)
cherry.robot.me_behave.start()
time.sleep(1.3)
cherry.robot.rest_position.start()
if tab[7] == 1 :
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase3.mp3')
threadMp3.start()
cherry.robot.question_behave.start()
time.sleep(1)
cherry.robot.rest_position.start()
if tab[8] == 1 :
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase4.mp3')
threadMp3.start()
time.sleep(0.5)
if tab[9] == 1 and tab[2] < -0.9 :
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase5Yes.mp3')
threadMp3.start()
time.sleep(1)
cherry.robot.question_behave.start()
time.sleep(1)
cherry.robot.rest_position.start()
elif tab[9] == 1 :
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase5.mp3')
threadMp3.start()
time.sleep(1)
cherry.robot.laugh_behave.start()
time.sleep(2.7)
cherry.robot.rest_position.start()
if tab[10] == 1 :
cherry.robot.hunkers_behave.start()
time.sleep(0.8)
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase6.mp3')
threadMp3.start()
time.sleep(1)
cherry.robot.rest_position.start()
if tab[11] == 1 :
cherry.robot.me_arm_behave.start()
time.sleep(0.8)
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase7.mp3')
threadMp3.start()
time.sleep(1)
cherry.robot.rest_position.start()
if tab[12] == 1 :
cherry.robot.extra_arms_up.start()
time.sleep(0.8)
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase8.mp3')
threadMp3.start()
time.sleep(1.5)
cherry.robot.question_behave.start()
time.sleep(2)
cherry.robot.me_behave.start()
time.sleep(2)
cherry.robot.rest_position.start()
if tab[13] == 1 :
threadMp3 = MP3Read('../utils/audio/oui.mp3')
threadMp3.start()
time.sleep(0.5)
if tab[14] == 1 :
threadMp3 = MP3Read('../utils/audio/non.mp3')
threadMp3.start()
time.sleep(0.5)
if tab[0] < -0.9 :
cherry.robot.hug_behave.start()
time.sleep(0.9)
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase11.mp3')
threadMp3.start()
time.sleep(1)
cherry.robot.rest_position.start()
if tab[0] > 0.9 :
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase12.mp3')
threadMp3.start()
time.sleep(3)
cherry.robot.question_behave.start()
time.sleep(2)
cherry.robot.show_front_hunkers_behave.start()
time.sleep(3)
cherry.robot.show_right_rest_behave.start()
time.sleep(3)
cherry.robot.rest_position.start()
if tab[1] < -0.9 :
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase9.mp3')
threadMp3.start()
time.sleep(0.5)
cherry.robot.left_arms_behave.start()
time.sleep(2)
cherry.robot.right_arms_behave.start()
time.sleep(1.5)
cherry.robot.rest_position.start()
time.sleep(2.5)
cherry.robot.right_hand_up_behave.start()
time.sleep(2.5)
cherry.robot.rest_position.start()
if tab[1] > 0.9 :
cherry.robot.show_front_hunkers_behave.start()
time.sleep(0.5)
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase10.mp3')
threadMp3.start()
time.sleep(1.2)
cherry.robot.extra_arms_up.start()
time.sleep(1.8)
cherry.robot.question_behave.start()
time.sleep(2)
cherry.robot.rest_position.start()
if tab[2] > 0.9 :
threadMp3 = MP3Read('../utils/audio/neSaisPas.mp3')
threadMp3.start()
time.sleep(1)
time.sleep(0.02)
def stop(self):
self.running = False
In [ ]:
pygame.init()
j = pygame.joystick.Joystick(0)
j.init()
print 'Initialized Joystick : %s' % j.get_name()
for m in cherry.robot.arms :
m.compliant = False
for m in cherry.robot.motors:
m.moving_speed = 0
thread = GamePadRead("Test")
thread.start()
In [ ]:
thread.stop()
In [ ]:
#REPOS
cherry.robot.rest_position.start()
In [ ]:
#SE MONTRE
cherry.robot.me_behave.start()
In [ ]:
#SE MONTRE AVEC BRAS EN L'AIR
cherry.robot.me_arm_behave.start()
In [ ]:
#BRAS OUVERT
cherry.robot.question_behave.start()
In [ ]:
#BRAS EN L'AIR
cherry.robot.extra_arms_up.start()
In [ ]:
#CALIN
cherry.robot.hug_behave.start()
In [ ]:
#MAINS SUR LES HANCHES
cherry.robot.hunkers_behave.start()
In [ ]:
#RIRE
cherry.robot.laugh_behave.start()
In [ ]:
#BRAS A GAUCHE
cherry.robot.left_arms_behave.start()
In [ ]:
#BRAS A DROITE
cherry.robot.right_arms_behave.start()
In [ ]:
#BRAS DROIT EN L'AIR
cherry.robot.right_hand_up_behave.start()
In [ ]:
#POINTE DU DOIGT
cherry.robot.show_front_hunkers_behave.start()
In [ ]:
#MONTRE SUR LE COTE
cherry.robot.show_right_rest_behave.start()
In [ ]:
In [ ]:
In [ ]: