def strippedTrialTask(avatar, turningAngle, vLinear, tLegs, idxTrial, output = {}):
	"""
	master task that invokes all other tasks as subtasks to ensure right order
	"""
	# add text for instructions
	screenText = viz.addText('trial no. '+str(idxTrial),viz.SCREEN)
	screenText.setBackdrop(viz.BACKDROP_RIGHT_BOTTOM)
	screenText.setBackdropColor(viz.GRAY)
	screenText.setPosition(0.05, 0.5)
	
	# wait for key press and execute trial
	yield viztask.waitKeyDown(' ')
	screenText.message('')
	passage = passageAction(turningAngle, vLinear, tLegs)
	avatar.addAction(passage)
	yield viztask.waitActionEnd(avatar, passage)
	
	# get homing vectors
	yield helperFunctions.saveHomingVectors(avatar, output)
	print output
	
	# post trial instructions & position reset
	yield viztask.waitTime(0.2)
	screenText.message('please select your\nanswer for trial '+str(idxTrial))
	yield viztask.waitKeyDown(' ')
	screenText.remove()
	yield helperFunctions.resetTask(avatar)
Beispiel #2
0
def experiment():
    for trialN in range(10):
        if trialN < 9:
            datafile = 'Trial0' + str(trialN + 1) + '.txt'
            respfile = 'RT_Trial0' + str(trialN + 1) + time.strftime(
                "_%d-%b-%y_%H-%M") + '.csv'
        else:
            datafile = 'Trial' + str(trialN + 1) + '.txt'
            respfile = 'RT_Trial' + str(trialN + 1) + time.strftime(
                "_%d-%b-%y_%H-%M") + '.csv'

        colors = []
        with open(datafile, 'rb') as csvfile:
            csvreader = csv.reader(csvfile, delimiter=' ')
            for row in csvreader:
                colors.append(row)
        colors = numpy.asarray(colors, dtype=uInt8)
        # colors = colors[0]

        strobes = Strobes(x, 100)
        leds = LEDs(colors, 0.05, 0.9403)
        vizact.onkeydown('.', leds.recordResp)

        sensor_Target = vizproximity.Sensor(
            vizproximity.RectangleArea([4, 0.1],
                                       center=[0, real_tg_dist[(-1)**trialN]]),
            None)
        manager.addSensor(sensor_Target)

        # Show where the target is and ask them to face to the target
        yield viztask.waitKeyDown('a')
        standBy = viztask.schedule(leds.standby(trialN % 2))
        # Turn of the LED to get the experiment ready to start
        yield viztask.waitKeyDown('s')
        standBy.kill()
        leds.all_off()
        leds.stop()
        monitor_record_Network.send('Start!')
        strobes.StartTask()
        f = viztask.schedule(leds.flashing())
        monitor_record_Network.send('Start!')
        yield vizproximity.waitEnter(
            sensor_Target)  # flash until they enter the target zone
        f.kill()
        # Once reach the target turn off both the LEDs and strobes
        strobes.StopTask()
        strobes.ClearTask()
        leds.all_off()
        leds.stop()
        leds.clear()
        # Save the data into a csv file
        leds.saveAsFile(respfile)
        manager.clearSensors()

    yield viztask.waitTime(10)
    viz.quit()
def practice_maze():

    # declare globals
    global coordinate_array
    global movement_time
    global maze

    # Display instructions until they are removed
    practice_instructions = viz.addText(
        'This practice session is designed to help you get used to\n using the joystick. Navigate through the hallways using\n the joystick until you are comfortable using to move.',
        viz.SCREEN)
    practice_instructions.fontSize(42)
    practice_instructions.setPosition(.5, .5)
    practice_instructions.alignment(viz.TEXT_CENTER_CENTER)
    yield viztask.waitKeyDown('m')
    practice_instructions.remove()

    # show user fixation cross
    yield display_fix()

    # setup viewpoint and positioning
    yield setup_view()

    # load the  maze
    maze_name = maze_root + '.IVE'
    maze = viz.add(maze_name)
    maze.visible(viz.OFF)
    yield maze.visible(viz.ON)

    # load coordinate_array in clear it so that previous trial data is gone
    coordinate_array = array([])

    # enable all of the global events
    joy_timer.setEnabled(viz.ON)
    coor_timer.setEnabled(viz.ON)
    write_onkey.setEnabled(viz.ON)
    quit_onkey.setEnabled(viz.ON)

    # reset and start the clock
    movement_time = TickTockTimer()
    movement_time.StartTimer()

    # stay in maze until experimenter presses a key...
    yield viztask.waitKeyDown('m')

    # disable events and quit maze
    disable()
    write_trial_data()
    maze.remove()
    def setup(self):
        self.experiment.prox.addTarget(self.experiment.leds[self.effector])

        if not os.path.isdir(self.output):
            os.makedirs(self.output)

        yield viztask.waitKeyDown(' ')
Beispiel #5
0
    def BlockProcedure(self):
        yield viztask.waitKeyDown(' ')
        yield self.experimentProcedure()
        with open('data/subject' + subject + '_run_jj' + run + '.csv',
                  'a') as f:
            wr = csv.writer(f,
                            delimiter=';',
                            lineterminator='\n',
                            quoting=csv.QUOTE_ALL)

            import itertools
            flattened = flattened = [[
                item for sublist in list for item in sublist
            ] for list in self.COM_DATA]

            #[framelist for segment in self.COM_DATA for segment in framelist in self.COM_DATA]

            print(flattened)

            for rv_data, coord_data, tcbom in zip(self.RV_DATA, flattened,
                                                  self.TCBOM):

                row = rv_data + coord_data + tcbom

                wr.writerow(row)

            print(self.RV_DATA)
            print(self.COM_DATA)
Beispiel #6
0
def froo():

		yield viztask.waitKeyDown('k')
		boxL.visible(0)
		stuff = viz.addChild('targetexplode12.osgb',pos=[-0.2,targetL,0],scale=[0.1,(targettol+0.02),0.0125])
#		stuff = viz.addChild('targetexplode10.osgb',pos=[0,2,20])
		stuff.setAnimationState(0)
    def setup(self):
        self.experiment.prox.addTarget(self.experiment.leds[self.effector])

        if not os.path.isdir(self.output):
            os.makedirs(self.output)

        yield viztask.waitKeyDown(' ')
Beispiel #8
0
def experiment():

    # Wait for spacebar to begin experiment
    yield viztask.waitKeyDown(" ")

    # Proceed through experiment phases
    participant = yield participantInfo()
    yield learnPhase()
    results = yield testPhase()

    # Log results to file
    try:
        with open(participant.id + "_experiment_data.txt", "w") as f:

            # write participant data to file
            data = "Participant ID: {p.id}\nLast Name: {p.lastName}\nFirst Name: {p.firstName}\nGender: {p.gender}\nAge: {p.ageGroup}\n\n".format(
                p=participant
            )
            f.write(data)

            # write result of each trial
            for name, time in results:
                data = "The {} trial took {:.2f} seconds\n".format(name, time)
                f.write(data)
    except IOError:
        viz.logWarn("Could not log results to file. Make sure you have permission to write to folder")
Beispiel #9
0
def mySubTask():
	while True:
		question_text.message('Do they keep dancing? (y/n)')
		d = yield viztask.waitKeyDown(['y','n'])
		if d.key == 'n':
			question_text.message('')
			return
def calibrateHand():
    if exp.optotrak:
        optoLink = viz.link(hand, m_hand)

    text_line1 = create_text2d(
        'Please put finger on physical start position\n press -space- to start calibration'
    )
    yield viztask.waitKeyDown(' ')
    text_line1.message("Calibration in progress")
    #collect samples
    samples = []
    old_sample = m_hand.getPosition()
    samples.append(old_sample)
    while len(samples) < 100:
        new_sample = m_hand.getPosition()
        if not (new_sample == old_sample):
            samples.append(new_sample)
            old_sample = new_sample
        yield viz.waitTime(0.001)
    check_position = np.mean(samples, axis=0)

    position_offset = np.array(exp.start_pos) - np.array(check_position)
    print position_offset
    hand0 = optofilter.position(hand,
                                offset=(position_offset[0],
                                        position_offset[1] + 0.006,
                                        position_offset[2]))
    if exp.optotrak:
        optoLink = viz.link(hand0, m_hand)
    text_line1.message("Calibration done")
    yield viz.waitTime(0.75)
    text_line1.visible(viz.OFF)
Beispiel #11
0
def doShutdownTreadmill():
    yield viztask.waitKeyDown('q')
    viz.sendEvent(STOP_TREADMILL)
    yield viztask.waitEvent(TREADMILL_STOPPED)
    print "pause ...",
    yield viztask.waitTime(1)
    print "done"
    viz.quit()
    def recess(n=None, message=""):

        Panel = panel().draw()[0]
        Panel.visible(viz.ON)
        Panel.alpha(1)
        Panel.setText(message)
        yield viztask.waitKeyDown('c')
        Panel.remove()
def CanvasButtonTask(canvas):
	while True:
		yield viztask.waitKeyDown(' ')
		canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.DOWN)
		print 'mouse down'
		yield viztask.waitKeyUp(' ')
		canvas.sendMouseButtonEvent(viz.MOUSEBUTTON_LEFT, viz.UP)
		print 'mouse up'
Beispiel #14
0
def showMessage(msg):
	"""	Show a message in the virtual environment until keypress """
	
	message = vizinfo.InfoPanel(msg, align=viz.ALIGN_CENTER_CENTER, fontSize=22, icon=False, key=None)
	message.setPosition(.5, .5, mode=viz.RELATIVE)
	#hmd.addWindowMessage(message)
	yield viztask.waitKeyDown(' ')
	message.remove()
Beispiel #15
0
def WaitForTrig(Quick):

	if Quick!=1:
		viz.MainWindow.setScene(4)
		#wait for trigger
		message= 'Run ' + str(runNum) +', waiting for T'
		waitT = viz.addText(message,viz.SCREEN,scene=4)
		waitT.fontSize(18)
		waitT.color(viz.RED)
		waitT.setPosition([0,0,0])
		waitT.visible(1)
		yield viztask.waitKeyDown(['s','S']) #trigger
		waitT.visible(0)
		startTime = time.clock()

	else: 
		yield viztask.waitKeyDown(['s','S']) #trigger
Beispiel #16
0
def MainTask():
    """Top level task that controls the game"""

    # Display instructions and wait for key press to continue
    yield DisplayInstructionsTask()

    # Create panel to display trial results
    resultPanel = vizinfo.InfoPanel("", align=viz.ALIGN_CENTER, fontSize=25, icon=False, key=None)
    resultPanel.visible(False)

    viztask.waitDirector(getData)

    while True:

        num_trials += 1

        # Randomly choose hiding spots from list
        locations = random.sample(HIDING_SPOTS, TRIAL_COUNT)

        # Reset score
        score = 0
        UpdateScore(score)

        # Go through each position
        for pos in locations:

            # Perform a trial
            found = yield TrialTask(pos)

            # Update score and display status text
            if found:
                viz.playSound("sounds/pigeon_catch.wav")
                score += 1
                total_score += 1
                UpdateScore(score)
                tracker.runAction(vizact.spinTo(point=pos, time=0.8, interpolate=vizact.easeOutStrong))
                resultPanel.setText(TRIAL_SUCCESS)
            else:
                viz.playSound("sounds/pigeon_fly.wav")
                viztask.schedule(FadeToGrayTask())
                resultPanel.setText(TRIAL_FAIL)

            # Display success/failure message
            resultPanel.visible(True)

            # Add delay before starting next trial
            yield viztask.waitTime(TRIAL_DELAY)
            resultPanel.visible(False)

            # Disable gray effect
            gray_effect.setEnabled(False)

        viztask.waitDirector(writeScore, score)
        # Display results and ask to quit or play again
        resultPanel.setText(RESULTS.format(score, TRIAL_COUNT))
        resultPanel.visible(True)
        yield viztask.waitKeyDown(" ")
        resultPanel.visible(False)
Beispiel #17
0
def DisplayInstructionsTask():
    """Task that display instructions and waits for keypress to continue"""
    panel = vizinfo.InfoPanel(INSTRUCTIONS,align=viz.ALIGN_CENTER,fontSize=22,icon=False,key=None)
    pigeonClone = pigeon.clone(scale=[200]*3)
    pigeonClone.addAction(vizact.spin(0,1,0,45))
    pigeonClone.enable(viz.DEPTH_TEST,op=viz.OP_ROOT)
    panel.addItem(pigeonClone,align=viz.ALIGN_CENTER)
    yield viztask.waitKeyDown(' ')
    panel.remove()
Beispiel #18
0
def DisplayInstructionsTask():
    """Task that display instructions and waits for keypress to continue"""
    panel = vizinfo.InfoPanel(INSTRUCTIONS,
                              align=viz.ALIGN_CENTER,
                              fontSize=22,
                              icon=False,
                              key=None)
    yield viztask.waitKeyDown(' ')
    panel.remove()
def experiment():
    yield participantInfo()
    yield calibrate()
    yield Data()
    yield practice()
    wait_text = viz.addText3D('Please wait for instructions.',
                              pos=[-6, 1.7, 30])
    wait_text.color(0, 0, 0)
    yield viztask.waitKeyDown(viz.KEY_KP_ENTER)
    wait_text.remove()
    exp_text = viz.addText3D('Get ready to start the experiment!',
                             pos=[-6, 1.7, 30])
    exp_text.color(0, 0, 0)
    yield viztask.waitTime(2)
    exp_text.remove()
    yield Block1()
    end_block1 = viz.addText3D(
        'End of the first block of trials. Please wait for instructions.',
        pos=[-12, 1.7, 35])
    end_block1.color(0, 0, 0)
    yield viztask.waitKeyDown(viz.KEY_KP_ENTER)
    end_block1.remove()
    yield viztask.waitTime(1)
    yield view()
    start_block2 = viz.addText3D(
        'Beginning second block of trials. Please wait for instructions.',
        pos=[-12, 1.7, 35])
    start_block2.color(0, 0, 0)
    yield viztask.waitKeyDown(viz.KEY_KP_ENTER)
    start_block2.remove()
    yield viztask.waitTime(1)
    yield Block2()
    end_block2 = viz.addText3D(
        'End of the second block of trials. Please wait for instructions.',
        pos=[-12, 1.7, 35])
    end_block2.color(0, 0, 0)
    yield viztask.waitKeyDown(viz.KEY_KP_ENTER)
    end_block2.remove()
    yield viztask.waitTime(1)
    yield Block3()
    datafile.close()
    end_text = viz.addText3D('Please wait for instructions', pos=[-6, 1.7, 30])
    end_text.color(0, 0, 0)
Beispiel #20
0
    def interfaceTasks(self):
        """
		Grab and Release task. viztask was used to make grab and release dependent on the occurence of one another.
		In order for a release there must have been a grab and vice versa.
		"""
        while True:
            yield viztask.waitKeyDown(' ')
            grab(self.outlineCenter, self.dogCenter)
            yield viztask.waitKeyUp(' ')
            release(self)
Beispiel #21
0
def fileTask():
    
    yield viztask.waitKeyDown(' ')
    viz.logNotice('Started file operation')
    
    #Execute the getLast function in a separate thread
    #and wait for it to complete and return some data
    data = yield viztask.waitDirector(getLast)
    
    viz.logNotice('Finished file operation, last line is: ',data.returnValue)
    def pause(self):

        if self.current_maze is 'I':
            self.scene.change_instruction("Noch fragen?")
            print '!!! GIBT ES NOCH UNKLARHEITEN? WEITER MIT TASTE W !!!'
        else:
            self.scene.change_instruction("Pause machen?")
            print '!!! PAUSE? START NEXT MAZE WITH W KEY !!!'
        yield viztask.waitKeyDown('w')
        self.scene.hide_instruction()
Beispiel #23
0
    def interfaceTasks(self):
        """
		Grab and Release task. viztask was used to make grab and release dependent on the occurence of one another.
		In order for a release there must have been a grab and vice versa.
		"""
        while True:
            yield viztask.waitKeyDown(" ")
            grab(self.outlineCenter, self.dogCenter)
            yield viztask.waitKeyUp(" ")
            release(self)
def walking():
	yield viztask.waitKeyDown(' ')
	male.addAction(vizact.walkTo([1, 0, 0]))
	yield vizproximity.waitEnter(femaleSensor)
	female.state(3)
	yield viztask.waitTime(2)
	male.state(33)
	yield viztask.waitTime(3)
	male.addAction(vizact.walkTo([-4, 0, 0], walkAnim = 70, walkSpeed = 2))
	yield vizproximity.waitExit(femaleSensor)
	female.state(8)
def expertise_maze():

    # setup viewpoint and positioning
    yield setup_view()

    # declare globals
    global signal
    global collide_coords
    global movement_time
    global coordinate_array
    global maze

    # clear the coordinate array
    coordinate_array = array([])

    # Setup the objection "collision"
    signal = viztask.Signal()
    collide_coords = end_coords

    # Show instructions and wait for user signal until they are removed
    instructions = viz.addText('Please navigate to the blue wall', viz.SCREEN)
    instructions.fontSize(42)
    instructions.setPosition(.5, .5)
    instructions.alignment(viz.TEXT_CENTER_CENTER)
    yield viztask.waitKeyDown('m')
    instructions.remove()

    # show user fixation cross
    yield display_fix()

    # Load the maze
    maze_name = maze_root + '.IVE'
    maze = viz.add(maze_name)
    maze.visible(viz.OFF)
    yield maze.visible(viz.ON)

    # enable all of the global events
    joy_timer.setEnabled(viz.ON)
    coor_timer.setEnabled(viz.ON)
    write_onkey.setEnabled(viz.ON)
    quit_onkey.setEnabled(viz.ON)
    pos_timer.setEnabled(viz.ON)

    # reset and start the clock
    movement_time = TickTockTimer()
    movement_time.StartTimer()

    # wait for "collision" signal
    yield signal.wait()

    #disable and quit
    disable()
    write_trial_data()
    maze.remove()
Beispiel #26
0
def Replace():

		viz.MainWindow.setScene(1)

		#teleport to new location each trial
		x , y = pol2cart(numpy.random.randint(10,radius), numpy.random.randint(0,360))
		viz.MainView.setPosition(x,0,y) 
		viz.MainView.setEuler(numpy.random.randint(0,360),0,0)

		#wait for response
		yield viztask.waitKeyDown(['b','B'])
Beispiel #27
0
def mySubTask():
    #Until this function returns a value or is killed. . .
    while True:
        #Set the text's message.
        question_text.message( 'Do they keep dancing? (y/n)' )
        #Wait for either 'y' or 'n' key to be pressed
        d = yield viztask.waitKeyDown( ['y','n'] )
        #If the keystroke is an 'n'. . .
        if d.key == 'n':
            question_text.message('')
            #End the task.
            return
Beispiel #28
0
def myTask():
	while True:
		question_text.message('Hit the spacebar to begin.')
		yield viztask.waitKeyDown(' ')
		female.state(5)
		yield viztask.waitTime(1)
		yield viztask.addAction(male, vizact.walkTo([-1,-0,0]))
		male.state(5)
		yield mySubTask()
		male.state(9)
		yield viztask.addAction(female,vizact.animation(6))
		male.addAction( vizact.walkTo( [2,0,-1],2.5,90,11 ) )
def experiment():
	#Wait for spacebar to begin experiment
	yield viztask.waitKeyDown(' ')
	#Proceed through experiment phases
	viz.mouse.setVisible(True)
	participant = yield participantInfo()
	viz.mouse.setVisible(False)
	yield learnPhase()
	results = yield testPhase()
	
	#write participant data to file
	data = "Participant ID: {p.id}\nLast Name: {p.lastName}\nFirst Name: {p.firstName}\nGender: {p.gender}\nAge: {p.ageGroup}\n\n".format(p=participant)
	data_file.write(data)
Beispiel #30
0
    def getTargetAngle(self):
        gotAngle = 0
        
        # log trial onset
        self.trialData['trialOnset']  = viz.tick()
        
        # show pointing target
        self.info.showTargetInfo(self.cTrial, self.trialCtr+1, len(self.trials))
        
        while not gotAngle:
            keyObj = yield viztask.waitKeyDown(keys=None)
            
            if keyObj.key == ' ':
                trgAngle = viz.MainView.getEuler(viz.ABS_GLOBAL)
                print trgAngle[0]
                gotAngle = 1
                
#            if keyObj.key == 't':
#                viz.MainView.lookAt( self.cTrial.getPos('trg', 'center') )
#                self.cTrial.showBuilding('trg', 'opaque')
#                trueAngle = viz.MainView.getEuler(viz.ABS_GLOBAL)
#                print trueAngle[0]                
            
            if keyObj.key == 'q':
                self.cTrial.src.toggleTransp()
                        
        # hide buildings
        self.cTrial.hideBuildings()
        
        # hide pointing info
        self.info.resetMsg()
        
        # log trial end
        self.trialData['tChoiceMade'] = viz.tick()
        
        # log target angle
        self.trialData['measAngle'] = trgAngle[0] # measured
        
        self.refVert.lookAt( self.cTrial.getPos('trg', 'center') )
        trueAngle = self.refVert.getEuler(viz.ABS_GLOBAL)
        print "refVert: ", trueAngle[0]
        self.trialData['trueAngle'] = trueAngle[0] # ground truth
        
        # DEBUGGING
        # print self.trialData
        
        # log data
        self.logHdl.logDictData(self.trialData)
        
        # start new trial
        viztask.schedule( self.startNewTrial() )
    def execute(self):
        ''' runs the experiment procedure '''

        # 0. Warmup phase #
        if "True" in self.warmup:
            for index, scene in enumerate(self.warmupList[index]):
                if "True" in self.warmup[0]:
                    yield self.changeScene(scene)
                    # Warmup survey #
                    if self.warmupSurvey:
                        yield survey(scene, self.delay,
                                     self.warmupSurvey).changeQ("")
                    # remove scene #
                    yield self.changeScene(scene, remove=True)
            if "False" not in self.warmupMessage:
                yield self.recess(
                    "Practice stage complete, please take off the headset")

        # 1. Experimental phase #		s
        print self.stimuliList
        for index, scene in enumerate(self.stimuliList):

            yield self.changeScene(self.stimuliList[index])

            # experimental survey #
            if "True" in self.survey:
                yield survey(scene, self.delay, self.mainSurvey).changeQ("")

            else:
                yield viztask.waitKeyDown(" ")

            yield self.changeScene(scene, remove=True)

            #clear texture memory after 3 scenes#
            if index % 3 == 0:
                viz.setOption(scene, viz.FREE_TEXTURE_MEMORY_HINT)

            # 2. recess phase
            if str(index + 1) in self.recessList and index + 1 != len(
                    self.stimuliList):
                yield self.recess(
                    message=
                    "Its time to get a break, please take off your headset")

        # 3. Finale phase #
        if "True" in self.finale:
            finaleFile = os.path.join(IMAGE_PATH, "Finale.osgb")
            yield self.changeScene(finaleFile)
            panel().infoPanel(self.finaleMessage)
Beispiel #32
0
def calibrate ():
	calibration = viz.addText3D('Please take a moment to calibrate the headset',pos = [-10,(float(height)+3),25])
	calibration.color(0,0,0)
	fixation = viz.addText3D('+',pos = [0,(float(height)),10])
	fixation.color(0,0,0)
	calibration.color(0,0,0)
	adjust = viz.addText3D('Adjust the position of the headset on your face and slide',pos = [-12.5,(float(height)-2.45),25])
	adjust.color(0,0,0)
	lever = viz.addText3D('the lever under your right eye until the plus sign is in focus',pos = [-12.5,(float(height)-4),25])
	lever.color(0,0,0)
	yield viztask.waitKeyDown(viz.KEY_KP_ENTER)
	fixation.remove()
	calibration.remove()
	adjust.remove()
	lever.remove()
def learn_move():

    # declare globals
    global sub_trial_number
    global movement_time
    global trial_time

    # stop the trial timer until we are back in the maze
    trial_time.Pause()

    # disable events and turn maze off
    disable()
    write_trial_data()
    yield maze.visible(viz.OFF)

    # Display the insturctions
    instructions = viz.addText('Please follow the arrows again.', viz.SCREEN)
    instructions.fontSize(42)
    instructions.setPosition(.5, .5)
    instructions.alignment(viz.TEXT_CENTER_CENTER)
    yield viztask.waitKeyDown('m')
    yield instructions.remove()

    # show user fixation cross
    yield display_fix()

    # move the viewpoint and turn maze back on
    yield move()
    yield maze.visible(viz.ON)

    # enable events
    joy_timer.setEnabled(viz.ON)
    coor_timer.setEnabled(viz.ON)
    write_onkey.setEnabled(viz.ON)
    quit_onkey.setEnabled(viz.ON)
    pos_move_timer.setEnabled(viz.ON)
    time_timer.setEnabled(viz.ON)

    # start the clocks again
    movement_time = TickTockTimer()
    movement_time.StartTimer()
    trial_time.UnPause()

    # increase the sub_trial number by 1
    sub_trial_number = sub_trial_number + 1
def run_tasks():
    global pickle_path
    global tbox, message, numtrials, test_fov, test_timeline

    # load path set from file
    unpicklefile = open(pickle_path, "r")
    pg = pickle.load(unpicklefile)
    unpicklefile.close()

    newPg = PathGenerator()

    # show space bar message
    tbox.message("Press space to start")

    # for each trial
    for i in range(0, numtrials):

        d = viz.Data()

        # wait for space bar
        yield viztask.waitKeyDown(("y", "n"), d)

        if d.key == "y":
            newPg.pathSets.append(pg.pathSets[i])
            file = open("SavedPaths", "w")
            pickle.dump(newPg, file)
            file.close()

            # hide message box
        tbox.visible(viz.OFF)

        # set up variables for this condition
        environment_setup.setARfov(test_fov)

        # run the path set
        if d.key != "s":
            yield pg.runExperimentPathSet(i, test_timeline)

            # show trial over message
        tbox.visible(viz.ON)
        tbox.message("Trial %d Over" % (i + 1))

        # show done message
    tbox.message("Done!")
Beispiel #35
0
def DisplayInstructionsTask():
    global male2
    global revealSelf
    global manChase

    """Task that display instructions and waits for keypress to continue"""
    panel = vizinfo.InfoPanel(INSTRUCTIONS,align=viz.ALIGN_CENTER,fontSize=22,icon=False,key=None)
    pigeonClone = pigeon.clone(scale=[200]*3)
    pigeonClone.addAction(vizact.spin(0,1,0,45))
    pigeonClone.enable(viz.DEPTH_TEST,op=viz.OP_ROOT)
    panel.addItem(pigeonClone,align=viz.ALIGN_CENTER)
    d = yield viztask.waitMouseDown(None)
    panel.remove()
    if d.button == viz.MOUSEBUTTON_RIGHT:
        revealSelf = True
    if d.button == viz.MOUSEBUTTON_MIDDLE:
        manChase = True
    panel = vizinfo.InfoPanel("PRESS SPACE TO BEGIN THE HUNT",align=viz.ALIGN_CENTER,fontSize=22,icon=False,key=None)
    yield viztask.waitKeyDown(' ')
    panel.remove()
Beispiel #36
0
def StartDemo(env, wait):
    a = env
    sky.visible(viz.ON)
    env = viz.addEnvironmentMap(IMAGE_PATH + '/' + env)
    sky.texture(env)
    Panelvisible(Panel, 0)
    yield viztask.waitTime(4)
    sky.visible(viz.OFF)
    yield changeQ(a, IntroQ, 0, "", breakQ=True)
    if wait:
        Panelvisible(Panel, 1)
        Panel.setText("Warmup stage complete! Please take off your headset ")
        rowBottom.visible(viz.OFF)
        maxNumber.visible(viz.OFF)
        yield viztask.waitKeyDown('c')
        #yield viztask.waitAny([waitButton2],d)
        #if d.condition is waitButton2:
        Panelvisible(Panel, 0)
        rowBottom.visible(viz.OFF)
        sky.visible(viz.OFF)
Beispiel #37
0
def StartRun(runNum, openMess, closeMess):

    if openMess:
        viz.MainWindow.setScene(2)
        if runNum % 2 == 0:
            con = 2
        else:
            con = 1
        Message = 'Press t to start training in Arena ' + str(con)
        #info
        info = viz.addText(Message, viz.SCREEN, scene=2)
        info.fontSize(36)
        info.color(viz.WHITE)
        info.setPosition([0.3, 0.5, 0])
        info.visible(1)

        #wait for response
        yield viztask.waitKeyDown(['t', 'T'])
        info.visible(0)
        yield viztask.waitTime(ITI - 1)
    else:
        viz.MainWindow.setScene(2)
        Message = 'Good job!'
        #info
        info = viz.addText(Message, viz.SCREEN, scene=2)
        info.fontSize(36)
        info.color(viz.WHITE)
        info.setPosition([0.4, 0.5, 0])
        info.visible(1)
        yield viztask.waitTime(ITI)
        info.visible(0)
        if closeMess:
            Message = 'Training Complete. Please get experimenter'
            #info
            info = viz.addText(Message, viz.SCREEN, scene=2)
            info.fontSize(36)
            info.color(viz.WHITE)
            info.setPosition([0.3, 0.5, 0])
            info.visible(1)
            yield viztask.waitTime(ITI)
            info.visible(0)
def crystalBallScene():
 global globeScene, crystalBall
 globeScene.enable(viz.RENDERING)
 viz.fog(0.2)
 crystalBall = globeScene.getChild('preview.osgb')
 crystalBall.alpha(0.7)
 #insideCrystal = globeScene.getChild('preview2.osgb')
 crystalBall.disable(viz.RENDERING)
 #insideCrystal.disable(viz.RENDERING)
 yield fader.fadeInTask()
 #globeScene.playsound('background.wav')
 globe = globeScene.getChild('earthGlobe.OSGB')
 spinForever = vizact.spin(0,-1,0, 25, dur = viz.FOREVER)
 spinForever2 = vizact.spin(0,1,0, 20, dur = viz.FOREVER)
 spinSome = vizact.spin(0,-1,0, 30, dur=5)
 globe.addAction(spinSome)
 crystalBall.addAction(spinForever)
 #insideCrystal.addAction(spinForever2)
 yield viztask.waitTime(5)
 fadeOutGlobe = vizact.fadeTo(0, speed = .7)
 globe.addAction(fadeOutGlobe)
 crystalBall.enable(viz.RENDERING)
 #insideCrystal.enable(viz.RENDERING)
 yield viztask.waitTime(1)
 globe.remove()
 manager = vizproximity.Manager()
 manager.setDebug(False) #make true to see the outline of the proximity sensor
 rightHandTarget = vizproximity.Target(globals_oa.rightHand)
 leftHandTarget = vizproximity.Target(globals_oa.leftHand)
 ballSensor = vizproximity.Sensor(vizproximity.Sphere(1.5, center=[0,5.5,0]), source=crystalBall)
 manager.addTarget(rightHandTarget)
 manager.addTarget(leftHandTarget)
 manager.addSensor(ballSensor)
 #yield vizproximity.waitEnter(ballSensor)
 yield viztask.waitKeyDown('/')
 globals_oa.AUDIO_SUCCESS.play()
 yield fader.fadeOutTask()
 globeScene.remove()
 crystalBall.remove()
Beispiel #39
0
def myTask():
    #As long as the task is running . . .
    while True:
        question_text.message( 'Hit the spacebar to begin.' )
        #Wait for a keypress.
        yield viztask.waitKeyDown( ' ' )
        #Animate the female.
        female.state( 5 )
        #Wait for a second.
        yield viztask.waitTime( 1 )
        #Make the male walk and wait for him to finish the action.
        yield viztask.addAction( male,  vizact.walkTo( [-1,0,0] ) )
        #Make the male dance.
        male.state( 5 )
        #Wait for a sub task to finish.
        yield mySubTask()
        #Give the male a new animation.
        male.state(9)
        #Give the female a new animation and wait for it to finish.
        yield viztask.addAction( female, vizact.animation(6) )
        #Make the male run.
        male.addAction( vizact.walkTo( [2,0,-1],2.5,90,11 ) )
Beispiel #40
0
def talk() :
	while True:
		yield viztask.waitKeyDown('1')
		yield viztask.addAction(avatar, vizact.animation(65))
		yield viztask.addAction(cat, vizact.animation(3))
		if i < 10:
			numberString = '00' + numberString
		elif i < 100:
			numberString = '0' + numberString
		co2 = globals_oa.boat.getChild("Plane" + numberString, viz.CHILD_REPLACE_TRANSFORM)
#		co2.disable(viz.LIGHTING)
		effect = vizfx.addLightingModel(diffuseRamp=rampTexture)
		co2.apply(effect)
		ambient = vizfx.addAmbientEffect(color=viz.WHITE)
		co2.apply(ambient)
		if i % 3:
			co2.disable(viz.ANIMATIONS)
	
	bigCO2.enable(viz.RENDERING)
	
skipKey = viztask.waitKeyDown('-')

def h2co3FormationTriggerEvent(e):
	global rightHandTarget, leftHandTarget, bubble
	print "Forming H2CO3 now!!!"
	bubble.disable(viz.RENDERING)
	if e.target == rightHandTarget:
		vizact.ontimer2(0.004, 25, vibrateHandController, 2)
	elif e.target == leftHandTarget:
		vizact.ontimer2(0.004, 25, vibrateHandController, 1)
	viztask.schedule(H2CO3formation())
#	yield viz.waitTime(2)
#	globals_oa.BOAT_SCENE2.play()
#	yield viztask.waitAny([viztask.waitMediaEnd(globals_oa.BOAT_SCENE2), skipKey])

def flyingCO2():
 def setup(self):
     if not os.path.isdir(self.output):
         os.makedirs(self.output)
     vrlab.sounds.gong.play()
     yield viztask.waitKeyDown(' ')
def run_tasks():
	global tbox, message, numtrials, results, conditions, participantNumber, resultsPath
	#sys.exit()
	ls = latinSquare.LatinSquare(numtrials)
	order = ls.getOrder(participantNumber % numtrials)
	#order[0]=0# temporary debug
	#print "order:",order
	#for i in xrange(numtrials):
	#	print ls.getOrder(i)
	#sys.exit()
	
	#for i in xrange(numtrials):
	#	print conditions[order[i]].fov
	#	print conditions[order[i]].myDeadLength
	
	# load path set from file
	unpicklefile = open('pathGen67130', 'r')
	pg = pickle.load(unpicklefile)
	unpicklefile.close()

	# show space bar message
	tbox.message("Press space to start")

	#resultsfile = open(resultsPath,'a')
	#resultsfile.write("%d\n"%participantNumber)
	#resultsfile.close()

	# for each trial
	for i in range(0,numtrials):
		
		# wait for space bar
		yield viztask.waitKeyDown(' ')

		# hide message box
		tbox.visible(viz.OFF)

		# set up variables for this condition
		environment_setup.setARfov( conditions[order[i]].fov )
		
		# run the path set
		yield pg.runExperimentPathSet(27+order[i],conditions[order[i]])
		
		# append the results
		# results.append([ncorrect, nfalsepos, nfalseneg])
		results.append( pg.errlist )
		print pg.errlist
		
		# show trial over message
		tbox.visible(viz.ON)
		tbox.message("Trial %d Over"%(i+1))
		#print "Result: fov, latency, ncorrect, nfalsepos, nfalseneg"
		#print conditions[i] +results[i]
		
		# open results file
		resultsfile = open(resultsPath,'a')

		# this is amazing and secret
		resultsfile.write("%d, "%participantNumber)
		resultsfile.write("%d, "%conditions[order[i]].fov)
		resultsfile.write("%d, "%conditions[order[i]].myDeadLength)
		for err in pg.errlist:
		    resultsfile.write("%f, "%err)
		resultsfile.write('\n')
		resultsfile.write(",,,")
		for time in pg.timelist:
		    resultsfile.write("%f, "%time)
		resultsfile.write('\n')
	
		# close results file
		# using close command
		# resultsfile.close() <-- like this
		resultsfile.close()

	# show done message
	tbox.message("Done!")
def Block3():
    datafile.write('\n')
    datafile.write('Block3')
    global dum3
    if dum == 2.5 and dum2 == 3.5:
        dum3 = 38
    if dum == 2.5 and dum2 == 38:
        dum3 = 3.5
    if dum == 3.5 and dum2 == 2.5:
        dum3 = 38
    if dum == 3.5 and dum2 == 38:
        dum3 = 2.5
    if dum == 38 and dum2 == 2.5:
        dum3 = 3.5
    if dum == 38 and dum2 == 3.5:
        dum3 = 2.5
    targets = [
        4.8, 6.2, 7.6, 9, 10.4, 11.8, 13.2, 14.6, 17.4, 20.2, 23, 25.8, 30,
        float(dum3),
        float(dum3)
    ]
    while len(targets) > 0:
        global k
        k = 0
        yield viztask.waitTime(.5)
        ready_text = viz.addText3D('Get ready!', pos=[-2, 1.7, 20])
        ready_text.color(0, 0, 0)
        yield viztask.waitTime(1)
        ready_text.remove()
        yield viztask.waitTime(2)
        yield room()
        doors = []
        D1 = random.choice([-4.25, -3.25, -2.25, -1.25])
        D2 = random.choice([4.75, 5.75, 6.75, 7.75])
        D3 = random.choice([13.75, 14.75, 15.75, 16.75])
        D4 = random.choice([22.75, 23.75, 24.75, 25.75])
        D5 = random.choice([31.75, 32.75, 33.75, 34.75])
        L_doors = []
        L_doors.append(D1)
        L_doors.append(D2)
        L_doors.append(D3)
        L_doors.append(D4)
        L_doors.append(D5)
        D7 = random.choice([-4.25, -3.25, -2.25, -1.25])
        D8 = random.choice([4.75, 5.75, 6.75, 7.75])
        D9 = random.choice([13.75, 14.75, 15.75, 16.75])
        D10 = random.choice([22.75, 23.75, 24.75, 25.75])
        D11 = random.choice([31.75, 32.75, 33.75, 34.75])
        R_doors = []
        R_doors.append(D7)
        R_doors.append(D8)
        R_doors.append(D9)
        R_doors.append(D10)
        R_doors.append(D11)
        people = []
        P1 = random.choice([-3.75, -2.75, -1.75, .75, 1.75, 2.75, 3.75, 5.25])
        P2 = random.choice(
            [9.25, 10.25, 11.25, 12.25, 18.25, 19.25, 20.25, 21.25])
        P3 = random.choice(
            [27.25, 28.25, 29.25, 30.25, 36.25, 37.25, 38.25, 39.25])
        L_people = []
        L_people.append(P1)
        L_people.append(P2)
        L_people.append(P3)
        P4 = random.choice([-3.75, -2.75, -1.75, .75, 1.75, 2.75, 3.75, 5.25])
        P5 = random.choice(
            [9.25, 10.25, 11.25, 12.25, 18.25, 19.25, 20.25, 21.25])
        P6 = random.choice(
            [27.25, 28.25, 29.25, 30.25, 36.25, 37.25, 38.25, 39.25])
        R_people = []
        R_people.append(P4)
        R_people.append(P5)
        R_people.append(P6)
        targ = random.choice(targets)
        if targ == 2.5:
            size = .051006
        if targ == 3.5:
            size = .071409
        if targ == 4.8:
            size = .097932
        if targ == 6.2:
            size = .126495
        if targ == 7.6:
            size = .155059
        if targ == 9:
            size = .183622
        if targ == 10.4:
            size = .212186
        if targ == 11.8:
            size = .240749
        if targ == 13.2:
            size = .269313
        if targ == 14.6:
            size = .297876
        if targ == 17.4:
            size = .355003
        if targ == 20.2:
            size = .41213
        if targ == 23:
            size = .469257
        if targ == 25.8:
            size = .526384
        if targ == 30:
            size = .612075
        if targ == 38:
            size = .775295
        print targ
        datafile.write('\n')
        datafile.write('%f' % (targ))
        sphere = vizshape.addSphere((size), 20, 20)
        sphere.color(1.02, .444, 0)
        sphere.setPosition([0, (size), (targ)])
        shadow = vizshape.addCircle((size), 20)
        shadow.color([.05, .05, .05])
        shadow.setEuler([0, 90, 0])
        shadow.setPosition([0, .001, (targ)])
        for z in np.asarray(L_doors):
            door = vizshape.addBox(size=[.04445, 2.13, .91])
            door.texture(wood)
            door.setPosition([-4.9733, 1.065, float(z)])
            doors.append(door)
            doorknob = vizshape.addSphere(radius=.045, axis=vizshape.AXIS_X)
            doorknob.color(viz.YELLOW)
            doorknob.setPosition(-4.9396, 1, (float(z) - .3364))
            doors.append(doorknob)
        for z in np.asarray(R_doors):
            door = vizshape.addBox(size=[.04445, 2.13, .91])
            door.texture(wood)
            door.setPosition([4.9683, 1.065, float(z)])
            doors.append(door)
            doorknob = vizshape.addSphere(radius=.045, axis=vizshape.AXIS_X)
            doorknob.color(viz.YELLOW)
            doorknob.setPosition(4.9396, 1, (float(z) - .3364))
            doors.append(doorknob)
        for z in np.asarray(L_people):
            object = random.choice([1, 2, 3])
            if object == 1:
                x = random.choice([0, 90, 180])
                person = viz.addAvatar('vcc_female.cfg',
                                       euler=(float(x), 0, 0))
                person.setPosition([-4.25, 0, float(z)])
                person.state(1)
                people.append(person)
            if object == 2:
                x = random.choice([0, 90, 180])
                person = viz.addAvatar('vcc_male.cfg', euler=(float(x), 0, 0))
                person.setPosition([-4.25, 0, float(z)])
                person.state(1)
                people.append(person)
            if object == 3:
                x = random.choice([0, 90, 180])
                person = viz.addAvatar('vcc_male2.cfg', euler=(float(x), 0, 0))
                person.setPosition([-4.25, 0, float(z)])
                person.state(1)
                people.append(person)
        for z in np.asarray(R_people):
            object = random.choice([1, 2, 3])
            if object == 1:
                x = random.choice([0, 180, 270])
                person = viz.addAvatar('vcc_female.cfg',
                                       euler=(float(x), 0, 0))
                person.setPosition([4.5, 0, float(z)])
                person.state(1)
                people.append(person)
            if object == 2:
                x = random.choice([0, 180, 270])
                person = viz.addAvatar('vcc_male.cfg', euler=(float(x), 0, 0))
                person.setPosition([4.5, 0, float(z)])
                person.state(1)
                people.append(person)
            if object == 3:
                x = random.choice([0, 180, 270])
                person = viz.addAvatar('vcc_male2.cfg', euler=(float(x), 0, 0))
                person.setPosition([4.5, 0, float(z)])
                person.state(1)
                people.append(person)
        targets.remove(targ)
        en_env()
        tic = time.time()
        yield viztask.waitTime(5.5)  #Actually is closer to 5 seconds
        toc = time.time()
        mask.enable(viz.RENDERING)
        dis_env()
        sphere.remove()
        shadow.remove()
        for door in np.asarray(doors):
            door.remove()
        for person in np.asarray(people):
            person.remove()
        yield viztask.waitTime(1)
        mask.disable(viz.RENDERING)
        print toc - tic
        datafile.write(' %f' % (toc - tic))
        viz.callback(viz.KEYDOWN_EVENT, KeyEvents)
        yield viztask.waitKeyDown(viz.KEY_KP_ENTER)
        if k == 1:
            targets.append(targ)
            datafile.write(' targ missed')
def practice():
    practice_text = viz.addText3D('Practice trials', pos=[-2.5, 1.7, 20])
    practice_text.color(0, 0, 0)
    yield viztask.waitKeyDown(viz.KEY_KP_ENTER)
    practice_text.remove()
    targets = [5, 12, 24]
    while len(targets) > 0:
        global k
        k = 0
        yield viztask.waitTime(.5)
        ready_text = viz.addText3D('Get ready!', pos=[-2, 1.7, 20])
        ready_text.color(0, 0, 0)
        yield viztask.waitTime(1)
        ready_text.remove()
        yield viztask.waitTime(2)
        yield room()
        doors = []
        D1 = random.choice([-4.25, -3.25, -2.25, -1.25])
        D2 = random.choice([4.75, 5.75, 6.75, 7.75])
        D3 = random.choice([13.75, 14.75, 15.75, 16.75])
        D4 = random.choice([22.75, 23.75, 24.75, 25.75])
        D5 = random.choice([31.75, 32.75, 33.75, 34.75])
        L_doors = []
        L_doors.append(D1)
        L_doors.append(D2)
        L_doors.append(D3)
        L_doors.append(D4)
        L_doors.append(D5)
        D7 = random.choice([-4.25, -3.25, -2.25, -1.25])
        D8 = random.choice([4.75, 5.75, 6.75, 7.75])
        D9 = random.choice([13.75, 14.75, 15.75, 16.75])
        D10 = random.choice([22.75, 23.75, 24.75, 25.75])
        D11 = random.choice([31.75, 32.75, 33.75, 34.75])
        R_doors = []
        R_doors.append(D7)
        R_doors.append(D8)
        R_doors.append(D9)
        R_doors.append(D10)
        R_doors.append(D11)
        people = []
        P1 = random.choice(
            [9.25, 10.25, 11.25, 12.25, 18.25, 19.25, 20.25, 21.25])
        P2 = random.choice(
            [27.25, 28.25, 29.25, 30.25, 36.25, 37.25, 38.25, 39.25])
        L_people = []
        L_people.append(P1)
        L_people.append(P2)
        P3 = random.choice(
            [9.25, 10.25, 11.25, 12.25, 18.25, 19.25, 20.25, 21.25])
        P4 = random.choice(
            [27.25, 28.25, 29.25, 30.25, 36.25, 37.25, 38.25, 39.25])
        R_people = []
        R_people.append(P3)
        R_people.append(P4)
        targ = random.choice(targets)
        if targ == 5:
            size = .102012
        if targ == 12:
            size = .24483
        if targ == 24:
            size = .48966
        sphere = vizshape.addSphere((size), 20, 20)
        sphere.color(1.02, .444, 0)
        sphere.setPosition([0, (size), (targ)])
        shadow = vizshape.addCircle((size), 20)
        shadow.color(
            [.05, .05, .05]
        )  #proportion of 1 for amount of each color (red, green, blue). 0,0,0 = black, 1,1,1 = white.
        shadow.setEuler([0, 90, 0])
        shadow.setPosition([0, .001, (targ)])
        for z in np.asarray(L_doors):
            door = vizshape.addBox(size=[.04445, 2.13, .91])
            door.texture(wood)
            door.setPosition([-4.9733, 1.065, float(z)])
            doors.append(door)
            doorknob = vizshape.addSphere(radius=.045, axis=vizshape.AXIS_X)
            doorknob.color(viz.YELLOW)
            doorknob.setPosition(-4.9396, 1, (float(z) - .3364))
            doors.append(doorknob)
        for z in np.asarray(R_doors):
            door = vizshape.addBox(size=[.04445, 2.13, .91])
            door.texture(wood)
            door.setPosition([4.9683, 1.065, float(z)])
            doors.append(door)
            doorknob = vizshape.addSphere(radius=.045, axis=vizshape.AXIS_X)
            doorknob.color(viz.YELLOW)
            doorknob.setPosition(4.9396, 1, (float(z) - .3364))
            doors.append(doorknob)
        for z in np.asarray(L_people):
            x = random.choice([0, 90, 180])
            person = viz.addAvatar('vcc_female.cfg', euler=(float(x), 0, 0))
            person.setPosition([-4.25, 0, float(z)])
            person.state(1)
            people.append(person)
        for z in np.asarray(R_people):
            x = random.choice([0, 180, 270])
            person = viz.addAvatar('vcc_female.cfg', euler=(float(x), 0, 0))
            person.setPosition([4.5, 0, float(z)])
            person.state(1)
            people.append(person)
        targets.remove(targ)
        en_env()
        tic = time.time()
        yield viztask.waitTime(
            .01
        )  #this is necessary to keep the headset display on for the duration of time.sleep. Can't use time.sleep for any longer than 100 ms or so bc it pauses tracking
        time.sleep(
            .09
        )  #this is necessary to be as precise as possible in the display time. Still not perfect bc of unknown processing time of background functions
        toc = time.time()
        mask.enable(viz.RENDERING)
        dis_env()
        sphere.remove()
        shadow.remove()
        for door in np.asarray(doors):
            door.remove()
        for person in np.asarray(people):
            person.remove()
        yield viztask.waitTime(1)
        mask.disable(viz.RENDERING)
        print toc - tic
        viz.callback(
            viz.KEYDOWN_EVENT, KeyEvents
        )  #press Enter (main keyboard) if the participant misses the target and the target will be appended back into the list.
        yield viztask.waitKeyDown(viz.KEY_KP_ENTER)
        if k == 1:
            targets.append(targ)
Beispiel #46
0
def recess():
    Panelvisible(Panel, 1)
    Panel.setText("Stage 1 complete, please take off the headset")
    rowBottom.visible(viz.OFF)
    maxNumber.visible(viz.OFF)
    yield viztask.waitKeyDown('c')
Beispiel #47
0
def validation():
	'''
	Show same calibration points and compare calulated gaze point to ground truth. 
	(Displays both + angular error)
	'''
	
	# ask for the sub port
	req.send_string('SUB_PORT')
	sub_port = req.recv_string()

	# open a sub port to listen to pupil
	sub = ctx.socket(zmq.SUB)
	sub.connect("tcp://{}:{}".format(addr, sub_port))
	sub.setsockopt_string(zmq.SUBSCRIBE, u'gaze')

	# add gaze marker
	m_gaze = vizshape.addSphere(radius=sphere_size, color=viz.GREEN)
	m_gaze.disable(viz.INTERSECTION)
	if not gaze_marker_visible:
		m_gaze.disable(viz.RENDER) # invisible but phyisically present



	def get_gaze(eye_number):
		'''
		checks gaze stream for confident measures of the eye (eye_number) until it finds them
		Args:    eye_number (int): 1=left, 0=right
		Returns: [x, y] (float): normalized x and y values range [0,1]
		'''
		found_confident_val = False
		
		while found_confident_val == False:

			topic = sub.recv_string() # unused
			msg = sub.recv()
			msg = loads(msg, encoding='utf-8')
			
			confidence = msg['confidence']
			
			if msg['id'] == eye_number:
				
				if confidence > confidence_level:
				
					found_confident_val = True
					
					t = msg['timestamp'] # unused
					npx = msg['norm_pos'][0]
					npy = msg['norm_pos'][1]
					
					return [npx, npy]


	def updateGaze():	
		'''
		calls 'get_gaze function' and takes the average of two
		eyes for the normal values - they will be used to project a 
		sphere on where subjects look at
		'''
		
		# get gaze data
		norm_pos_x = np.mean([get_gaze(1)[0], get_gaze(0)[0]])
		norm_pos_y = np.mean([get_gaze(1)[1], get_gaze(0)[1]])
				
		# find the intersection and project sphere
		line = viz.MainWindow.screenToWorld([norm_pos_x, norm_pos_y])
		intersection = viz.intersect(line.begin, line.end)
		m_gaze.setPosition(intersection.point)
		
	# update cursor location on every sample		
	vizact.onupdate(viz.PRIORITY_LINKS+1, updateGaze)


	dot_norm_pos=[]
	gaze_norm_pos=[]
	ang_error = []


	yield showMessage('Zum Starten der Validierung die Leertaste drücken')
	
	for p in norm_positions:
		
		print('calibration point: ', p)
	
		norm_x = p[0]
		norm_y = p[1]
		
		first_run = True
		
		if first_run:
			
			first_run = False
		
			'''set up a plane 'right in front of user' on which we want to project the dots'''
	
			# target the current center of view
			p_line = viz.MainWindow.screenToWorld(.5, .5)
		
			# let's modify the line and call it line 2. Here we let the line end at the "depth" value
			p_line_2 = viz.Line(begin=p_line.begin, end=p_line.end, dir=p_line.dir, length=depth)
						
			# Add the plane and apply the matrix of our viewpoint to the plane
			plane = vizshape.addBox(size=[3.6, 2, .1])
			mymat = viz.MainView.getMatrix()
			plane.setMatrix(mymat)
			
			# Reposition the plane to the end of line 2
			plane.setPosition(p_line_2.end)
			plane.color([.25,.25,.25])
			plane.alpha(.95)
			
			# Lock it to user
			plane_link = viz.grab(viz.MainView, plane)
		
		
		# interpolate a line from norm values to 3d coordinates
		line = viz.MainWindow.screenToWorld([norm_x, norm_y])
		
		# find the intersection
		intersection = viz.intersect(line.begin, line.end)
		
		# place a dot (at depth level of line) 
		dot = vizshape.addSphere(radius=sphere_size)
		dot.setPosition(intersection.point)
		
		# lock dot to user
		view_link = viz.grab(viz.MainView, dot)
		
		print('ready')
		viz.playSound('beep500_200.wav')
		yield viztask.waitKeyDown(' ')
				
		for s in range(60):
			
			# get the current pupil time (pupil uses CLOCK_MONOTONIC with adjustable timebase).
			# You can set the pupil timebase to another clock and use that.
			t = get_pupil_timestamp()

			dot_norm_pos.append(p)
			gaze_norm_pos.append(viz.MainWindow.worldToScreen(m_gaze.getPosition()))

			yield viztask.waitTime(1/60.)
			print(t)
		
		dot.color(viz.RED)
		
		print('waiting for next position...')
		
		yield viztask.waitKeyDown(' ')
		
		yield dot.remove()
				
	time.sleep(2)
		
	showMessage('validation done!')
	
	for p in norm_positions:
		
		i = norm_positions.index(p)
		chunk = range(i*60, (i+1)*60)
		print(i)
		dmx = np.mean([gaze_norm_pos[x][0] for x in chunk])
		dmy = np.mean([gaze_norm_pos[y][1] for y in chunk])
		
		# interpolate a line from norm values to 3d coordinates
		line = viz.MainWindow.screenToWorld([p[0], p[1]])
		line_v = viz.MainWindow.screenToWorld([dmx, dmy])
		
		# find the intersection
		intersection = viz.intersect(line.begin, line.end)
		intersection_v = viz.intersect(line_v.begin, line_v.end)
		
		# place a dots (at depth level of line) for both ground truth and gaze point
		dot = vizshape.addSphere(radius=sphere_size)
		dot.setPosition(intersection.point)
		dot.color(viz.BLUE)
		
		dot_v = vizshape.addSphere(radius=sphere_size*0.75)
		dot_v.setPosition(intersection_v.point)
		dot_v.color(viz.YELLOW_ORANGE)
		
		# lock dots to user
		view_link = viz.grab(viz.MainView, dot)
		viel_link2 = viz.grab(viz.MainView, dot_v)
		
		# calculate angular error
		error = vizmat.AngleBetweenVector(line.dir, line_v.dir)
#		cosangle = np.dot(a,b) / (np.linalg.norm(a) * np.linalg.norm(b))
#		angle = np.arccos(cosangle)
#		error = np.degrees(angle)
		
		ang_error.append(error)
		
		print('angle is: ', error, 'for ', p)

	
	showMessage('mean angular error is: {}'.format(np.mean(ang_error)))
	
	print('mean angular error is: ', np.mean(ang_error), ' deg/ visual angle')
Beispiel #48
0
def run_tasks():
	global tbox, message, tophat, people, numtasks, random_seeds, nfalsepos, nfalseneg, ncorrect, tophatwindow, tophatclicked
	global ringbuffer_idx, ringbuffer_len
	tbox.message("Press space to start")
	for i in range(0,numtasks):
		
		yield viztask.waitKeyDown(' ')
		tbox.visible(viz.OFF)
		random.seed(random_seeds[i])
		
		nfalsepos = 0
		nfalseneg = 0
		ncorrect = 0
		tophatwindow = 0
		tophatclicked = 1
		
		setARfov( conditions[i][0] )
		ringbuffer_len = conditions[i][1]
		ringbuffer_idx = 0
		
		for j in range(0, num_av):
			people.append( a_person())
			
		tophat = a_person(1)
		people.append(tophat)
		tophat.custom_walk([[[0.1, 0, 10], 2]])#, [[-10, 0, 10], 3], [[-10, 0, -10], 4], [[10, 0, -10], 5], [[10, 0, 10], 6]])
		
		for person in people:
			viztask.schedule(person.walk_around())
			
			
		rpt = vizact.ontimer(0,reportTargetAngle)
		
		yield viztask.waitTime(45)
		results.append([ncorrect, nfalsepos, nfalseneg])
		
		vizact.removeEvent(rpt)
		vizact.removeEvent(tophat.arev)
		tophat.pointAR.remove()
		tophat.avatar.clearActions()
		tophat.avatar.remove()
		tophat.hat.remove()
		tophat.stop()
		for person in people:
			person.pointAR.remove()
			vizact.removeEvent(person.arev)
			person.avatar.clearActions()
			person.avatar.remove()
			person.stop()
			
		people = []
		tbox.visible(viz.ON)
		tbox.message("Task %d Over"%(i+1))
		print "Result: fov, latency, ncorrect, nfalsepos, nfalseneg"
		print conditions[i] +results[i]

	tbox.message("Done!")
	print "Results:"
	print "fov, latency, ncorrect, nfalsepos, nfalseneg"
	i = 0
	for r in results:
		print conditions[i] + r
		i += 1
def run_condition_one():

    # declare globals
    global collide_coords
    global movement_time
    global coordinate_array
    global trial_number
    global sub_trial_number
    global maze
    global phase
    global trial_time

    ################
    # Learning Phase#
    ################
    # phase = 'Learning'

    # setup viewpoint and positioning
    yield setup_view()

    # Setup the object for "collision"
    collide_coords = end_coords

    if phase_selection is 'Learning':
        phase = 'Learning'
        # Setup, but do not load maze
        maze_name = maze_root + 'arrows.IVE'
        maze = viz.add(maze_name)
        maze.visible(viz.OFF)

        # loop through the four learning trials
        for trial in range(1, 5):

            trial_number = trial
            sub_trial_number = 1

            # show user instructions
            instructions = viz.addText(
                'Trial ' + str(trial) + ': Please follows the arrows',
                viz.SCREEN)
            instructions.fontSize(42)
            instructions.setPosition(.5, .5)
            instructions.alignment(viz.TEXT_CENTER_CENTER)
            yield viztask.waitKeyDown('m')
            yield instructions.remove()

            # show user fixation cross
            yield display_fix()

            # load maze
            yield maze.visible(viz.ON)

            # clear coordinate_array so that previous trial data is gone
            coordinate_array = array([])

            # enable events
            joy_timer.setEnabled(viz.ON)
            coor_timer.setEnabled(viz.ON)
            write_onkey.setEnabled(viz.ON)
            quit_onkey.setEnabled(viz.ON)
            pos_move_timer.setEnabled(viz.ON)
            time_timer.setEnabled(viz.ON)

            # reset and start both the movement time and the total trial time
            movement_time = TickTockTimer()
            movement_time.StartTimer()
            trial_time = TickTockTimer()
            trial_time.StartTimer()

            # Wait until timer signal has been sent.
            yield time_signal.wait()

            # disable events and write the data
            disable()
            write_trial_data()

            # turn maze off and then move
            maze.visible(viz.OFF)
            yield move()

        # remove maze
        maze.remove()

        # Display between phase instructions
        instructions = viz.addText(
            'Please wait for the experimenter to give you more instructions.',
            viz.SCREEN)
        instructions.fontSize(42)
        instructions.setPosition(.5, .5)
        instructions.alignment(viz.TEXT_CENTER_CENTER)
        yield viztask.waitKeyDown('m')
        yield instructions.remove()

        phase = 'Testing'

    ###############
    #Testing Phase#
    ###############
    # remove the learning maze and setup testing maze

    maze_name = maze_root + 'noarrows.IVE'
    maze = viz.add(maze_name)
    maze.visible(viz.OFF)

    # loop through the three testing trials
    for trial in range(1, 4):

        trial_number = trial

        # Show instructions and wait for user signal until they are removed
        instructions = viz.addText('Please navigate to the end of the maze',
                                   viz.SCREEN)
        instructions.fontSize(42)
        instructions.setPosition(.5, .5)
        instructions.alignment(viz.TEXT_CENTER_CENTER)
        yield viztask.waitKeyDown('m')
        yield instructions.remove()

        # display fixation
        yield display_fix()

        # turn maze on
        yield maze.visible(viz.ON)

        # clear the coordinate array
        coordinate_array = array([])

        # enable events
        joy_timer.setEnabled(viz.ON)
        coor_timer.setEnabled(viz.ON)
        write_onkey.setEnabled(viz.ON)
        quit_onkey.setEnabled(viz.ON)
        pos_timer.setEnabled(viz.ON)

        # reset and start the clock
        movement_time = TickTockTimer()
        movement_time.StartTimer()

        # wait for "collision" signal
        yield signal.wait()

        # disable all timers
        disable()
        write_trial_data()

        # turn maze off and then move
        maze.visible(viz.OFF)
        if trial != 4:
            yield move()

    maze.remove()
def run_condition_two():

    # declare globals
    global collide_coords
    global movement_time
    global coordinate_array
    global trial_number
    global maze
    global phase
    global trial_object

    # setup collision destination
    collide_coords = end_coords

    ################
    #Learning Phase#
    ################
    #phase = 'Learning'

    # setup viewpoint and positioning
    yield setup_view()

    # setup maze for loading
    maze_name = maze_root + 'noarrows.IVE'
    maze = viz.add(maze_name)
    maze.visible(viz.OFF)
    if phase_selection is 'Learning':
        phase = 'Learning'
        # loop through each of the five learning phase trials
        for trial in range(1, 5):

            trial_number = trial

            # Show instructions and wait for user signal until they are removed
            instructions = viz.addText('Please explore the maze.', viz.SCREEN)
            instructions.fontSize(42)
            instructions.setPosition(.5, .5)
            instructions.alignment(viz.TEXT_CENTER_CENTER)
            yield viztask.waitKeyDown('m')
            instructions.remove()

            # show user fixation cross
            yield display_fix()

            # turn maze on
            yield maze.visible(viz.ON)

            # load coordinate_array in clear it so that previous trial data is gone
            coordinate_array = array([])

            # enable events
            joy_timer.setEnabled(viz.ON)
            coor_timer.setEnabled(viz.ON)
            write_onkey.setEnabled(viz.ON)
            quit_onkey.setEnabled(viz.ON)
            pos_timer.setEnabled(viz.ON)

            # reset and start the clock
            movement_time = TickTockTimer()
            movement_time.StartTimer()

            # Wait for trial to expire
            yield viztask.waitTime(300)
            # yield viztask.waitTime(420)

            # disable all timers
            disable()
            write_trial_data()

            # turn maze off and then move
            maze.visible(viz.OFF)
            # if trial != 3:
            if trial != 5:
                yield move()

        # Display between phase instructions
        instructions = viz.addText(
            'Please wait for the experimenter to give you more instructions.',
            viz.SCREEN)
        instructions.fontSize(42)
        instructions.setPosition(.5, .5)
        instructions.alignment(viz.TEXT_CENTER_CENTER)
        yield viztask.waitKeyDown('m')
        yield instructions.remove()

        phase = 'Testing'

    ###############
    #Testing Phase#
    ###############

    # setup maze start and end locations for each maze
    if maze_root == 'C:\Experiments\Bike_Extend_Pilot\SNAP\SNAPMazeA':
        # setup start location dictionary {Start Location:((Start Coordinates),(Start Orientation)),...}
        start_dic = {
            'A': ((-1049, 40, 1530), (0, 0, 0)),
            'B': ((675, 40, 1814), (-90, 0, 0)),
            'C': ((110, 40, 678), (0, 0, 0)),
            'D': ((-725, 40, 2155), (-90, 0, 0)),
            'E': ((0, 40, 0), (0, 0, 0)),
            'F': ((-1040, 0, 670), (-180, 0, 0))
        }
        # setup object list (Object,Start Location,End Coordinates)
        objects = (('Table', 'C', (-710, -664, 669, 769)),
                   ('Chair', 'A', (397, 464, 1784, 1849)),
                   ('Round Stool', 'F', (148, 174, 1445, 1480)),
                   ('Rug', 'E', (-312, -259, 1060, 1130)),
                   ('Mirror', 'B', (-330, 259, 730, 755)),
                   ('Wooden Basket', 'A', (-1070, -994, 361,
                                           433)), ('Bench with cushions', 'B',
                                                   (-316, -194, 1784, 1827)),
                   ('Coat Rack', 'D', (-675, -645, 890,
                                       945)), ('Wooden Chest', 'E',
                                               (-1071, -1032, 1170, 1850)),
                   ('Potted Plant', 'F',
                    (-6, 40, 206, 260)), ('TV', 'D', (113, 149, 1013, 1111)),
                   ('Curtains', 'C', (-1070, -1022, 1518, 1538)))
    elif maze_root == 'C:\Experiments\Bike_Extend_Pilot\SNAP\SNAPMazeB':
        # setup start location dictionary {Start Location:((Start Coordinates),(Start Orientation)),...}
        start_dic = {
            'A': ((-1835, 40, 1100), (0, 0, 0)),
            'B': ((12, 40, -10), (0, 0, 0)),
            'C': ((-1114, 40, 2151), (-180, 0, 0)),
            'D': ((-1835, 40, 545), (-180, 0, 0)),
            'E': ((-1255, 40, 323), (-90, 0, 0)),
            'F': ((410, 40, 737), (-90, 0, 0))
        }
        # setup object list (Object,Start Location,End Coordinates)
        objects = (('Purple Chair', 'C', (-223, -165, 1030, 1080)),
                   ('Round Table', 'E', (-381, -277, 282, 358)),
                   ('Fireplace', 'B', (-1873, -1854, 289, 371)),
                   ('Long Table', 'A', (-1058, -951, 634, 669)),
                   ('Dining Chair', 'F', (-854, -826, 1003,
                                          1048)), ('Wall Lamp', 'E',
                                                   (-1856, -1802, 1057, 1080)),
                   ('Window', 'F', (-1519, -1440, 1410,
                                    1433)), ('Umbrella Stand', 'D',
                                             (-678, -628, 681,
                                              715)), ('Vase', 'A', (-19, 46,
                                                                    -57, -10)),
                   ('Cabinet with Dishes', 'B',
                    (-1290, -1251, 1019,
                     1201)), ('Floor Lamp', 'D',
                              (-817, -772, 1435,
                               1491)), ('Rug', 'C', (-1600, -1510, 667, 715)))
    elif maze_root == 'C:\Experiments\Bike_Extend_Pilot\SNAP\SNAPMazeC':
        # setup start location dictionary {Start Location:((Start Coordinates),(Start Orientation)),...}
        start_dic = {
            'A': ((788, 0, 110), (0, 0, 0)),
            'B': ((2064, 0, 995), (180, 0, 0)),
            'C': ((110, 0, 1050), (90, 0, 0)),
            'D': ((100, 0, -47), (90, 0, 0)),
            'E': ((700, 0, 2100), (180, 0, 0)),
            'F': ((950, 0, 1714), (90, 0, 0))
        }
        # setup object list (Object,Start Location,End Coordinates)
        objects = (('Aquarium', 'A', (370, 450, 1795, 1850)),
                   ('Basket', 'B', (790, 830, 455, 500)),
                   ('Playset', 'C', (90, 185, 2035, 2120)),
                   ('Dartboard', 'D', (2020, 2120, 365, 430)),
                   ('Ladder', 'E', (1650, 1700, 850, 900)), ('Bench', 'F',
                                                             (1220, 1320, 1060,
                                                              1100)),
                   ('Speaker', 'B', (730, 765, 1160, 1235)), ('Lawnmower', 'E',
                                                              (1225, 1300,
                                                               1670, 1750)),
                   ('Doghouse', 'F', (340, 450, 1050, 1100)), ('Freezer', 'A',
                                                               (350, 470, -100,
                                                                -35)),
                   ('Crib', 'D', (1280, 1325, 675, 750)), ('washer', 'C',
                                                           (690, 740, 1750,
                                                            1800)))
    elif maze_root == 'C:\Experiments\Bike_Extend_Pilot\SNAP\SNAPMazeD':
        # setup start location dictionary {Start Location:((Start Coordinates),(Start Orientation)),...}
        start_dic = {
            'A': ((1395, 0, 1795), (90, 0, 0)),
            'B': ((2060, 0, 316), (0, 0, 0)),
            'C': ((1145, 0, 211), (0, 0, 0)),
            'D': ((414, 0, 285), (0, 0, 0)),
            'E': ((560, 0, 1150), (90, 0, 0)),
            'F': ((1130, 0, 1070), (90, 0, 0))
        }
        # setup object list (Object,Start Location,End Coordinates)
        objects = (('Drums', 'A', (740, 830, 1710, 1750)),
                   ('Fountain', 'B', (1890, 1940, 1430, 1490)),
                   ('Pooltable', 'C', (1660, 1750, 1200, 1250)),
                   ('Bed', 'D', (1390, 1500, 1000, 1060)),
                   ('Sandpit', 'E', (1680, 1750, 1800, 1850)), ('Stove', 'F',
                                                                (790, 830, 610,
                                                                 650)),
                   ('Shower', 'D', (2345, 2400, 275, 365)), ('Barrel', 'E',
                                                             (1770, 1820, 640,
                                                              675)),
                   ('Tiger', 'F', (740, 830, 178,
                                   200)), ('Bike', 'A', (370, 395, 560, 640)),
                   ('Grill', 'D', (770, 830, 1100, 1140)), ('Ironingboard',
                                                            'C', (2080, 2120,
                                                                  645, 735)))
    else:
        print 'Maze ' + maze_root + ' not supported for condition 2 testing phase.'

    # loop through object/finish location
    trial_number = 1
    for object in objects:

        trial_object = object[1]

        # show user instructions
        instructions = viz.addText(
            'Please navigate to the object displayed on the stand.',
            viz.SCREEN)
        instructions.fontSize(42)
        instructions.setPosition(.5, .5)
        instructions.alignment(viz.TEXT_CENTER_CENTER)
        yield viztask.waitKeyDown('m')
        instructions.remove()

        # show user fixation cross
        yield display_fix()

        # load coordinate_array, then clear it so that previous trial data is gone
        coordinate_array = array([])

        # set object specific finish location
        collide_coords = object[2]

        # set position and orientation
        viz.MainView.setPosition(start_dic[object[1]][0], viz.ABS_GLOBAL)
        viz.MainView.setEuler((0, 0, 0), viz.ABS_GLOBAL)
        viz.MainView.setEuler(start_dic[object[1]][1], viz.BODY_ORI,
                              viz.ABS_GLOBAL)

        # load the maze
        yield maze.visible(viz.ON)

        # enable events
        joy_timer.setEnabled(viz.ON)
        coor_timer.setEnabled(viz.ON)
        write_onkey.setEnabled(viz.ON)
        quit_onkey.setEnabled(viz.ON)
        pos_timer.setEnabled(viz.ON)

        # reset and start the clock
        movement_time = TickTockTimer()
        movement_time.StartTimer()

        # wait for "collision" signal
        yield signal.wait()

        # disable all timers
        disable()
        write_trial_data()

        # turn maze off and then move
        maze.visible(viz.OFF)
        if (object != objects[len(objects) - 1]):
            yield move()
            trial_number = trial_number + 1
    maze.remove()
 def wait_for_target(self):
     if self.target_signal:
         yield self.target_signal.wait()
     else:
         yield viztask.waitKeyDown(' ')
Beispiel #52
0
def calibration():
	''' The heart of the calibration routine. Presents points and collects data. '''


	# start calibration routine and sample data
	n = {'subject':'calibration.should_start', 'hmd_video_frame_size':(2160,1200), 'outlier_threshold':35}
	print(send_recv_notification(n))


	ref_data = []
	
	yield showMessage('Zum Starten die Leertaste drücken')
	
	for p in norm_positions:
		
		print('calibration point: ', p)
	
		norm_x = p[0]
		norm_y = p[1]
		
		first_run = True
		
		if first_run:
			
			first_run = False
		
			'''set up a plane 'right in front of user' on which we want to project the dots'''
	
			# target the current center of view
			p_line = viz.MainWindow.screenToWorld(.5, .5)
		
			# let's modify the line and call it line 2. Here we let the line end at the "depth" value
			p_line_2 = viz.Line(begin=p_line.begin, end=p_line.end, dir=p_line.dir, length=depth)
						
			# Add the plane and apply the matrix of our viewpoint to the plane
			plane = vizshape.addBox(size=[3.6, 2, .1])
			mymat = viz.MainView.getMatrix()
			plane.setMatrix(mymat)
			
			# Reposition the plane to the end of line 2
			plane.setPosition(p_line_2.end)
			plane.color([.25,.25,.25])
			plane.alpha(.95)
			
			# Lock it to user
			plane_link = viz.grab(viz.MainView, plane)
		
		
		# interpolate a line from norm values to 3d coordinates
		line = viz.MainWindow.screenToWorld([norm_x, norm_y])
		
		# find the intersection
		intersection = viz.intersect(line.begin, line.end)
		
		# place a dot (at depth level of line) 
		dot = vizshape.addSphere(radius=sphere_size)
		dot.setPosition(intersection.point)
		
		# lock dot to user
		view_link = viz.grab(viz.MainView, dot)
		
		print('ready')
		viz.playSound('beep500_200.wav')
		yield viztask.waitKeyDown(' ')
				
		for s in range(60):
			
			# get the current pupil time (pupil uses CLOCK_MONOTONIC with adjustable timebase).
			# You can set the pupil timebase to another clock and use that.
			t = get_pupil_timestamp()

			# here the left and right screen marker positions are identical.
			datum0 = {'norm_pos':p,'timestamp':t,'id':0}
			datum1 = {'norm_pos':p,'timestamp':t,'id':1}
			ref_data.append(datum0)
			ref_data.append(datum1)
			yield viztask.waitTime(1/60.)
			print(t)
		
		dot.color(viz.RED)
		
		print('waiting for next position...')
		
		yield viztask.waitKeyDown(' ')
		
		yield dot.remove()
		
	

	# send ref data to Pupil Capture/Service:
	# this notification can be sent once at the end or multiple times.
	# during one calibraiton all new data will be appended.
	n = {'subject':'calibration.add_ref_data','ref_data':ref_data}
	print(send_recv_notification(n))

	# stop calibration
	# pupil will correlate pupil and ref data based on timestamps,
	# compute the gaze mapping params, and start a new gaze mapper.
	n = {'subject':'calibration.should_stop'}
	print(send_recv_notification(n))

	time.sleep(2)
		
	showMessage('calibration done! - now validate!')

	plane.remove()
	
	yield viztask.waitTime(2)
Beispiel #53
0
def MainTask():
    """Top level task that controls the game"""
    global won
    global manChase

    # Display instructions and wait for key press to continue
    yield DisplayInstructionsTask()

    yield manKicksBall()

    # Create panel to display trial results
    resultPanel = vizinfo.InfoPanel('',align=viz.ALIGN_CENTER,fontSize=25,icon=False,key=None)
    resultPanel.visible(False)

    resetManChase = False

    if manChase == True:
        resetManChase = True

    while True:

        # Randomly choose hiding spots from list
        locations = random.sample(HIDING_SPOTS,TRIAL_COUNT)

        # Reset score
        score = 0
        UpdateScore(score)

        # Go through each position
        for pos in locations:

            # Perform a trial
            found = yield TrialTask(pos)

            # Update score and display status text
            if found:
                viz.playSound('sounds/pigeon_catch.wav')
                score += 1
                UpdateScore(score)
                tracker.runAction(vizact.spinTo(point=pos,time=0.8,interpolate=vizact.easeOutStrong))
                resultPanel.setText(TRIAL_SUCCESS)
                won = True
                data = yield viztask.waitDirector(writeData)
            else:
                viz.playSound('sounds/pigeon_fly.wav')
                viztask.schedule(FadeToGrayTask())
                resultPanel.setText(TRIAL_FAIL)
                data = yield viztask.waitDirector(writeData)

            #allow for other animations for male2 while also ensuring
            #he chases the pigeon each round
            if resetManChase:
                manChase = True

            #Display success/failure message
            resultPanel.visible(True)

            # Add delay before starting next trial
            yield viztask.waitTime(TRIAL_DELAY)
            resultPanel.visible(False)

            # Disable gray effect
            gray_effect.setEnabled(False)

        #Display results and ask to quit or play again
        resultPanel.setText(RESULTS.format(score,TRIAL_COUNT))
        resultPanel.visible(True)
        yield viztask.waitKeyDown(' ')
        resultPanel.visible(False)
Beispiel #54
0
def myTask(text):
    yield viztask.waitKeyDown("k")
    pigeon.addAction(dead(text))
Beispiel #55
0
		#teleport to new location each trial
		x , y = pol2cart(numpy.random.randint(10,radius), numpy.random.randint(0,360))
		viz.MainView.setPosition(x,0,y)
        startAng = numpy.random.randint(0,360)
		viz.MainView.setEuler(startAng,0,0)

		#ADD rotation here
		deg = 0
		while deg < 360:
			viz.MainView.setPosition(x,0,y) 
			viz.MainView.setEuler(startAng + deg,0,0)
			deg = deg + 0.5
			yield viztask.waitTime(1 / 720)

		#wait for response
		yield viztask.waitKeyDown(['a','A'])


#####################################
########WAIT FOR TRIGGERS############
#####################################
def WaitForTrig(Quick):

	if Quick!=1:
		viz.MainWindow.setScene(4)
		#wait for trigger
		message= 'Run ' + str(runNum) +', waiting for T'
		waitT = viz.addText(message,viz.SCREEN,scene=4)
		waitT.fontSize(18)
		waitT.color(viz.RED)
		waitT.setPosition([0,0,0])