Doc_code |

Cargando...
Buscando...
Nada coincide
simple_tracker_experiment.py
Ir a la documentación de este archivo.
1# example script for using PyGaze
2
3# # # # #
4# importing the relevant libraries
5 import random
6 import constants
7 from pygaze import libscreen
8 from pygaze import libtime
9 from pygaze import liblog
10 from pygaze import libinput
11 from pygaze import eyetracker
12
13# # # # #
14# experiment setup
15
16# create display object
17disp = libscreen.Display()
18
19# create eyetracker object
20tracker = eyetracker.EyeTracker(disp)
21
22# create keyboard object
23keyboard = libinput.Keyboard(keylist=['space'], timeout=None)
24
25# create logfile object
26log = liblog.Logfile()
27log.write(["trialnr", "trialtype", "endpos", "latency", "correct"])
28
29# create screens
30inscreen = libscreen.Screen()
31inscreen.draw_text(text="When you see a cross, look at it and press space. Then make an eye movement to the black circle when it appears.\n\n(press space to start)", fontsize=24)
32fixscreen = libscreen.Screen()
33fixscreen.draw_fixation(fixtype='cross',pw=3)
34targetscreens = {}
35targetscreens['left'] = libscreen.Screen()
36targetscreens['left'].draw_circle(pos=(int(constants.DISPSIZE[0]*0.25),constants.DISPSIZE[1]/2), fill=True)
37targetscreens['right'] = libscreen.Screen()
38targetscreens['right'].draw_circle(pos=(int(constants.DISPSIZE[0]*0.75),constants.DISPSIZE[1]/2), fill=True)
39feedbackscreens = {}
40feedbackscreens[1] = libscreen.Screen()
41feedbackscreens[1].draw_text(text='correct', colour=(0,255,0), fontsize=24)
42feedbackscreens[0] = libscreen.Screen()
43feedbackscreens[0].draw_text(text='incorrect', colour=(255,0,0), fontsize=24)
44
45# # # # #
46# run the experiment
47
48# calibrate eye tracker
49tracker.calibrate()
50
51# show instructions
52disp.fill(inscreen)
53disp.show()
54keyboard.get_key()
55
56# run 20 trials
57 for trialnr in range(1,21):
58 # prepare trial
59 trialtype = random.choice(['left','right'])
60
61 # drift correction
62 checked = False
63 while not checked:
64 disp.fill(fixscreen)
65 disp.show()
66 checked = tracker.drift_correction()
67
68 # start eye tracking
69 tracker.start_recording()
70 tracker.status_msg("trial %d" % trialnr)
71 tracker.log("start_trial %d trialtype %s" % (trialnr, trialtype))
72
73 # present fixation
74 disp.fill(screen=fixscreen)
75 disp.show()
76 tracker.log("fixation")
77 libtime.pause(random.randint(750, 1250))
78
79 # present target
80 disp.fill(targetscreens[trialtype])
81 t0 = disp.show()
82 tracker.log("target %s" % trialtype)
83
84 # wait for eye movement
85 t1, startpos = tracker.wait_for_saccade_start()
86 endtime, startpos, endpos = tracker.wait_for_saccade_end()
87
88 # stop eye tracking
89 tracker.stop_recording()
90
91 # process input:
92 if (trialtype == 'left' and endpos[0] < constants.DISPSIZE[0]/2) or (trialtype == 'right' and endpos[0] > constants.DISPSIZE[0]/2):
93 correct = 1
94 else:
95 correct = 0
96
97 # present feedback
98 disp.fill(feedbackscreens[correct])
99 disp.show()
100 libtime.pause(500)
101
102 # log stuff
103 log.write([trialnr, trialtype, endpos, t1-t0, correct])
104
105# end the experiment
106log.close()
107tracker.close()
108disp.close()
109libtime.expend()