WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rating: Thread Rating: 3 votes, 5.00 average. Display Modes
  #1  
Old 11-30-2007, 08:37 AM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
The sample script didn't really do anything. Maybe I'm not implementing it correctly, but I can't seem to get consistent results. When I'm running a script other than just that simple script the frame rate fluctuates around 49. Anyway, is there a way that I'm supposed to put your sample script within the code I have to make it work? Because what I did didn't do anything.
Reply With Quote
  #2  
Old 11-30-2007, 02:45 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Cool

Did you place your code for collecting samples in the DoSample function? That function will be called at the specified rate.
Reply With Quote
  #3  
Old 12-03-2007, 08:39 AM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
This is what I did:

Code:
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
	flock1 = viz.add('flockofbirds.dls')	
	flock1.command(6)
	tracking_data = open('openloopsine_complex/headdata_'+ str(Subnum) + " " + str(Trial) + '.txt', 'a')
	def mytimer(num):
		if num == 0:
			global AMPLITUDE, TOTALCYCLES, X1, X2, samples
			
			data1 = flock1.get()
			
			HEADLAT = data1[0]
			HEADVERT = data1[1]
			HEADAP = data1[2]
			HEADYAW = data1[3]
			HEADPITCH = data1[4]
			HEADROLL = data1[5]
			
			head_data = str(Subnum) + '\t' + str(Trial) + '\t' + str(HEADAP) + '\t' +str(HEADLAT) + '\t' +str(HEADVERT) + '\t' +str(HEADYAW) + '\t' +str(HEADPITCH) + '\t' +str(HEADROLL) +'\n'
			tracking_data.write(head_data)	
		if num == 4:
			xmove = AMPLITUDE*math.sin(2*(math.pi/180)*X1) + AMPLITUDE*math.sin(2.5*(math.pi/180)*X1) + AMPLITUDE*math.sin(3.5*(math.pi/180)*X1) + AMPLITUDE*math.sin(1.75*(math.pi/180)*X1) + AMPLITUDE*math.sin(2*(math.pi/180)*X1) + AMPLITUDE*math.sin(2.5*(math.pi/180)*X1) + AMPLITUDE*math.sin(3*(math.pi/180)*X1) + AMPLITUDE*math.sin(2.5*(math.pi/180)*X1)+ AMPLITUDE*math.sin(2*(math.pi/180)*X1) + AMPLITUDE*math.sin(1.75*(math.pi/180)*X1)
			X1 = X1 + 1	
			sphere.translate(0,1.8,.2+.3*xmove, viz.ABSOLUTE)
		if num == 3:
			viz.quit()	
	pass

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

#Start the sampler
sampler.start()

viz.callback(viz.TIMER_EVENT,mytimer)

def onkeydown(key):
	if key == ' ':
		viz.starttimer(0,(1.0/30.0), viz.FOREVER)
		viz.starttimer(4,(1.0/30.0),viz.FOREVER)
		viz.starttimer(3,60,1)
viz.callback(viz.KEYDOWN_EVENT,onkeydown)

I think my problem is that I don't know how to embed "mytimer" within "dosample." Because even when I try different indentations it doesn't start at all. And it keeps giving me this error message:
Traceback (most recent call last):
File "<string>", line 12, in ?
File "openloopsine(complex)_adjusted timer3.py", line 111, in ?
viz.callback(viz.TIMER_EVENT,mytimer)
NameError: name 'mytimer' is not defined

So I'm assuming that it's not registering it as it's own identity/function but I'm a bit confused as to how that would work. Would I have to change "dosample" to a class? And if so, would the rest stay the same?
Reply With Quote
  #4  
Old 12-04-2007, 09:37 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
You only need to place your timer code inside the DoSample function. Everything else should be outside the function. So it should looke something like this:
Code:
def DoSample():
	global AMPLITUDE, TOTALCYCLES, X1, X2, samples

	data1 = flock1.get()

	HEADLAT = data1[0]
	HEADVERT = data1[1]
	HEADAP = data1[2]
	HEADYAW = data1[3]
	HEADPITCH = data1[4]
	HEADROLL = data1[5]

	head_data = str(Subnum) + '\t' + str(Trial) + '\t' + str(HEADAP) + '\t' +str(HEADLAT) + '\t' +str(HEADVERT) + '\t' +str(HEADYAW) + '\t' +str(HEADPITCH) + '\t' +str(HEADROLL) +'\n'
	tracking_data.write(head_data)
Reply With Quote
Reply


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 06:53 PM.


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