WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-03-2012, 06: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
  #2  
Old 05-04-2012, 07:24 AM
hrm hrm is offline
Member
 
Join Date: Feb 2012
Posts: 2
Hello there,
An update.
So using either A) viz.callback or B) viztask.schedule functions work in getting some response from the button box presses. -- see below

BUT I can't seem to get these keypresses from the button box to move the views using if-else conditions
viz.key.isDown('2'):#(viz.KEY_UP):
Should I be using viz.key.isDown with the button box keys? The function works for keyboard keys though...
I also did get this error:
"before Glyph::subload(): detected OpenGL error: invalid enumerant"
i) I am not sure if it the inability to move the trigger based on a button box key press is related to that error.
ii) would lack of RAM be an issue?

Any help/advise would be appreciated!
Thanks in advance.
May

--------------------------------------------------------------------
A)
import viz
import viztask

viz.go()

keyDisplay = viz.addText( 'key pressed: ', viz.SCREEN , pos=(0.25,0.5,0) )
keyDisplay.fontSize(30)
keyDisplay2 = viz.addText( 'keys 1,2, or 3 pressed: ', viz.SCREEN , pos=(0.25,0.75,0) )
keyDisplay2.color(viz.RED)
keyDisplay2.fontSize(30)

global key
def mykeyinput(key):
ShowData(viz.tick(),key)
viz.callback(viz.KEYDOWN_EVENT, mykeyinput)


def ShowData(currenttime,key):#(k):#(currenttime,key,k ):
global data
data = 'time: '+ str(currenttime) + ' keypress: "' + key + '"'
print data
kpress = 'Key " '+key+ ' "'
keyDisplay.message(kpress)#( 'keypress: ' + str(k.key) )
if key=='1':
keyDisplay2.message('yo!')#(kpress)
elif key=='2':
keyDisplay2.message('yoyo!')#(kpress)
elif key=='3':
keyDisplay2.message('yoyoyo!')#(kpress)
elif key=='4':
keyDisplay2.message('yoyoyoyo!')#(kpress)
else:
keyDisplay2.message('oooooooooooooooooooo!')#(kpre ss)

B)
import viz
import viztask

viz.go()

keyDisplay = viz.addText( 'key pressed: ', viz.SCREEN , pos=(0.25,0.5,0) )
keyDisplay.fontSize(30)
keyDisplay2 = viz.addText( 'keys 1,2, or 3 pressed: ', viz.SCREEN , pos=(0.25,0.75,0) )
keyDisplay2.color(viz.RED)
keyDisplay2.fontSize(30)

def mykeyinput():#(key):
global k
while True:
k=yield viztask.waitKeyDown(None)
# Calls the function SaveData and hands it the current time and key
#ShowData(viz.tick(),key,k)
ShowData(k)
#displayKeypress(k)
# Defines a callback for keyboard events
#viz.callback(viz.KEYDOWN_EVENT, mykeyboard)
viztask.schedule(mykeyinput)

def ShowData(k):#(currenttime,key,k):
global data
#data = 'time: '+ str(currenttime) + ' keypress: "' + key + '"'
data = "Key '"+k.key+"' was pressed at time",k.time
print data
kpress = 'Key " '+ k.key+' "'
#displayKey = viz.addText(str(kpress), viz.SCREEN , pos=(0.1,0.5,0) )
keyDisplay.message(kpress)#( 'keypress: ' + str(k.key) )
if k.key=='1':
keyDisplay2.message('yo!')#(kpress)
elif k.key=='2':
keyDisplay2.message('yoyo!')#(kpress)
elif k.key=='3':
keyDisplay2.message('yoyoyo!')#(kpress)
else:
keyDisplay2.message('oooooooooooooooooooo!')#(kpre ss)
Reply With Quote
Reply


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
integrating osgocean with vizard mousa Plug-in development 0 01-10-2012 05:57 AM
Integrating Triton Ocean with Vizard 3.18 mousa Vizard 0 01-07-2012 09:24 AM
Vizard 4 Beta Testing farshizzo Announcements 0 02-01-2011 11:46 AM
Vizard 4 Beta Testing farshizzo Vizard 0 02-01-2011 11:46 AM
Vizard tech tip: Using the Python Imaging Library (PIL) Jeff Vizard 0 03-23-2009 12:13 PM


All times are GMT -7. The time now is 07:10 PM.


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