|  | 
| 
			 
			#1  
			
			
			
			
			
		 | |||
| 
 | |||
| 
				
				Inconsistent timestamp while logging
			 
			
			Hi all, I have come across a problem concerning the timestamps in a log file that I want to use to monitor the position and view angle of a subject during an experiment. At the beginning of the experiment, I am calling the logging function with vizact.ontimer(fs,function), with fs being the desired sampling frequency. When I use this method, I am not getting timestamps with equal time spans in the log file. It seems that the time spans vary about the given fs with +-10ms. I am using datetime.datetime.now() to get the current time. Is there any other way of producing accurate time readings? I have read that datetime essentially uses time.time(), which is supposed to be the most accurate function in Python. Here is an example for an fs = 10: Timestamp, Position, View Angle 18:42:41:056,[0.000,1.820,-0.000],[-0.000] 18:42:41:166,[0.000,1.820,-0.000],[-0.000] 18:42:41:259,[0.000,1.820,-0.000],[-0.000] 18:42:41:368,[0.000,1.820,-0.000],[-0.000] 18:42:41:462,[0.000,1.820,-0.000],[-0.000] 18:42:41:556,[0.000,1.820,-0.000],[-0.000] 18:42:41:665,[0.000,1.820,-0.000],[-0.000] 18:42:41:758,[0.000,1.820,-0.000],[-0.000] 18:42:41:868,[0.000,1.820,-0.000],[-0.000] 18:42:41:961,[0.000,1.820,-0.000],[-0.000] 18:42:42:070,[0.000,1.820,-0.000],[-0.000] 18:42:42:164,[0.000,1.820,-0.000],[-0.000] 18:42:42:258,[0.000,1.820,-0.000],[-0.000] Also, I am including a minimum working example: Code: from __future__ import division
import viz
import vizact
import viztask
import os
import datetime
class myTimer():
	def __init__(self,number,dateFormat,timeFormat):
		
		self.nr = number
		self.dateFormat = dateFormat
		self.timeFormat = timeFormat
	
	def time(self):
		
		self.curDateTime = datetime.datetime.now()
		self.curTime = self.curDateTime.strftime(self.timeFormat)
		if self.timeFormat == '%H:%M:%S:%f':
			self.curTime = self.curTime[:-3]
		return self.curTime
logTime = myTimer(1,'%d.%m.%Y','%H:%M:%S:%f')	
file = open('test.txt', 'w')	
	
def posLogger():
	
	curAngle = viz.MainView.getEuler()
	curPos = viz.MainView.getPosition()
	file.write('%s,[%0.3f,%0.3f,%0.3f],[%0.3f]\n' % 
	(logTime.time(),curPos[0],curPos[1],curPos[2],curAngle[0]))
# -----
# Start
# -----
fs = 10
print 1/fs
logTimer = vizact.ontimer((1/fs),posLogger)	
viz.go() | 
| Thread Tools | |
| Display Modes | Rate This Thread | 
| 
 | 
 | 
|  Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Head tracking logging & realtime data | tmcw | Vizard | 2 | 08-18-2007 10:31 AM |