from Robot import Robot import paramiko import time import sys class RobotFishy(Robot): def fishyIntro(self): ''' The intriduction to the experiment. Sam explains how the task will work and what to do, as well as a demonstration on how to touch the head and hands ''' if self.language == 'EN': self.say_1 = "^start(animations/Stand/Gestures/Explain_2)You are goint to hear a triplet of three different syllables. \ One of the triplets is said in a different voice. \ It is your task to determine which triplet is said in a different voice. \ You can answer by touching my right hand, \\pau=500\\ head \\pau=500\\or left hand. \ Lets give it a try. ^wait(animations/Stand/Gestures/Explain_2)" self.say_2 = "If the first word is said in a different voice, then touch the top of my right hand. Try it." self.say_3 = "Great! \\pau=500\\ and if the second sound is said differently, then touch the top of my head." self.say_4 = "Super! \\pau=500\\ and if the last sound is said in a different voice, then touch the top of my left hand." self.say_5 = "Very good!. During the experiment, when my eyes turn green like this," self.say_6 = "I am ready for your answer." # self.say_7 = "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_7 = "\\pau=500\\ Now I will try to make myself as quite as possible." elif self.language == 'NL': self.say_1 = "^start(animations/Stand/Gestures/Explain_2)Je gaat 3 keer een triplet van verschillende lettergrepen horen.\ 1 van de tripletten wordt gezegd met een andere stem. Het is jouw taak om aan te geven welke anders klinkt. \ Je kunt antwoorden door je hand op mijn rechterhand, \\pau=500\\ hoofd \\pau=500\\of linkerhand te leggen. \ Laten we het proberen. ^wait(animations/Stand/Gestures/Explain_2)" self.say_2 = "Als het eerste woord met een andere stem gezegd wordt, leg je jouw hand op de bovenkant van mijn rechterhand. Probeer maar" self.say_3 = "Heel goed \\pau=500\\ en als het tweede woord met een andere stem gezegd wordt, leg je jouw hand op de bovenkant van mijn hoofd" self.say_4 = "Super \\pau=500\\ en als laatste de bovenkant van mijn linkerhand" self.say_5 = "Heel goed. Dan 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.rechterhand_beweging() self.aas.say(self.say_3) self.hoofd_beweging() self.aas.say(self.say_4) self.linkerhand_beweging() # time.sleep(1) self.aas.say(self.say_5) self.all.fadeRGB("FaceLeds", "green", 0.01) self.tts.say("\\pau=500\\") self.aas.say(self.say_6) self.all.fadeRGB("FaceLeds", "white", 0.01) self.aas.say(self.say_7) self.mtn.rest() self.mtn.setStiffnesses(self.hips, 1.0) def play_sounds(self, soundfiles_att): ''' Uploads the stimuli files to Sam using a paramiko sftp server. Sam then plays the files, then deletes them off its main storage. ''' soundfiles = list(soundfiles_att.split(", ")) # soundfiles = [] # filename = "" # for i in soundfiles_att: # if i == ',': # soundfiles.append(filename) # filename = '' # else: # filename = filename+i 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/') for soundfile in soundfiles: # localpath = ( # 'C:\\Users\\Nao\\Documents\\Nao\\Python_scripts\\tmp\\' + soundfile) # localpath = "./" + soundfile.strip() remotepath = str('/home/nao/tests/' + soundfile) try: sftp.put(soundfile, remotepath) except: raise ValueError('Yo cannot find the right stuff') for i in range(1, 1000): dir_list = sftp.listdir() if soundfile in dir_list: break else: time.sleep(0.01) if i == 999: raise ValueError('File was not uploaded to nao') sys.exit() for soundfile in soundfiles: # localpath = ( # 'C:\\Users\\Nao\\Documents\\Nao scripts\\Expe_files\\' + soundfile) localpath = "./tmp/" + soundfile remotepath = str('/home/nao/tests/' + soundfile) try: self.aap.playFile(remotepath) except RuntimeError: # raise ValueError( # 'stupid thing needs to be string check type') sys.exit(0) sys.exit(0) sftp.remove(soundfile) time.sleep(0.5) def answer(self, robot_input): ''' Waits for the response from the subject on which of the sounds was different. ''' try: if self.language == 'EN': self.say_1 = "That is correct." self.say_2 = "That is incorrect." self.say_3 = "You did not give an answer." elif self.language == 'NL': self.say_1 = "Dat is correct." self.say_2 = "Dat is niet correct." self.say_3 = "Je hebt geen antwoord gegeven." correct_answer = int(robot_input[0]) feedback = int(robot_input[1]) # this function returns the answer given by the participant. As input it requires the correct answer (from matlab) and it has an option for feedback (0 or 1). start_time = time.time() # LEDs change colour to indicate Sam is ready for a response self.all.fadeRGB("FaceLeds", "green", 0.01) current_running_time = 0 answer_given = 0 # TODO maybe add a warning after 7 seconds. # TODO add a way to replay the sounds if necessary? while current_running_time < (start_time+120): # check the data continously for 7 seconds 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 = 0 break elif any(head): answer_given = 1 break elif any(left): answer_given = 2 break current_running_time = time.time() except RuntimeError: 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.1) return answer_given except RuntimeError: sys.exit(0) # === Custom movements ===