WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Timer issues (https://forum.worldviz.com/showthread.php?t=4284)

snovob93 07-04-2012 10:17 PM

Timer issues
 
Below is the script we are using for the project. I wish to add a timer that starts as soon as the file is run and records the time and target number that was touched. It should keep doing this as each target is touched.
Hope someone can help!


import viz
import vizact
import vizproximity
import viztask
import random

#Define session parameters
nTrial = 10;
nTargetList = [1,2,3,1,2,3,1,2,3,1];
#nRandList = random.shuffle(nTargetList)
print nTargetList

viz.setMultiSample(4)
viz.fov(60)
viz.go()

#Create Background and Main View
viz.clearcolor(viz.BLACK)

viz.MainView.setPosition(0,2,-6)

#Create Floor
floor = viz.add('ground.osgb')

#Connect to server at specified IP address
phasespace = viz.add('phasespace.dle',0,'10.3.6.119:2')

#Add first marker
marker1 = phasespace.addMarker(1)

#Target Marker (finger)
marker2 = phasespace.addMarker(5)
ball = viz.add('white_ball.wrl',color=viz.RED,cache=viz.C ACHE_CLONE)
viz.link(marker2,ball, priority=1)

#Create proximity manager
manager = vizproximity.Manager()
manager.setDebug(viz.ON)

#Spheres 1 : 4
spheres = []
sphereSensors = []
sphere1 = viz.add('ball.wrl')
sphere1.setPosition([0,0,0])
spheres.append(sphere1)
#proximity sensor-sphere
sphereSensor1 = vizproximity.Sensor(vizproximity.Box([0.5,0.5,0.5],center=[0,0.1,0]),source=sphere1)
#Add sensors to manager (sphere)
manager.addSensor(sphereSensor1)
sphereSensors.append(sphereSensor1)
sphere2 = viz.add('ball.wrl')
sphere2.setPosition([0,0.5,0])
spheres.append(sphere2)
#proximity sensor-sphere
sphereSensor2 = vizproximity.Sensor(vizproximity.Box([0.5,0.5,0.5],center=[0,0.1,0]),source=sphere2)
#Add sensors to manager (sphere)
manager.addSensor(sphereSensor2)
sphereSensors.append(sphereSensor2)
sphere3 = viz.add('ball.wrl')
sphere3.setPosition([0,1,0])
spheres.append(sphere3)
#proximity sensor-sphere
sphereSensor3 = vizproximity.Sensor(vizproximity.Box([0.5,0.5,0.5],center=[0,0.1,0]),source=sphere3)
#Add sensors to manager (sphere)
manager.addSensor(sphereSensor3)
sphereSensors.append(sphereSensor3)
sphere4 = viz.add('ball.wrl')
sphere4.setPosition([0,1.5,0])
spheres.append(sphere4)
#proximity sensor-sphere
sphereSensor4 = vizproximity.Sensor(vizproximity.Box([0.5,0.5,0.5],center=[0,0.1,0]),source=sphere4)
#Add sensors to manager (sphere)
manager.addSensor(sphereSensor4)
sphereSensors.append(sphereSensor4)


#Add main viewpoint as proximity target
target = vizproximity.Target(marker2)
#Add viewpoint target to manager
manager.addTarget(target)

def destinationsTask():
fade1 = vizact.fadeTo(0,speed=2)
fade2 = vizact.fadeTo(1,speed=2)
spheres[1].addAction(fade1)
spheres[2].addAction(fade1)
spheres[3].addAction(fade1)
x = 1;
while x <= nTrial:
print 'Reach to start.'
yield viztask.waitTime(2)
yield vizproximity.waitEnter(sphereSensors[0])
spheres[0].addAction(fade1)
spheres[nTargetList[x]].addAction(fade2)
print 'Reach to target.'
yield viztask.waitTime(1)
yield vizproximity.waitEnter(sphereSensors[nTargetList[x]])
spheres[nTargetList[x]].addAction(fade1)
spheres[0].addAction(fade2)
x = x + 1;
print 'The end.'

viztask.schedule( destinationsTask() )

Jeff 07-06-2012 06:03 AM

Register a callback function for the EnterProximity event. Within the callback function you can record the sensor and simulation time to a file:
Code:

def EnterProximity(e):
        """@args vizproximity.ProximityEvent()"""
        sensor = e.sensor
        time = viz.getFrameTime()
       
        #record sensor and time to file

manager.onEnter(None,EnterProximity)



All times are GMT -7. The time now is 01:00 PM.

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