WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-23-2011, 10:43 PM
dcnieho dcnieho is offline
Member
 
Join Date: Feb 2011
Posts: 59
viz.tick()

Dear All,

I'm collecting data on every frame and storing it. I wanted to add a timestamp and am trying to use viz.tick() for that. But on every sample it returns exactly the same time (15.6746965561 for instance), while the other variables do seem to be correct. Let me give you the relevant code:

Code:
# if have a member function of a class that runs a trial. Its responsible for collecting the data
def collectData(self):
    class Sample:
        def __init__(self):
            # self.frameNum           = 0
            self.time               = 0
            self.subjectVirtualPos  = [0,0]
            self.subjectEuler       = 0
            self.subjectRealPos     = [0,0]
            self.targetPolePos      = [0,0]
 
        def __str__(self):
            temp = [s.time] + self.subjectVirtualPos + self.subjectRealPos + [self.subjectEuler] + self.targetPolePos
            return iterable2str(temp,'\t')
 
    while True:
        # [::2] for a three element list returns first and third elements (X and Z coords)
        # for the subject Euler we only need the first number, which is the yaw
        s = Sample()
        # s.frameNum          = viz.getFrameNumber()
        s.time              = viz.tick()
        s.subjectVirtualPos = viz.MainView.getPosition()[::2]
        s.subjectEuler      = viz.MainView.getEuler()[0]
        s.subjectRealPos    = screenAndTracker.headLink.getSrc().getPosition()[::2]
        s.targetPolePos     = self.targetPole.node.getPosition()[::2]
        self.sampleList.append(s)
        yield viztask.waitTime(self.SAMPLING_SECONDS_TO_WAIT)   # using 1/framerate instead so sampling is uniform even if program's framerate is jittery.
 
 
# when running the trial, I start data recording by writing
collectDataTask = viztask.schedule(self.collectData())
 
 
# and for completeness sake (though not relevant), iterable2str:
# for converting list item to str with separator(s) in between
def iterable2str(seq, sep): 
    it = iter(seq)
    sep = str(sep)
    try:
        first = it.next()
    except StopIteration:
        return []
 
    def add_sep(r, v):
        r += [sep, str(v)]
        return r
 
    return ''.join(reduce(add_sep, it, [str(first)]))
As said, the viz.task() always returns the same time for the whole trial. The next trial (a new trial class instance), it returns another time, the same one for the whole trial again.

Don't know if its relevant, but the outer skeleton for running an experiment is:
Code:
### run expt: loop over trials
viztask.schedule(self.doTrials())
 
# function that runs over the trials
# function that runs over the trials
def doTrials(self):
    for condID,runNr in zip(self.trialSequence,self.runNrSequence):
        # get trial info (this returns a new instance of the trial class)
        trial = getTrial(condID,conditionList)
 
        # run the trial
        yield trial.doTrial(self.stim)
The collectDataTask shown above gets created in the doTrial function.

Do you know what might be going on? Or do you need more code to be able to diagnose this?

Thank you for your help!
Reply With Quote
  #2  
Old 05-24-2011, 08:38 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I believe the problem is in the Sample.__str__ method. You are using s.time instead of self.time.
Reply With Quote
  #3  
Old 05-24-2011, 08:02 PM
dcnieho dcnieho is offline
Member
 
Join Date: Feb 2011
Posts: 59
Ah, good catch, it works now. Thanks!
Reply With Quote
Reply

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


All times are GMT -7. The time now is 10:37 AM.


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