from Robot import Robot import paramiko import os import sys import cPickle as pickle import time from naoqi import ALProxy class RobotCRM(Robot): def crmIntro(self): if self.language == "EN": self.say_1 = "^start(animations/Stand/Gestures/Explain_2)You are going to hear a sentence that sounds like it is spoken in a noisy room. \\pau=500\\ \ It is your task to determine what was said in the sentence. An example sentence is, show the dog where the green 4 is.\\pau=500\\ \ To enter your answer, you will have to use the coloured grid on the tablet provided. You must choose both the correct color and number that was spoken.\ ^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. \\pau=500\\" self.say_4 = "Now I will try to make myself as quiet as possible." elif self.language == "NL": self.say_1 = "^start(animations/Stand/Gestures/Explain_2)You are going to hear a sentence that sounds like it is spoken in a noisy room. \\pau=500\\ \ It is your task to determine what was said in the sentence. An example sentence is, show the dog where the green 4 is.\\pau=500\\ \ To enter your answer, you will have to use the coloured grid on the tablet provided. You must choose both the correct color and number that was spoken.\ ^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. \\pau=500\\" self.say_4 = "Now I will try to make myself as quiet as possible." self.mtn.wakeUp() self.aas.say(self.say_1) 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_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) print "trying to upload" 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) print "uploaded, now playing" try: self.aap.playFile(remotepath) except RuntimeError: sys.exit(0) sftp.remove(stimulus) time.sleep(0.5) return True def answer(self, correct_answer, feedback, current_trial, total_trials): self.mtn.setStiffnesses(self.hips, 1.0) self.all.fadeRGB("FaceLeds", "green", 0.01) start_time = time.time() current_running_time = 0 folder = os.path.dirname("./crm/") ans_file = 'answer.p' answer = {} while current_running_time < start_time + 120: dirs = os.listdir('./crm') if ans_file in dirs: try: with open('./crm/answer.p', 'rb') as f: answer = pickle.load(f) break except EOFError as e: print e current_running_time = time.time() answer["number"] = int(answer["number"]) response_time = time.time() - start_time if feedback: self.mtn.setStiffnesses(["HeadYaw", "HeadPitch"], [1.0, 1.0]) if answer["colour"] == correct_answer["colour"] and answer["number"] == correct_answer["number"]: self.head_nod() else: self.head_shake() self.mtn.setStiffnesses(["HeadYaw", "HeadPitch"], [0.0, 0.0]) self.all.fadeRGB("FaceLeds", "white", 0.01) os.remove(os.path.join(folder, ans_file)) trial_track = {"current_trial": current_trial + 1, "total_trials": total_trials} with open('./crm/trials.p', 'wb') as f: pickle.dump(trial_track, f) print current_trial return answer, response_time