WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
Prev Previous Post   Next Post Next
  #16  
Old 11-29-2007, 09:25 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I cannot run your code because it is not inside the [code][/code] tags. Python code depends on indentation, and posting code without the proper tag loses the indentation.

Either way, I've included a sample script that will manually maintain a proper sample rate. Here is the code:
Code:
import viz
from time import clock
viz.go()

class SampleRate(viz.EventClass):
	def __init__(self,rate,func):
		viz.EventClass.__init__(self)
		self.rate = rate
		self.func = func
		self.lastSampleTime = 0.0
		self.callback(viz.TIMER_EVENT,self.onTimer)

	def onTimer(self,num):
		now = clock()
		while (now - self.lastSampleTime) >= self.rate:
			self.func()
			self.lastSampleTime += self.rate
			
	def start(self):
		self.killtimer(0)
		self.lastSampleTime = clock()
		self.starttimer(0,0,viz.FOREVER)
		
	def stop(self):
		self.killtimer(0)
		

def DoSample():
	#Collect sample here
	pass

#Call function 'DoSample' at rate of '1/30.0'
sampler = SampleRate(1/30.0,DoSample)

#Start the sampler
sampler.start()
Reply With Quote
 


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
Flock of Birds recognized, but no data sent sjroorda Vizard 9 03-01-2016 08:48 PM
Using vrpn_server with Flock of birds sylvain Precision Position Tracker (PPT) 3 11-30-2007 09:45 AM
Flock of Birds Elittdogg Vizard 9 10-02-2007 01:53 PM
Flock of birds extended range problem theuberk Vizard 4 07-30-2007 09:31 AM
Adding more than one Flock of Birds asimbh Vizard 3 12-15-2006 01:48 AM


All times are GMT -7. The time now is 10:51 PM.


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