PDA

View Full Version : Mark & Print Oculus data


tianmoran
10-08-2018, 11:17 AM
Hi there,

I'm coding for an experiment but muddled with some trouble. My goal is to record the Oculus data(position, euler) every 50ms. At the same time, I need to mark some events, like below the events are 'cylinder is on', 'key pressed', 'cylinder is off'. So I put a variable called 'Event' and hope to change its value right after each event happens. Unfortunately, it didn't work.

I kind of know why it's not working. But is there any solution on that?

Thank you so much if anyone would like to help me out!!!

import viz
import vizact
import vizshape
import viztask
import vizinput
import vizinfo
import time
import random
import oculus
import vizfx
import numpy
from numpy import *

viz.go()

##### SET UP OCULUS
hmd = oculus.Rift()
oculus = viz.addGroup()
oculusView = viz.link(oculus, viz.MainView)
oculusView.preMultLinkable(hmd.getSensor())
oculusView.setOffset([0,0.5,-1])

def Demo():
global acc, RT, Keycode, trialNo, oculus, oculusView, Cond, FMM, Code_direct, Event, trial, block, unit, acc, RT, Keycode, trialNo, oculus, oculusView,oculus_timer, Group, Code_Type, Code_Letter, FirstTrial
FirstTrial = 1
Instr = vizshape.addCylinder(1,0.05)
Instr.setPosition(0,0,0)
Instr.color(0.5,0,0)
Instr.visible(viz.OFF)
yield viztask.waitTime(0.5)

Oculusdata = open('testtest'+ "_Oculus.txt",'a',1)

for trial in range(10):

###### Calculating Reaction Time
def df():
global startTime
startTime = viz.tick()
print str(trial), 'startTime', startTime
Instr.visible(viz.ON)
yield vizact.ontimer2(1,0,df)
Event = 0

def waitkeydown():
global r, KeyPress, startTime
r = yield viztask.waitKeyDown(None)

if r.key == 'j':
acc[0][trial] = 1
Keycode[0][trial] = 2 ### Key J is pressed
elif r.key == 'f':
acc[0][trial] = 0
Keycode[0][trial]= 1 ### Key F is pressed

yield viztask.waitAny([waitkeydown(), viztask.waitTime(3)])
Event = 1
Instr.visible(viz.OFF)
Event = 2

def printOculusData():
global oculus_timer
oculus_timer = viz.tick()
OculusData = "%s\t%s\t%s\t%s\t%s\n" %(trial, Event,oculus_timer,oculusView.getPosition(), oculusView.getEuler())
Oculusdata.write(OculusData)
if FirstTrial == 1:
vizact.ontimer(0.05,printOculusData)
FirstTrial = 0

viztask.schedule(Demo())