import paramiko import time import os import sys from naoqi import ALProxy from Robot import Robot from RobotGender import RobotGender def printTotals(transferred, toBeTransferred): print "Transferred: {0}\tOut of: {1}".format(transferred, toBeTransferred) class RobotEmotion(RobotGender): def emotionIntro(self): if self.language == "EN": self.say_1 = "^start(animations/Stand/Gestures/Explain_2)You are going to hear a voice that sounds either happy, sad, or angry. \ It is your task to determine the emotion of the voice. \ ^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. You can answer by touching my right hand, head, or left hand. Let's try it. \\pau=500\\" self.say_4 = "\\pau=500\\ Now I will try to make myself as quite as possible so we can get started." self.say_5 = "Touch my right hand if the voice sounds happy" self.say_6 = "My head if the voice sounds angry." self.say_7 = "Or my left hand if the voice sounds sad." elif self.language == "NL": if "HIK" in self.subject: self.say_1 = "^start(animations/Stand/Gestures/Explain_2)Je gaat een stem horen die blij, verdrietig, of boos klinkt. \ Jouw taak is om te zeggen welke emotie je hebt gehoord. \ ^wait(animations/Stand/Gestures/Explain_2)" self.say_2 = "Prima!\\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.say_5 = "Als de stem blij klinkt, raak dan mijn rechterhand aan. Probeer maar." self.say_6 = "Super! \\pau=150\\ Als de stem boos klinkt, raak dan mijn hoofd aan." self.say_7 = "Heel goed! \\pau=150\\ Of als de stem verdrietig klinkt, raak dan mijn linkerhand aan." else: self.say_1 = "^start(animations/Stand/Gestures/Explain_2)Je gaat een stem horen die blij, verdrietig, of boos klinkt. \ Jouw taak is om te zeggen welke emotie je hebt gehoord. \ ^wait(animations/Stand/Gestures/Explain_2)" self.say_2 = "Prima!\\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.say_5 = "Als de stem blij klinkt, raak dan mijn rechterhand aan. Probeer maar." self.say_6 = "Super! \\pau=150\\ Als de stem boos klinkt, raak dan mijn hoofd aan." self.say_7 = "Heel goed! \\pau=150\\ Of als de stem verdrietig klinkt, raak dan mijn linkerhand aan." self.mtn.wakeUp() self.aas.say(self.say_1) self.aas.setBodyLanguageMode = 0 # self.pst.goToPosture("Stand", 0.7) # self.rightHandMotion(self.say_5) self.aas.say(self.say_2) self.all.fadeRGB("FaceLeds", "green", 0.01) self.tts.say("\\pau=500\\") self.aas.say(self.say_3) self.all.fadeRGB("FaceLeds", "white", 0.01) self.aas.say(self.say_5) self.rechterhand_beweging() # self.tts.say("\\pau=250\\") # self.headMovement(self.say_6) self.aas.say(self.say_6) self.hoofd_beweging() # self.tts.say("\\pau=250\\") # self.leftHandMove(self.say_7) self.aas.say(self.say_7) self.linkerhand_beweging() 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) try: self.aap.playFile(remotepath) except RuntimeError: sys.exit(0) sftp.remove(stimulus) time.sleep(0.5) def answer(self, correct_answer, feedback): self.mtn.setStiffnesses(self.hips, 1.0) start_time = time.time() self.all.fadeRGB("FaceLeds", "green", 0.01) current_running_time = 0 answer_given = 0 while current_running_time < (start_time + 120): try: head1 = self.mem.getData('RearTactilTouched') head2 = self.mem.getData('FrontTactilTouched') head3 = self.mem.getData('MiddleTactilTouched') head = [head1, head2, head3] 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 = "happy" break elif any(left): answer_given = "sad" break elif any(head): answer_given = "angry" break current_running_time = time.time() except RuntimeError as e: print e sys.exit(0) if feedback == 1: self.mtn.setStiffnesses(["HeadYaw", "HeadPitch"], [1.0, 1.0]) if answer_given == correct_answer: self.head_nod() elif answer_given != correct_answer: self.head_shake() else: self.tts.say(self.say_3) self.mtn.setStiffnesses(["HeadYaw", "HeadPitch"], [0.0, 0.0]) self.all.fadeRGB("FaceLeds", "white", 0.01) return answer_given def headMovement(self, string): '''Moves the head down for the subject to test the tactile function of Sam during the introduction.''' names = list() times = list() keys = list() names.append("HeadPitch") times.append([0.7]) keys.append([[0.35738, [3, -0.133333, 0], [3, 0, 0]]]) names.append("HeadYaw") times.append([0.7]) keys.append([[-0.0399261, [3, -0.133333, 0], [3, 0, 0]]]) try: motion = ALProxy("ALMotion") motion.moveInit() w = motion.post.angleInterpolationBezier(names, times, keys) self.tts.say(string) motion.wait(w, 0) except BaseException, err: print err names.append("HeadPitch") times.append([0.7]) keys.append([[-0.17185, [3, -0.133333, 0], [3, 0, 0]]]) names.append("HeadYaw") times.append([0.7]) keys.append([[-0.0153821, [3, -0.133333, 0], [3, 0, 0]]]) try: self.mtn.angleInterpolationBezier(names, times, keys) except BaseException, err: print err