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-28-2007, 01:17 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Press the F4 key while your script is running and it will display the framerate in the upper left corner of the window.

I was referring to the results of your script that vary between 1700 to 1800 samples recorded.
Reply With Quote
  #2  
Old 11-29-2007, 08:02 AM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
When I press F4 the number keeps rapidly changing. It looks like it's fluctuating between 45-55. I don't know what that means but that's what I got. Is it supposed to be stationary? If so, is there a way to fix that value?
Reply With Quote
  #3  
Old 11-29-2007, 08:32 AM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
Here's the code of what I have:

import viz
import math
import whrandom
import string

viz.go(viz.PROMPT)

# Get subject number from prompt box
promptMesg = viz.get(viz.INITMESG)
if promptMesg == "":
Subnum = 999
Trial = 100

else:
text = string.split(promptMesg)
Subnum = int(text[0])
Trial = int(text[1])

print "Subnum =", Subnum
print "Trial =", Trial

PORT_FOB = 1
NUM_FOB = 6
NUM_DOTS = 900
RADIUS = .5
DATA = 2
AMPLITUDE = .05
X1 = 0
X2 = 64

MAX_SAMPLES = 60.0 * 30.0
SAMPLE_RATE = 1.0 / 30.0
samples = 0

viz.startlayer(viz.POINTS)
viz.vertexcolor(1,1,1)
viz.pointsize(4)

for i in range(0, NUM_DOTS):
x = whrandom.random() - 0.5
y = whrandom.random() - 0.5
z = whrandom.random() - 0.5
length = math.sqrt(x*x + y*y + z*z)
x = x / length * RADIUS
y = y / length * RADIUS
z = z / length * RADIUS
viz.vertex(x, y, z)

sphere = viz.endlayer()
sphere.translate(0,1.8,.2)

flock1 = viz.add('flockofbirds.dls')
#flock2 = viz.add('flockofbirds.dls')
#flock3 = viz.add('flockofbirds.dls')
#flock4 = viz.add('flockofbirds.dls')

flock1.command(6)
#flock2.command(6)
#flock3.command(6)
#flock4.command(6)

tracking_data = open('openloopsine_complex/headdata_'+ str(Subnum) + " " + str(Trial) + '.txt', 'a')
#tracking_data2 = open('openloopsine_complex/hipdata_'+ str(Subnum) + " " + str(Trial) + '.txt', 'a')
#tracking_data3 = open('openloopsine_complex/kneedata_'+ str(Subnum) + " " + str(Trial) + '.txt', 'a')
#tracking_data4 = open('openloopsine_complex/ankledata_'+ 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
# print xmove
sphere.translate(0,1.8,.2+.3*xmove, viz.ABSOLUTE)

if num == 3:
viz.quit()

if num == 1:

#TODO: Process sample

#Increment samples
samples += 1
if samples < MAX_SAMPLES:
viz.starttimer(1,SAMPLE_RATE)
else:
print 'Finished collecting samples'

viz.callback(viz.TIMER_EVENT,mytimer)

def onkeydown(key):
if key == ' ':
viz.starttimer(0,(1.0/30.0), viz.FOREVER)
#Clear samples and start timer
samples = 0
MAX_SAMPLES = 60 * 30
viz.starttimer(1,SAMPLE_RATE)
viz.starttimer(4,(1.0/30.0),viz.FOREVER)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)

In this instance I need it to collect for 60 seconds at a rate of 30 HZ recording from the birds once I press ' ' at which point everything should start. The field of points should only run for 60 seconds and I need to collect at 30Hz for a total of 1800 points. I ran this once so far and I got 1167 points of data.

Additionally, I also need to be able to not have to specify the amount of time that I'm collecting for or the total number of samples I need but rather JUST the sample rate or collection rate. That way I will consistently collect at 30Hz but the amount of data points will vary given the length of the trial (but in each instance will be a multiple of 30 Hz).

What am I missing/doing wrong/why isn't this working?
Reply With Quote
  #4  
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
  #5  
Old 11-29-2007, 09:28 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Also, your framerate should usually be 60. What is your framerate when you run the following basic script?
Code:
import viz
viz.go()
Reply With Quote
  #6  
Old 11-29-2007, 10:17 AM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
Hopefully you can run it now:

Code:
import viz					
import math					
import whrandom 			
import string				

viz.go(viz.PROMPT)			

# Get subject number from prompt box
promptMesg = viz.get(viz.INITMESG)		
if promptMesg == "":					
	Subnum 	= 999						
	Trial	= 100						
	
else:									
	text = string.split(promptMesg)		
	Subnum = int(text[0])  				
	Trial = int(text[1]) 				
	
print "Subnum =", Subnum				
print "Trial =", Trial					

PORT_FOB = 1
NUM_FOB = 6								
NUM_DOTS = 900							
RADIUS = .5								
DATA = 2								
AMPLITUDE = .05							
X1 = 0									
X2 = 64									

MAX_SAMPLES = 60.0 * 30.0
SAMPLE_RATE = 1.0 / 30.0
samples = 0

viz.startlayer(viz.POINTS)				
viz.vertexcolor(1,1,1)					
viz.pointsize(4)						

for i in range(0, NUM_DOTS):			
  x = whrandom.random() - 0.5			 
  y = whrandom.random() - 0.5			
  z = whrandom.random() - 0.5			
  length = math.sqrt(x*x + y*y + z*z)	
  x = x / length * RADIUS				
  y = y / length * RADIUS				
  z = z / length * RADIUS				
  viz.vertex(x, y, z)					

sphere = viz.endlayer()					
sphere.translate(0,1.8,.2)				

flock1 = viz.add('flockofbirds.dls')	
#flock2 = viz.add('flockofbirds.dls')
#flock3 = viz.add('flockofbirds.dls')	
#flock4 = viz.add('flockofbirds.dls')	

flock1.command(6)						
#flock2.command(6)						
#flock3.command(6)						
#flock4.command(6)						

tracking_data = open('openloopsine_complex/headdata_'+ str(Subnum) + " " + str(Trial) + '.txt', 'a')			
#tracking_data2 = open('openloopsine_complex/hipdata_'+ str(Subnum) + " " + str(Trial) + '.txt', 'a')			
#tracking_data3 = open('openloopsine_complex/kneedata_'+ str(Subnum) + " " + str(Trial) + '.txt', 'a')			
#tracking_data4 = open('openloopsine_complex/ankledata_'+ 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												
#		print xmove
		sphere.translate(0,1.8,.2+.3*xmove, viz.ABSOLUTE)		
		
	if num == 3:							
		viz.quit()							

	if num == 1:
		
		#TODO: Process sample
		
		#Increment samples
		samples += 1
		if samples < MAX_SAMPLES:
			viz.starttimer(1,SAMPLE_RATE)
		else:
			print 'Finished collecting samples'
			
viz.callback(viz.TIMER_EVENT,mytimer)

def onkeydown(key):
	if key == ' ':
		viz.starttimer(0,(1.0/30.0), viz.FOREVER)
		#Clear samples and start timer
		samples = 0
		MAX_SAMPLES = 60 * 30
		viz.starttimer(1,SAMPLE_RATE)
		viz.starttimer(4,(1.0/30.0),viz.FOREVER)

viz.callback(viz.KEYDOWN_EVENT,onkeydown)
Reply With Quote
  #7  
Old 11-29-2007, 10:20 AM
Elittdogg Elittdogg is offline
Member
 
Join Date: Aug 2007
Posts: 77
When I run that simple script my fram rate is essentially 60 (it constantly changes between 59 and 60).
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

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 07:52 AM.


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