WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 07-02-2014, 10:22 AM
hfarmer hfarmer is offline
Member
 
Join Date: Jan 2014
Posts: 6
Logging an RT with a window of time

Hi,

I'm currently trying to get a study set up using vizard 4 and am having a bit of a problem. I want to set up some code to measure reaction times after the presentation of a stimuli. However I want the program to move on to the next trial after 3 seconds regardless of whether a key is pressed or not. However this doesn't seem to be possible using the standard way of measuring reaction times given in the Vizard tutorial e.g:
Code:
		d = yield viztask.waitDraw() #Set Display time
		displayTime = d.time #Log display time
		d = yield viztask.waitKeyDown(None) #Log keypress time
		pressTime = d.time
		reactionTime = pressTime- displayTime #Calculate reaction time
Basically I want to know if there's a way to set up two parallel processes, one which is waiting for a key press to log reaction times and the other which just runs a timer and moves on the program after 3 seconds. Any help would be much appreciated.
Reply With Quote
  #2  
Old 07-02-2014, 04:48 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,465
You can use the viztask.waitAny command to wait for one condition, out of a list of conditions, to occur.
Reply With Quote
  #3  
Old 07-07-2014, 02:53 AM
hfarmer hfarmer is offline
Member
 
Join Date: Jan 2014
Posts: 6
Hi Jeff,

Thanks for your help.

I found that command but the problem is that I want the program to always wait 3 seconds before moving on regardless of whether a key is pressed or not. But it seems like to log the reaction time I need to make if a yield command and that means the program will wait until a key is pressed before moving on. Is there a way to log reaction time without using the yield command?

Best,

Harry
Reply With Quote
  #4  
Old 07-07-2014, 03:23 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,465
You could log the reaction time and then yield for an additional amount of time equal to 3 seconds minus the reaction time:

Code:
import viz
import viztask
viz.go()

def MyTask():
	
	waitKey = viztask.waitKeyDown(' ')
	waitTime = viztask.waitTime(3)
	
	while True:
		
		print 'start'

		#Wait for next frame to be drawn to screen
		d = yield viztask.waitDraw()

		#Save start time
		startTime = d.time

		d = yield viztask.waitAny( [ waitKey, waitTime ] )
		
		if d.condition is waitKey:
			keyData = d.data
			elapsed = keyData.time - startTime
			print 'The spacebar was pressed after {:.2f} seconds'.format(elapsed)
			yield viztask.waitTime(3-elapsed)
			
		elif d.condition is waitTime:
			print '3 seconds passed, the spacebar was not pressed'

viztask.schedule( MyTask() )
Reply With Quote
  #5  
Old 07-18-2014, 05:38 AM
hfarmer hfarmer is offline
Member
 
Join Date: Jan 2014
Posts: 6
Hi Jeff,

Sorry for the delay in getting back to you, thanks for the example code, I didn't know about the condition command before but can see that it would be very useful. However I have one more question which is how to remove the "True" condition after each trial so that the program moves on to the next trial.

At the moment I am getting the information logged but the program seems to stick on the first condition rather than timing out after 3 seconds. Could you let me know what the "while True" part of the code refers to? I assume it just means while in that function but am a bit unclear on how to end the function with a command.

Best,

Harry
Reply With Quote
  #6  
Old 07-18-2014, 02:28 PM
Jeff Jeff is offline
WorldViz Team Member
 
Join Date: Aug 2008
Posts: 2,465
The while True line always evaluates to True so the loop keeps repeating. To run that code a set number of times you could use a for loop or have an expression following while that evaluates to False after several loops. Try replacing:

Code:
while True
with:

Code:
for i in range(1,5):
	
	print 'start trial {}'.format(i)
Reply With Quote
  #7  
Old 07-21-2014, 06:15 AM
hfarmer hfarmer is offline
Member
 
Join Date: Jan 2014
Posts: 6
Dear Jeff,

Just wanted to let you know that I tried what you suggested and the program works perfectly now.

Many Thanks,

Harry
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
exact copy of mainview in second window dcnieho Vizard 1 06-30-2014 04:02 PM
Window always on top madeinjava Vizard 4 08-27-2013 02:10 PM
Unexpected Change of Window Size javadi Vizard 7 07-23-2013 02:56 PM
Inconsistent timestamp while logging mape2k Vizard 4 07-15-2013 06:03 AM
timer question Elittdogg Vizard 5 10-10-2007 02:49 PM


All times are GMT -7. The time now is 03:44 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2021, vBulletin Solutions, Inc.
Copyright 2002-2018 WorldViz LLC