def TrialTask(pos): """Task for individual trial. Returns whether pigeon was found.""" #Reset tracker to origin tracker.setPosition([0,1.8,0]) tracker.setEuler([0,0,0]) # Flash screen FlashScreen() # Place pigeon at new location pigeon_root.setPosition(pos) pigeon_root.visible(True) hooting.play(loop=True) # Create proximity sensor for pigeon using main view as target manager = vizproximity.Manager() #manager.setDebug(True) manager.addTarget( vizproximity.Target(viz.MainView) ) sensor = vizproximity.Sensor(vizproximity.Sphere(PROXIMITY_RADIUS),pigeon_root) manager.addSensor(sensor) # Wait until pigeon is found or time runs out wait_time = viztask.waitTask( TrialCountDownTask() ) wait_find = vizproximity.waitEnter(sensor) data = yield viztask.waitAny([wait_time,wait_find]) # Hide pigeon and remove proximity sensor pigeon_root.visible(False) hooting.pause() manager.remove() # Return whether pigeon was found viztask.returnValue(data.condition is wait_find)
def testPhase(): results = [] for i in range(0, 5): # Instruct participant where to go instruction = "Walk around for 5 seconds, see where you end up in this world. You can press 1, 2, or 3".format( sensor.name ) info.setText(instruction) # store the time at which this trial started startTime = viz.tick() position = viz.MainView.getPosition() before = str(subject) + "\t" + str(position) + "\n" # The yielded command returns a viz.Data object with information # about the proximity event such as the sensor, target involved yield vizproximity.wait(5) position = viz.MainView.getPosition() after = str(subject) + "\t" + str(position) + "\n" # save results results.append((before, after)) info.setText("Thank You. You have completed the experiment") # return results viztask.returnValue(results)
def getParticipantInfo(): #Add an InfoPanel with a title bar participantInfo = vizinfo.InfoPanel('', title='Participant Information', align=viz.ALIGN_CENTER, icon=False) #Add name and ID fields textbox_last = participantInfo.addLabelItem('Last Name', viz.addTextbox()) textbox_first = participantInfo.addLabelItem('First Name', viz.addTextbox()) textbox_id = participantInfo.addLabelItem('ID', viz.addTextbox()) participantInfo.addSeparator(padding=(20, 20)) #Add gender and age fields radiobutton_male = participantInfo.addLabelItem('Male', viz.addRadioButton(0)) radiobutton_female = participantInfo.addLabelItem('Female', viz.addRadioButton(0)) droplist_age = participantInfo.addLabelItem('Age Group', viz.addDropList()) ageList = ['20-30', '31-40', '41-50', '51-60', '61-70'] droplist_age.addItems(ageList) participantInfo.addSeparator(padding=(20, 20)) #Add 2d 3D fields radiobutton_2D = participantInfo.addLabelItem('2D', viz.addRadioButton(1)) radiobutton_3D = participantInfo.addLabelItem('3D', viz.addRadioButton(1)) participantInfo.addSeparator(padding=(20, 20)) #Add submit button aligned to the right and wait until it's pressed submitButton = participantInfo.addItem(viz.addButtonLabel('Submit'), align=viz.ALIGN_RIGHT_CENTER) yield viztask.waitButtonUp(submitButton) #Collect participant data data = viz.Data() data.lastName = textbox_last.get() data.firstName = textbox_first.get() data.id = textbox_id.get() data.ageGroup = ageList[droplist_age.getSelection()] if radiobutton_male.get() == viz.DOWN: data.gender = 'male' else: data.gender = 'female' if radiobutton_2D.get() == viz.DOWN: data.environment = '2D' else: data.environment = '3D' participantInfo.remove() # Return participant data viztask.returnValue(data)
def testPhase(): results = [] if centerSensor not in manager.getActiveSensors(): yield vizproximity.waitEnter(centerSensor) sensor = sphereSensors[0] info.setText("Walk to the sphere now.") startTime = viz.tick() yield vizproximity.waitEnter(sensor) info.setText('Please return to the center of the room') elapsedTime = viz.tick() - startTime results.append((sensor.name, elapsedTime)) info.setText("You're all done now!") viztask.returnValue(results)
def getParticipantInfo(): #Add an InfoPanel with a title bar participantInfo = vizinfo.InfoPanel('',title='Participant Information',align=viz.ALIGN_CENTER, icon=False) #Add name and ID fields textbox_last = participantInfo.addLabelItem('Last Name',viz.addTextbox()) textbox_first = participantInfo.addLabelItem('First Name',viz.addTextbox()) textbox_id = participantInfo.addLabelItem('ID',viz.addTextbox()) participantInfo.addSeparator(padding=(20,20)) #Add gender and age fields radiobutton_male = participantInfo.addLabelItem('Male',viz.addRadioButton(0)) radiobutton_female = participantInfo.addLabelItem('Female',viz.addRadioButton(0)) droplist_age = participantInfo.addLabelItem('Age Group',viz.addDropList()) ageList = ['20-30','31-40','41-50','51-60','61-70'] droplist_age.addItems(ageList) participantInfo.addSeparator(padding=(20,20)) #Add 2d 3D fields radiobutton_2D = participantInfo.addLabelItem('2D',viz.addRadioButton(1)) radiobutton_3D = participantInfo.addLabelItem('3D',viz.addRadioButton(1)) participantInfo.addSeparator(padding=(20,20)) #Add submit button aligned to the right and wait until it's pressed submitButton = participantInfo.addItem(viz.addButtonLabel('Submit'),align=viz.ALIGN_RIGHT_CENTER) yield viztask.waitButtonUp(submitButton) #Collect participant data data = viz.Data() data.lastName = textbox_last.get() data.firstName = textbox_first.get() data.id = textbox_id.get() data.ageGroup = ageList[droplist_age.getSelection()] if radiobutton_male.get() == viz.DOWN: data.gender = 'male' else: data.gender = 'female' if radiobutton_2D.get() == viz.DOWN: data.environment = '2D' else: data.environment = '3D' participantInfo.remove() # Return participant data viztask.returnValue(data)
def TrialTask(): """Task for individual trial. Returns whether BOMB was found.""" # Flash screen FlashScreen() # Wait until BOMB is found or time runs out wait_time = viztask.waitTask(TrialCountDownTask()) wait_find = vizproximity.waitEnter(sensor) #print wait_find wait_find2 = vizproximity.waitEnter(sensor2) wait_find3 = vizproximity.waitEnter(sensor3) wait_find4 = vizproximity.waitEnter(sensor4) wait_find5 = vizproximity.waitEnter(sensor5) wait_find6 = vizproximity.waitEnter(sensor6) wait_find7 = vizproximity.waitEnter(sensor7) data = yield viztask.waitAny([ wait_time, wait_find, wait_find2, wait_find3, wait_find4, wait_find5, wait_find6, wait_find7 ]) if data.condition == wait_find: manager.removeSensor(sensor) elif data.condition == wait_find2: manager.removeSensor(sensor2) elif data.condition == wait_find3: manager.removeSensor(sensor3) elif data.condition == wait_find4: manager.removeSensor(sensor4) elif data.condition == wait_find5: manager.removeSensor(sensor5) elif data.condition == wait_find6: manager.removeSensor(sensor6) elif data.condition == wait_find7: manager.removeSensor(sensor7) # Return whether bomb was found viztask.returnValue( data.condition is wait_find or data.condition is wait_find2 or data.condition is wait_find3 or data.condition is wait_find4 or data.condition is wait_find5 or data.condition is wait_find6 or data.condition is wait_find7)
def cross_block(list_of_trials,training=False): # keep track of trial results results = [] successes = 0 block_text.message("DEADLINE: %.2f"%list_of_trials[0][2]) vizact.ontimer2(rate=MESSAGE_TIME, repeats=0,func=clear_text) # Loop over the rest of the trials for trial in list_of_trials[1:]: res = yield cross_trial(*trial,training=training) results.append(res) successes += results[-1]["success"] # Display successes at the end yield end_block(successes,len(list_of_trials)) yield viztask.waitTime(4) # Clear the message block_text.message("") viztask.returnValue( results )
def participantInfo(): info.visible(viz.OFF) participantInfo = vizinfo.InfoPanel('',title='Participant Information',align=viz.ALIGN_CENTER, icon=False) textbox_last = participantInfo.addLabelItem('Last Name',viz.addTextbox()) textbox_first = participantInfo.addLabelItem('First Name',viz.addTextbox()) textbox_id = participantInfo.addLabelItem('ID',viz.addTextbox()) participantInfo.addSeparator(padding=(20,20)) submitButton = participantInfo.addItem(viz.addButtonLabel('Submit'),align=viz.ALIGN_RIGHT_CENTER) yield viztask.waitButtonUp(submitButton) data = viz.Data() data.lastName = textbox_last.get() data.firstName = textbox_first.get() data.id = textbox_id.get() participantInfo.remove() viztask.returnValue(data)
def participantInfo(): manager.setDebug(viz.OFF) debugEventHandle.setEnabled(viz.OFF) # Hide info panel currently displayed info.visible(viz.OFF) # Add an InfoPanel with a title bar participantInfo = vizinfo.InfoPanel("", title="Participant Information", align=viz.ALIGN_CENTER, icon=False) # Add name and ID fields textbox_last = participantInfo.addLabelItem("Last Name", viz.addTextbox()) textbox_first = participantInfo.addLabelItem("First Name", viz.addTextbox()) textbox_id = participantInfo.addLabelItem("ID", viz.addTextbox()) participantInfo.addSeparator(padding=(20, 20)) # Add gender and age fields radiobutton_male = participantInfo.addLabelItem("Male", viz.addRadioButton(0)) radiobutton_female = participantInfo.addLabelItem("Female", viz.addRadioButton(0)) droplist_age = participantInfo.addLabelItem("Age Group", viz.addDropList()) ageList = ["20-30", "31-40", "41-50", "51-60", "61-70"] droplist_age.addItems(ageList) participantInfo.addSeparator() # Add submit button aligned to the right and wait until it's pressed submitButton = participantInfo.addItem(viz.addButtonLabel("Submit"), align=viz.ALIGN_RIGHT_CENTER) yield viztask.waitButtonUp(submitButton) # Collect participant data data = viz.Data() data.lastName = textbox_last.get() data.firstName = textbox_first.get() data.id = textbox_id.get() data.ageGroup = ageList[droplist_age.getSelection()] if radiobutton_male.get() == viz.DOWN: data.gender = "male" else: data.gender = "female" participantInfo.remove() # Return participant data viztask.returnValue(data)
def participantInfo(): #Turn off visibility of proximity sensors and disable toggle manager.setDebug(viz.OFF) debugEventHandle.setEnabled(viz.OFF) #Hide info panel currently displayed info.visible(viz.OFF) #Add an InfoPanel with a title bar participantInfo = vizinfo.InfoPanel('',title='Participant Information',align=viz.ALIGN_CENTER, icon=False) #Add name and ID fields textbox_last = participantInfo.addLabelItem('Last Name',viz.addTextbox()) textbox_first = participantInfo.addLabelItem('First Name',viz.addTextbox()) textbox_id = participantInfo.addLabelItem('ID',viz.addTextbox()) participantInfo.addSeparator(padding=(20,20)) #Add gender and age fields radiobutton_male = participantInfo.addLabelItem('Male',viz.addRadioButton(0)) radiobutton_female = participantInfo.addLabelItem('Female',viz.addRadioButton(0)) droplist_age = participantInfo.addLabelItem('Age Group',viz.addDropList()) ageList = ['20-30','31-40','41-50','51-60','61-70'] droplist_age.addItems(ageList) participantInfo.addSeparator() #Add submit button aligned to the right and wait until it's pressed submitButton = participantInfo.addItem(viz.addButtonLabel('Submit'),align=viz.ALIGN_RIGHT_CENTER) yield viztask.waitButtonUp(submitButton) #Collect participant data data = viz.Data() data.lastName = textbox_last.get() data.firstName = textbox_first.get() data.id = textbox_id.get() data.ageGroup = ageList[droplist_age.getSelection()] if radiobutton_male.get() == viz.DOWN: data.gender = 'male' else: data.gender = 'female' participantInfo.remove() # Return participant data viztask.returnValue(data)
def testPhase(): results = [] trials = [3,2,0,4,1] for i in trials: #Check to see if participant is already in room center. If not #wait until the centerSensor is activated if centerSensor not in manager.getActiveSensors(): yield vizproximity.waitEnter(centerSensor) #Get sensor for this trial sensor = sphereSensors[i] #Instruct participant where to go instruction = 'Walk to the {} sphere'.format(sensor.name) info.setText(instruction) #store the time at which this trial started startTime = viz.tick() #The yielded command returns a viz.Data object with information #about the proximity event such as the sensor, target involved yield vizproximity.waitEnter(sensor) info.setText('Please return to the center of the room') #calculate the time it took for the subject to find the correct object elapsedTime = viz.tick() - startTime #save results results.append((sensor.name, elapsedTime)) info.setText('Thank You. You have completed the experiment') #return results viztask.returnValue(results)
def runSetOfTrials(): global data global collided global positionList global hitPosition collided = False viz.callback( viz.COLLIDE_BEGIN_EVENT, onCollide ) positions = createPositions() move = vizact.ontimer(0, UpdateMovement) variances = [] accuracys = [] for i in positions: data = "" positionList = [] logger.newTrial() environment.point.setPosition(0,parameters.point_height,0) if i == 0: [x,z] = polar2cartesian(parameters.radialCoordinate, parameters.angularCoordinate1) elif i == 1: [x,z] = polar2cartesian(parameters.radialCoordinate, parameters.angularCoordinate2) elif i == 2: [x,z] = polar2cartesian(parameters.radialCoordinate, parameters.angularCoordinate3) elif i == 3: [x,z] = polar2cartesian(parameters.radialCoordinate, parameters.angularCoordinate4) print [x,z] environment.goal.setPosition(x, parameters.goal_height,z) data += ( "\nGoal Position: " + str(environment.goal.getPosition())) #enable joystick movement environment.point.visible(viz.ON) environment.goal.visible(viz.ON) if parameters.dreiDEnvironment: environment.shadow.visible(viz.ON) if (parameters.training or parameters.intro): environment.arrow.visible(viz.ON) environment.thrust.disable() move.setEnabled(viz.ON) #wait till key is pressed let object fall down yield s.wait() if parameters.dreiDEnvironment: environment.shadow.visible(viz.OFF) dropPosition = environment.point.getPosition() data += ('\nDrop Position: ' + str(dropPosition)) move.setEnabled(viz.OFF) #set force on the point + no gravity [x,z] = windSpeed.computeWindForce(environment.point.getPosition()) if parameters.dreiDEnvironment: environment.thrust.setForce([x,parameters.gravity,z]) else: environment.thrust.setForce([x,0,z]) environment.thrust.enable(); #print(environment.point.getPosition()) yield viztask.waitTime(1) #show fallen object environment.thrust.disable() environment.point.setVelocity([0,0,0]) yield viztask.waitTime(1) #save hit position use global hit position if 3D based on collision or get last position of point in 2d if not parameters.dreiDEnvironment: hitPosition = environment.point.getPosition() data+= '\nHit Position: ' + str(hitPosition) #compute statistics accuracy = statistics.computeAccuracy(hitPosition, environment.goal.getPosition()) variance = statistics.computeVariance(dropPosition, positionList) data+= '\nAccuracy: ' + str(accuracy) data+= '\nVariance: ' + str(variance) #make point invisible wait and start next trial environment.point.visible(viz.OFF) environment.goal.visible(viz.OFF) if (parameters.training or parameters.intro): environment.arrow.visible(viz.OFF) yield viztask.waitTime(1) parameters.trialNumber+= 1 data+= "\n" + str(positionList) logger.write_logger(data) accuracys.append(accuracy) variances.append(variance) viztask.returnValue([variances,accuracys,positions.__len__()])
def cross_trial(start_time, wait_time, rt_deadline, remove, message="",training=False): """ Implements a single trial Parameters ========== start_time:float IF start_time == 0, wait for the next trigger pulse. Else, wait until start_time to begin the trial. wait_time:float time to wait until the cross should remove one of its lines rt_deadline:float if the subject did not respond more quickly than the deadline, tell them they blew it remove:str The portion of the cross to remove. Either "hbar" or "vbar". """ descr = {"onset":start_time, "duration":wait_time, "crossbar":remove} new_texture = hbar if remove == "vbar" else vbar if start_time == 0: yield vizact.waitsignal(TRIGGER_EVENT) else: while viz.tick() < start_time: yield viz.waitTime(0.01) # ---- If there's a message, display it for MESSAGE_TIME #block_text.message(message) #vizact.ontimer2(rate=MESSAGE_TIME, repeats=0,func=clear_text) # ---- Flash the cue quad.texture(cue) yield viztask.waitTime(0.5) quad.texture(cross) # ---- Wait the required time yield viztask.waitTime(wait_time) # ---- Set the new texture quad.texture(new_texture) #Wait for next frame to be drawn to screen d = yield viztask.waitDraw() #Save display time displayTime = d.time #Wait for a reaction reaction = yield viztask.waitAny( [HBAR_RESPONSE, VBAR_RESPONSE] ) time_at_response, = reaction.data.data[0] # How did they do?? # -> Hbar remains if reaction.condition is HBAR_RESPONSE: descr["acc_success"] = remove == "vbar" response = "hbar" # -> vbar remains if reaction.condition is VBAR_RESPONSE: descr["acc_success"] = remove == "hbar" response = "vbar" # print "removed:", remove,"responded:",response # Calculate reaction time reactionTime = time_at_response - displayTime descr["speed_success"] = reactionTime < rt_deadline success = descr["speed_success"] and descr["acc_success"] # What sort of feedback to give? #if training: # In training blocks, show the rt #yield training_display(reactionTime,descr["acc_success"]) #else: if success: yield success_display(reactionTime) else: failtype = "WRONG" if descr["speed_success"] else "TIMEOUT" yield fail_display(failtype, reactionTime) quad.texture(cross) descr["response"] = response descr["success"] = success descr["rt"] = reactionTime descr["rt_deadline"]= rt_deadline descr["changetime"] = d.time viztask.returnValue(descr)
def multitrial(): results = [] blocks = create_full_experiment([0.3, 0.2, 0.4, 0.5]) for block in blocks: results += yield cross_block(block,training=True) viztask.returnValue(results)
def participant_info(): """ Query the participant for basic data. Questions to select experimental condition and control type of the experimental condition. Returns: the queried data as a viz.data object """ participant_info = vizinfo.InfoPanel('', title='Participant Information', align=viz.ALIGN_CENTER, icon=False) # query control style droplist; Create a drop-down list drop_control_style = participant_info.addLabelItem('Choose control style', viz.addDropList()) items = ['dk2 head & right hand', 'mouse and keyboard'] # 'mouse and keyboard', 'joystick', 'dk2 head only', 'dk2 head wiimote', drop_control_style.addItems(items) # Add name and ID fields of maze configurations drop_maze_config = participant_info.addLabelItem('Choose maze configuration', viz.addDropList()) items2 = ['auto', 'baseline', 'training', 'I', 'L', 'Z', 'U']#, 'T', '+'] # Add a list of items. drop_maze_config.addItems(items2) # Add name and ID fields of experimental condition drop_maze_run = participant_info.addLabelItem('Choose maze run', viz.addDropList()) items2 = ['auto', '1', '2', '3'] drop_maze_run.addItems(items2) participant_info.addSeparator(padding=(10, 10)) textbox_id = participant_info.addLabelItem('ID', viz.addTextbox()) textbox_age = participant_info.addLabelItem('Age', viz.addTextbox()) textbox_handedness = participant_info.addLabelItem('Handedness', viz.addTextbox()) textbox_vision = participant_info.addLabelItem('Vision', viz.addTextbox()) textbox_cap_size = participant_info.addLabelItem('Cap size', viz.addTextbox()) textbox_neck_size = participant_info.addLabelItem('Neck size', viz.addTextbox()) textbox_labelscheme = participant_info.addLabelItem('Electrode Labelscheme', viz.addTextbox()) participant_info.addSeparator(padding=(10, 10)) # Add gender and age fields radiobutton_male = participant_info.addLabelItem('Male', viz.addRadioButton(2)) radiobutton_female = participant_info.addLabelItem('Female', viz.addRadioButton(2)) participant_info.addSeparator(padding=(10, 10)) # Add submit button aligned to the right and wait until it's pressed submit_button = participant_info.addItem(viz.addButtonLabel('Submit'), align=viz.ALIGN_CENTER) yield viztask.waitButtonUp(submit_button) # Collect participant data data = viz.Data() data.id = textbox_id.get() data.age = textbox_age.get() data.handedness = textbox_handedness.get() data.vision = textbox_vision.get() data.cap_size = textbox_cap_size.get() data.neck_size = textbox_neck_size.get() data.labelscheme = textbox_labelscheme.get() if radiobutton_male.get() == viz.DOWN: data.sex = 'male' else: data.sex = 'female' # Find the index of the current selection. Find the selection itself. data.control_style = drop_control_style.getItems()[drop_control_style.getSelection()] data.maze_config = drop_maze_config.getItems()[drop_maze_config.getSelection()] data.maze_run = drop_maze_run.getItems()[drop_maze_run.getSelection()] participant_info.remove() # Return participant data viztask.returnValue(data)
def runSetOfTrials(): global data global collided global positionList global hitPosition collided = False viz.callback(viz.COLLIDE_BEGIN_EVENT, onCollide) positions = createPositions() move = vizact.ontimer(0, UpdateMovement) variances = [] accuracys = [] for i in positions: data = "" positionList = [] logger.newTrial() environment.point.setPosition(0, parameters.point_height, 0) if i == 0: [x, z] = polar2cartesian(parameters.radialCoordinate, parameters.angularCoordinate1) elif i == 1: [x, z] = polar2cartesian(parameters.radialCoordinate, parameters.angularCoordinate2) elif i == 2: [x, z] = polar2cartesian(parameters.radialCoordinate, parameters.angularCoordinate3) elif i == 3: [x, z] = polar2cartesian(parameters.radialCoordinate, parameters.angularCoordinate4) print[x, z] environment.goal.setPosition(x, parameters.goal_height, z) data += ("\nGoal Position: " + str(environment.goal.getPosition())) #enable joystick movement environment.point.visible(viz.ON) environment.goal.visible(viz.ON) if parameters.dreiDEnvironment: environment.shadow.visible(viz.ON) if (parameters.training or parameters.intro): environment.arrow.visible(viz.ON) environment.thrust.disable() move.setEnabled(viz.ON) #wait till key is pressed let object fall down yield s.wait() if parameters.dreiDEnvironment: environment.shadow.visible(viz.OFF) dropPosition = environment.point.getPosition() data += ('\nDrop Position: ' + str(dropPosition)) move.setEnabled(viz.OFF) #set force on the point + no gravity [x, z] = windSpeed.computeWindForce(environment.point.getPosition()) if parameters.dreiDEnvironment: environment.thrust.setForce([x, parameters.gravity, z]) else: environment.thrust.setForce([x, 0, z]) environment.thrust.enable() #print(environment.point.getPosition()) yield viztask.waitTime(1) #show fallen object environment.thrust.disable() environment.point.setVelocity([0, 0, 0]) yield viztask.waitTime(1) #save hit position use global hit position if 3D based on collision or get last position of point in 2d if not parameters.dreiDEnvironment: hitPosition = environment.point.getPosition() data += '\nHit Position: ' + str(hitPosition) #compute statistics accuracy = statistics.computeAccuracy(hitPosition, environment.goal.getPosition()) variance = statistics.computeVariance(dropPosition, positionList) data += '\nAccuracy: ' + str(accuracy) data += '\nVariance: ' + str(variance) #make point invisible wait and start next trial environment.point.visible(viz.OFF) environment.goal.visible(viz.OFF) if (parameters.training or parameters.intro): environment.arrow.visible(viz.OFF) yield viztask.waitTime(1) parameters.trialNumber += 1 data += "\n" + str(positionList) logger.write_logger(data) accuracys.append(accuracy) variances.append(variance) viztask.returnValue([variances, accuracys, positions.__len__()])