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:
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/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()
if tab[8] == 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[9] == 1 :
threadMp3 = MP3Read('../utils/audio/extraverti/Phrase4.mp3')
threadMp3.start()
time.sleep(0.5)
if tab[10] == 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[11] == 1 :
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()
if tab[12] == 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[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.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[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[1] < -0.9 :
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[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[2] > 0.9 :
threadMp3 = MP3Read('../utils/audio/neSaisPas.mp3')
threadMp3.start()
time.sleep(1)
if tab[2] < -0.9 :
cherry.robot.copy_arm_behave.start()
for m in cherry.robot.arms:
m.moving_speed = 0
time.sleep(0.5)
if tab[3] < -0.9 :
cherry.robot.copy_arm_behave.stop()
for m in cherry.robot.arms:
m.compliant = False
cherry.robot.rest_position.start()
time.sleep(0.5)
if tab[3] > 0.9 :
cherry.robot.see_you_soon_behave.start()
time.sleep(1.5)
threadMp3 = MP3Read('../utils/audio/abientot.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 [ ]:
for m in cherry.robot.arms:
m.compliant = True
In [ ]:
for m in cherry.robot.arms:
m.compliant = False
In [ ]:
fileName = "../utils/moveRecord/test.move"
In [ ]:
move_recorder = MoveRecorder(cherry.robot, 50, cherry.robot.motors)
for m in cherry.robot.arms:
m.compliant = True
cherry.robot.abs_z.compliant = True
move_recorder.start()
In [ ]:
move_recorder.stop()
with open(fileName, 'w') as f:
move_recorder.move.save(f)
In [ ]:
import time
with open("../utils/moveRecord/test.move") as f:
m = Move.load(f)
cherry.robot.compliant = False
move_player = MovePlayer(cherry.robot, m)
move_player.start()
In [ ]:
cherry.robot.run_look.start()
In [ ]:
cherry.camera.displayVideo()
In [ ]:
cherry.robot.tracking_behave.start()
In [ ]:
cherry.robot.tracking_behave.stop()
cherry.robot.head_z.goal_position = 0.0
cherry.robot.head_y.goal_position = 30.0
In [ ]:
import time
import sys
from threading import Thread, RLock
import mp3play
import cv2
class DisplayVideo(Thread):
"""Thread chargé simplement d'afficher un mot dans la console."""
def __init__(self, frame):
Thread.__init__(self)
self._frame = frame
self.running = False
def run(self):
self.running = True
while self.running:
cv2.imshow('Video', self._frame)
time.sleep(0.02)
#self._cam.release()
cv2.destroyAllWindows()
def stop(self):
self.running = False
In [ ]:
threadVideo = DisplayVideo(cherry.camera._frame)
threadVideo.start()
In [ ]:
threadVideo.stop()