WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 10-08-2018, 12:17 PM
tianmoran tianmoran is offline
Member
 
Join Date: Nov 2016
Posts: 16
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())
Reply With Quote
 

Tags
events, oculus

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
Vizard and Matlab sagar29 Vizard 7 12-25-2017 11:36 PM
Sending data from MATLAB(Simulink) to Vizard sagar29 Vizard 0 01-05-2017 04:31 PM
Oculus runtime disrupts clustering to mirror DK2 display performlabrit Vizard 1 01-23-2015 08:00 AM
about a pair game emily800326 Vizard 2 11-06-2012 08:45 AM
Crashing when I select Tracker option GoldenSun Vizard 4 07-01-2008 12:06 PM


All times are GMT -7. The time now is 03:32 AM.


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