![]() |
|
|
|
#1
|
|||
|
|||
|
So now the question is why am I not getting consistent data collection results?
|
|
#2
|
|||
|
|||
|
I'm not sure, it might be a framerate issue. Did the sample script I posted above give you better results?
|
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
|||
|
|||
|
Did you place your code for collecting samples in the DoSample function? That function will be called at the specified rate.
|
|
#5
|
|||
|
|||
|
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? |
|
#6
|
|||
|
|||
|
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) |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |