#1
|
|||
|
|||
Mark & Print Oculus data
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!!! Code:
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()) |
Tags |
events, oculus |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Vizard and Matlab | sagar29 | Vizard | 7 | 12-25-2017 10:36 PM |
Sending data from MATLAB(Simulink) to Vizard | sagar29 | Vizard | 0 | 01-05-2017 03:31 PM |
Oculus runtime disrupts clustering to mirror DK2 display | performlabrit | Vizard | 1 | 01-23-2015 07:00 AM |
about a pair game | emily800326 | Vizard | 2 | 11-06-2012 07:45 AM |
Crashing when I select Tracker option | GoldenSun | Vizard | 4 | 07-01-2008 11:06 AM |