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?
|