Archived
Initial commit
This commit is contained in:
commit
d89b82be4a
103 files changed
+23110
No files matched your search
@@ -0,0 +1,231 @@
|
||||
from naoqi import ALProxy
|
||||
from Robot import Robot
|
||||
import paramiko
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
import numpy as np
|
||||
|
||||
|
||||
class RobotGender(Robot):
|
||||
|
||||
def genderIntro(self):
|
||||
if self.language == "EN":
|
||||
self.say_1 = "^start(animations/Stand/Gestures/Explain_2)You are going to hear a voice that sounds either like a boy, or a girl. \
|
||||
It is your task to determine the gender of the voice. \
|
||||
You can answer by touching my right hand, \\pau=500\\or left hand. \
|
||||
Each time you hear a voice, I will tell you which of my hands is for boy, and which hand is for girl. \
|
||||
^wait(animations/Stand/Gestures/Explain_2)"
|
||||
self.say_2 = "\\pau=500\\ During the experiment, when my eyes turn green like this,"
|
||||
self.say_3 = "I am ready for your answer."
|
||||
# self.say_4 = "One last thing. If at any point you want to stop the experiment, wait for me to stop talking, and then press my right foot. \\pau=500\\ Now I will try to make myself as quite as possible."
|
||||
self.say_4 = "Now I will try to make myself as quite as possible."
|
||||
|
||||
if self.language == "NL":
|
||||
self.say_1 = "^start(animations/Stand/Gestures/Explain_2)Je gaat een stem horen die zoals een jongen of een meisje klinkt. \
|
||||
Ik vraag dan aan jou of je de stem van een jongen of een meisje hebt gehoord. \
|
||||
Je kunt antwoorden door mijn rechterhand, \\pau=500\\of linkerhand aan te raken. \
|
||||
Elke keer als je een stem hoort, zal ik je vertellen welke hand voor jongen is, en welke hand voor meisje is. \
|
||||
^wait(animations/Stand/Gestures/Explain_2)"
|
||||
self.say_2 = "\\pau=500\\ Tijdens het experiment, als mijn ogen zo groen worden,"
|
||||
self.say_3 = "Mag jij antwoord geven."
|
||||
self.say_4 = "Nog een ding. Als je het experiment tussendoor wilt stoppen, wacht dan tot ik ben gestopt met praten en raak dan mijn rechtervoet aan. \\pau=500\\ Nou zal ik me nu zo stil mogelijk maken."
|
||||
|
||||
self.mtn.wakeUp()
|
||||
self.aas.say(self.say_1)
|
||||
self.aas.setBodyLanguageMode = 0
|
||||
self.pst.goToPosture("Stand", 0.7)
|
||||
self.aas.say(self.say_2)
|
||||
self.all.fadeRGB("FaceLeds", "green", 0.01)
|
||||
self.tts.say("\\pau=150\\")
|
||||
self.aas.say(self.say_3)
|
||||
self.all.fadeRGB("FaceLeds", "white", 0.01)
|
||||
self.aas.say(self.say_4)
|
||||
self.mtn.rest()
|
||||
self.mtn.setStiffnesses(self.hips, 1.0)
|
||||
|
||||
def play_sounds(self, stimulus, lang):
|
||||
'''
|
||||
Uploads the stimuli files to Sam using a paramiko sftp server.
|
||||
Sam then plays the files, then deletes them off its main storage.
|
||||
'''
|
||||
|
||||
NAO_USERNAME = "nao"
|
||||
NAO_PASSWORD = "nao"
|
||||
t = paramiko.Transport((self.ipadress, 22))
|
||||
t.connect(username=NAO_USERNAME, password=NAO_PASSWORD)
|
||||
sftp = paramiko.SFTPClient.from_transport(t)
|
||||
sftp.chdir('/home/nao/tests/')
|
||||
remotepath = str('/home/nao/tests/' + stimulus)
|
||||
|
||||
try:
|
||||
sftp.put(stimulus, remotepath)
|
||||
except:
|
||||
raise ValueError('No file provided for upload.')
|
||||
for i in range(1, 1000):
|
||||
dir_list = sftp.listdir()
|
||||
if stimulus in dir_list:
|
||||
break
|
||||
else:
|
||||
time.sleep(0.01)
|
||||
if i == 999:
|
||||
raise ValueError('File was not uploaded to nao')
|
||||
|
||||
# localpath = (
|
||||
# 'C:\\Users\\Nao\\Documents\\Nao scripts\\Expe_files\\' + soundfile)
|
||||
remotepath = str('/home/nao/tests/' + stimulus)
|
||||
try:
|
||||
self.aap.playFile(remotepath)
|
||||
except RuntimeError:
|
||||
# raise ValueError(
|
||||
# 'stupid thing needs to be string check type')
|
||||
sys.exit(0)
|
||||
|
||||
sftp.remove(stimulus)
|
||||
time.sleep(0.5)
|
||||
|
||||
def answer(self):
|
||||
self.mtn.setStiffnesses(self.hips, 1.0)
|
||||
self.mtn.setStiffnesses(
|
||||
["RShoulderPitch", "RShoulderRoll", "RElbowYaw", "RElbowRoll", "RWristYaw", "LShoulderPitch", "LShoulderRoll", "LElbowYaw", "LElbowRoll", "LWristYaw"], 1.0)
|
||||
OR = ""
|
||||
if self.language == "EN":
|
||||
gender = np.array(["Boy?", "Girl?"])
|
||||
OR = "or"
|
||||
elif self.language == "NL":
|
||||
gender = np.array(["Jongen?", "Meisje?"])
|
||||
OR = "of"
|
||||
np.random.shuffle(gender)
|
||||
self.rightHandMotion(gender[0])
|
||||
self.tts.say(OR)
|
||||
self.leftHandMove(gender[1])
|
||||
self.mtn.setStiffnesses(
|
||||
["RShoulderPitch", "RShoulderRoll", "RElbowYaw", "RElbowRoll", "RWristYaw", "LShoulderPitch", "LShoulderRoll", "LElbowYaw", "LElbowRoll", "LWristYaw"], 0.0)
|
||||
start_time = time.time()
|
||||
self.all.fadeRGB("FaceLeds", "green", 0.01)
|
||||
current_running_time = 0
|
||||
answer_given = 0
|
||||
gender_chosen = ""
|
||||
while current_running_time < (start_time + 120):
|
||||
try:
|
||||
left1 = self.mem.getData('HandLeftRightTouched')
|
||||
left2 = self.mem.getData('HandLeftBackTouched')
|
||||
left3 = self.mem.getData('HandLeftLeftTouched')
|
||||
left = [left1, left2, left3]
|
||||
right1 = self.mem.getData('HandRightRightTouched')
|
||||
right2 = self.mem.getData('HandRightBackTouched')
|
||||
right3 = self.mem.getData('HandRightLeftTouched')
|
||||
right = [right1, right2, right3]
|
||||
|
||||
if any(right):
|
||||
answer_given = 1
|
||||
gender_chosen = gender[0].split(" ")[-1][:-1]
|
||||
break
|
||||
elif any(left):
|
||||
answer_given = 2
|
||||
gender_chosen = gender[1].split(" ")[-1][:-1]
|
||||
break
|
||||
current_running_time = time.time()
|
||||
except RuntimeError:
|
||||
sys.exit(0)
|
||||
self.all.fadeRGB("FaceLeds", "white", 0.01)
|
||||
resp = {"answer": answer_given, "gender": gender_chosen}
|
||||
return resp, gender_chosen
|
||||
|
||||
# === Custom movements ===
|
||||
|
||||
def rightHandMotion(self, gender):
|
||||
|
||||
# Choregraphe bezier export in Python.
|
||||
names = list()
|
||||
times = list()
|
||||
keys = list()
|
||||
|
||||
names.append("RElbowRoll")
|
||||
times.append([1, 1.48, 1.96])
|
||||
keys.append([[0.90817, [3, -0.333333, 0], [3, 0.16, 0]], [0.909704,
|
||||
[3, -0.16, 0], [3, 0.16, 0]], [0.865218, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
names.append("RElbowYaw")
|
||||
times.append([1, 1.48, 1.96])
|
||||
keys.append([[0.493906, [3, -0.333333, 0], [3, 0.16, 0]], [1.00626,
|
||||
[3, -0.16, 0], [3, 0.16, 0]], [0.486236, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
names.append("RHand")
|
||||
times.append([1, 1.48, 1.96])
|
||||
keys.append([[0.3544, [3, -0.333333, 0], [3, 0.16, 0]], [0.3544,
|
||||
[3, -0.16, 0], [3, 0.16, 0]], [0.3544, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
names.append("RShoulderPitch")
|
||||
times.append([1, 1.48, 1.96])
|
||||
keys.append([[1.21804, [3, -0.333333, 0], [3, 0.16, 0]], [1.05083,
|
||||
[3, -0.16, 0], [3, 0.16, 0]], [1.23338, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
names.append("RShoulderRoll")
|
||||
times.append([1, 1.48, 1.96])
|
||||
keys.append([[-0.0552659, [3, -0.333333, 0], [3, 0.16, 0]], [-0.305308,
|
||||
[3, -0.16, 0], [3, 0.16, 0]], [0.0229681, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
names.append("RWristYaw")
|
||||
times.append([1, 1.48, 1.96])
|
||||
keys.append([[0.23466, [3, -0.333333, 0], [3, 0.16, 0]], [1.41737,
|
||||
[3, -0.16, 0], [3, 0.16, 0]], [0.0429101, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
try:
|
||||
# uncomment the following line and modify the IP if you use this script outside Choregraphe.
|
||||
# motion = ALProxy("ALMotion", IP, 9559)
|
||||
motion = ALProxy("ALMotion")
|
||||
motion.moveInit()
|
||||
w = motion.post.angleInterpolationBezier(names, times, keys)
|
||||
self.tts.say(gender)
|
||||
motion.wait(w, 0)
|
||||
except BaseException, err:
|
||||
print err
|
||||
|
||||
def leftHandMove(self, gender):
|
||||
|
||||
# Choregraphe bezier export in Python.
|
||||
names = list()
|
||||
times = list()
|
||||
keys = list()
|
||||
|
||||
names.append("LElbowRoll")
|
||||
times.append([1, 1.48])
|
||||
keys.append([[-1.03848, [3, -0.333333, 0], [3, 0.16, 0]],
|
||||
[-1.04921, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
names.append("LElbowYaw")
|
||||
times.append([1, 1.48])
|
||||
keys.append([[-1.71505, [3, -0.333333, 0], [3, 0.16, 0]],
|
||||
[-1.49416, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
names.append("LHand")
|
||||
times.append([1, 1.48])
|
||||
keys.append([[0.0296, [3, -0.333333, 0], [3, 0.16, 0]],
|
||||
[0.0296, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
names.append("LShoulderPitch")
|
||||
times.append([1, 1.48])
|
||||
keys.append([[1.20875, [3, -0.333333, 0], [3, 0.16, 0]],
|
||||
[1.53856, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
names.append("LShoulderRoll")
|
||||
times.append([1, 1.48])
|
||||
keys.append([[0.171766, [3, -0.333333, 0], [3, 0.16, 0]],
|
||||
[-0.220938, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
names.append("LWristYaw")
|
||||
times.append([1, 1.48])
|
||||
keys.append([[-0.983336, [3, -0.333333, 0], [3, 0.16, 0]],
|
||||
[0.96331, [3, -0.16, 0], [3, 0, 0]]])
|
||||
|
||||
try:
|
||||
# uncomment the following line and modify the IP if you use this script outside Choregraphe.
|
||||
# motion = ALProxy("ALMotion", IP, 9559)
|
||||
motion = ALProxy("ALMotion")
|
||||
motion.moveInit()
|
||||
w = motion.post.angleInterpolationBezier(names, times, keys)
|
||||
self.tts.say(gender)
|
||||
motion.wait(w, 0)
|
||||
except BaseException, err:
|
||||
print err
|
||||
Reference in new issue
Block a user