我正在尝试执行双重任务。两项任务都要求判断一个数字。刺激以可变的间隔(a_soa
)紧接出现。我需要收集对键盘给出的刺激的反应时间(第一个任务:y或x键;第二个任务:或。键)。我目前正在努力实现这一目标,因为对于第一个任务,程序甚至需要在绘制第二个任务之前就开始等待响应。然后,第二个刺激出现,并标志着对第二个任务的可能响应的开始。
我正在使用的两个函数的代码和主要函数均包含在下面。
def StimPresent(a_soa, b_s1, c_s2):
"""
Function StimPresent(a, b, c) presents stimulus_1 (b) for SOA ((a) number of frames),
then it adds stimulus_2 (d) and shows both for max 60 frames
and returns time of stimulus onset (tim)
"""
if event.getKeys(keyList='escape'):
myWin.close()
core.quit()
for frameN in range(a_soa):
b_s1.draw()
fixation.draw()
if frameN == 0: # RT S1 starting immediately after flip
onsetS1 = RT1.getTime()
myWin.flip()
for frameN in range(a_soa, (a_soa+60)):
b_s1.draw()
fixation.draw()
c_s2.draw()
if frameN == (a_soa+1):
onsetS2 = RT2.getTime() #RT S2 starting immediately after soa flip
myWin.flip()
for frameN in range((a_soa+60), 300):
fixation.draw()
myWin.flip()
return [b_s1, onsetS1, c_s2, onsetS2, a_soa]
def GetRTs(onS1, onS2):
allkeys = []
event.clearEvents()
while len(allkeys)!=2:
if event.getKeys(['y']):
buttonR1 = 55
allkeys.append(buttonR1)
buttonR1Time = RT1.getTime()
theRT1 = buttonR1Time - onS1
elif event.getKeys(['x']):
buttonR1 = 44
allkeys.append(buttonR1)
buttonR1Time = RT1.getTime()
theRT1 = buttonR1Time - onS1
else:
buttonR1 = 666
allkeys.append(buttonR1)
buttonR1Time = 'NaN'
theRT1 = 'NaN'
if event.getKeys(','):
buttonR2 = 44
allkeys.append(buttonR1)
buttonR2Time = RT2.getTime()
theRT2 = buttonR2Time - onS2
elif event.getKeys('.'):
buttonR2 = 55
allkeys.append(buttonR1)
buttonR2Time = RT2.getTime()
theRT2 = buttonR2Time - onS2
else:
buttonR2 = 666
allkeys.append(buttonR1)
buttonR2Time = 'NaN'
theRT2 = 'NaN'
if RT2.getTime() - onS2 > 210:
break
elif event.getKeys(['escape']):
myWin.close()
core.quit()
return [buttonR1, buttonR1Time, buttonR2, buttonR2Time, theRT1, theRT2]
主程序
for b in range(block < 2):
for thisTrial in trials:
"""
---------------------
Start des Durchgangs
---------------------
"""
RSIFix()
showChar = StimPresent(thisTrial.SOA, thisTrial.Stimulus_1, thisTrial.Stimulus_2)
s1 = showChar[0]
s1onset = showChar[1]
s2 = showChar[2]
s2onset = showChar[3]
soa = showChar[4]
responses = GetRTs(s1onset, s2onset)
感谢您的帮助:)
如果使用Psychopy的event
模块来收集响应,则需要将对按键的检查集成到绘图循环中。即,每个win.flip()
调用都检查一次按键,这样您就可以在每次屏幕刷新时有效地检查一次响应(并有效地获得非常精细的时间分辨率,对于60 Hz的显示通常为16.67 ms)。
event.getKeys()
函数的工作方式是时间戳是函数被调用的时间,而不是按键被按下的时间。也就是说,在您当前的代码中,可能是在刺激过程中按下了该键,而只是坐在缓冲区中等待您对其进行处理。因此,您的所有反应时间似乎都在刺激显示完毕之后。
已经说过,如果反应时间很重要,那么(从PsychoPy 3.1开始)现在的最佳实践是不使用event
模块。而是使用新的Keyboard
类:https://www.psychopy.org/api/hardware/keyboard.html这是从Psychtoolbox项目移植的,具有更好的计时性能。而且重要的是,时间戳记反映了按键的实际时间,无论您何时检查响应,而且其分辨率都与显示刷新率无关。