View Single Post
  #1  
Old 05-03-2012, 05:29 PM
hrm hrm is offline
Member
 
Join Date: Feb 2012
Posts: 2
integrating brain-imaging response buttons with Vizard

Hi there,

I am new to this Vizard world and am finding it rather challenging as its python-VBasic morphed language is nothing like Matlab which I feel more at home even if I am not an expert.

I am trying to see if we could use Vizard in a brain imaging study where timing is very important.
However I am having having initial problems with getting the response buttons to interact with Vizard.
I figured out using one of the example scripts e.g.
import viz

viz.go()

import vizinfo
vizinfo.add('When you press a keyboard button, the script will output the \ncurrent time and the button pressed to the file \'response.txt\'')

# Opens file 'response.txt' in write mode
file = open('testresponse.txt', 'w')

# Define a function that saves data
def SaveData(currenttime, key):
# Create the output string
out = 't:' + str(currenttime) + '\t' + '"' + key + '"' + '\n'

# Write the string to the output file
file.write(out)

# Makes sure the file data is really written to the harddrive
file.flush()
print out

# Define a function that is called every time a keyboard button is pressed
def mykeyboard(key):
# Calls the function SaveData and hands it the current time and key
SaveData(viz.tick(),key)

# Defines a callback for keyboard events
viz.callback(viz.KEYDOWN_EVENT, mykeyboard)
I managed to figure out that the response buttons correspond to keyboard keys:'1','2',3','4' etc. In addition, I am struggling to appreciate how the callback and schedule functions work.

Also is viz.KEYDOWN_EVENT or viz.key.isDown specific to 'keyboards' or can usb response buttons also benefit from them? Because I can't seem to get any of the response buttons to manipulate e.g. an action in the vizworld e.g. to print out on the screen which key is pressed and move. This bit of code seems to work with a keyboard but I have yet tried to use the response buttons keypard to test. It uses viztask.schedule instead of viz.callback; I don't understand how theses 2 functions work... they seem to be passing variables but I don't fully understand the arguments/variables needed in functions using vistask/vis.callback -- hope someone can clarify.
import viz
import viztask

viz.go()
keyDisplay = viz.addText( 'key pressed: ', viz.SCREEN , pos=(0.25,0.5,0) )

def mykeyinput():
global k
while True:
k=yield viztask.waitKeyDown(None)
ShowData(k)
viztask.schedule(mykeyinput)

def ShowData(k):
global data
data = "Key '"+k.key+"' was pressed at time",k.time
print data
kpress = 'Key " '+ k.key+' "'
keyDisplay.message(kpress)
If any specific one of the response buttons would be pressed and I can check this every 1ms I would like to use it to move the viewpoint in e.g. forward, backwards, left or right view before any movement action etc.

Basically, I am having difficulties understanding how to check these button presses every e.g. 1ms or as fast as possible, and use this button information to manipulate the viewpoint and position of the observer. and I would want it to do so for N trials while the viewer travels some number of steps e.g. movement (M) that is also counted.

I envision that it would be something like this for say 1 trial:
You have a Goal position to get to from current position and this could take a few steps/movements (M) to get to.
Before each movement you are asked what is the next step you'd take.
you make a choice (L,F,R,B) from start for M steps, and press the response buttons e.g.
I need to know this buttonpress = getButtonPress
Use buttons --> move to L,F,R,B relative to current position change the World view to reflect new position and view.
Once you get to the new position and view you repeat this process until you get to the Goal. This would be one trial. so there would be another loop for say N trials of different start to goal movements I would need to create.

If someone can offer some help/advise or some example code? It would be gratefully appreciated!

Thanks,
May
Reply With Quote