View Single Post
  #1  
Old 04-19-2012, 05:28 AM
Frank Verberne Frank Verberne is offline
Member
 
Join Date: Mar 2008
Location: Netherlands
Posts: 148
Avatar mimicking after

Hi all,

I'm trying to make an avatar mimic the head movements of a participant with a delay of 4 seconds. In the code below, I'm writing the euler information of the viz.MainView to a file (1.log) and after 4 seconds, I'm trying to read from the beginning of that same file (thus creating a delay of 4 seconds). But after 4 seconds, I get an error message (IOError: [Errno 0] Error) and I think that's because I'm reading from the same file I'm writing to. I understand this could be problematic, but I don't know an other approach for my problem. Any help is greatly appreciated!

Regards,
Frank
Code:
import viz
import vizact
import viztask
import time

viz.go()

#CONSTANTS
PATH = '.\\'
PARTICIPANT = 1
TRACKING_DATA = open(PATH+str(PARTICIPANT)+".log", 'w+')
TIMER_SPEED = 0.1
SEC_DELAY = 4

def logTrackingData():
    orientation = viz.MainView.getEuler()
    data = str(orientation[0])+' '+str(orientation[1])+' '+str(orientation[2])+'\n'
    TRACKING_DATA.write(data)

def readTrackingData():
    rotation = TRACKING_DATA.readline()
    print rotation

def readWithDelay():
    #Wait 4 seconds
    yield viztask.waitTime(SEC_DELAY)
    vizact.ontimer(TIMER_SPEED, readTrackingData)

vizact.ontimer(TIMER_SPEED, logTrackingData)
viztask.schedule(readWithDelay())
Reply With Quote