def proximityTask(): yield vizproximity.waitEnter(sensor1, target1, None) active = [manager.getActiveSensors()] print(active) yield vizproximity.waitEnter(sensor2, target2, None) active += [manager1.getActiveSensors()] print(active) yield vizproximity.waitEnter(sensor3, target3, None) active += [manager2.getActiveSensors()] if (len(active) == 3): finished()
def testPhase(): results = [] if centerSensor not in manager.getActiveSensors(): yield vizproximity.waitEnter(centerSensor) sensor = sphereSensors[0] info.setText("Walk to the sphere now.") startTime = viz.tick() yield vizproximity.waitEnter(sensor) info.setText('Please return to the center of the room') elapsedTime = viz.tick() - startTime results.append((sensor.name, elapsedTime)) info.setText("You're all done now!") viztask.returnValue(results)
def TrialTask(pos): """Task for individual trial. Returns whether pigeon was found.""" #Reset tracker to origin tracker.setPosition([0,1.8,0]) tracker.setEuler([0,0,0]) # Flash screen FlashScreen() # Place pigeon at new location pigeon_root.setPosition(pos) pigeon_root.visible(True) hooting.play(loop=True) # Create proximity sensor for pigeon using main view as target manager = vizproximity.Manager() #manager.setDebug(True) manager.addTarget( vizproximity.Target(viz.MainView) ) sensor = vizproximity.Sensor(vizproximity.Sphere(PROXIMITY_RADIUS),pigeon_root) manager.addSensor(sensor) # Wait until pigeon is found or time runs out wait_time = viztask.waitTask( TrialCountDownTask() ) wait_find = vizproximity.waitEnter(sensor) data = yield viztask.waitAny([wait_time,wait_find]) # Hide pigeon and remove proximity sensor pigeon_root.visible(False) hooting.pause() manager.remove() # Return whether pigeon was found viztask.returnValue(data.condition is wait_find)
def trialSetting_Exp(block_no, node): info.setText("Hurrah!! Please wait for the experimenter.") for m in range(4): yield viztask.waitNetwork(serverName) sub_rt.write('\nBlock ' + str(block_no) + ' Trial ' + str(m + 1)) node.color(viz.ORANGE) Target.visible(viz.ON) myNetwork.send('Ready') yield viztask.waitNetwork(serverName) sound.play() myNetwork.send('Block ' + str(block_no) + ' Trial ' + str(m + 1)) colorChange = viztask.schedule(changeColor(node)) yield vizproximity.waitEnter(sensor_Target) Target.visible(viz.OFF) sound.stop() colorChange.kill() myNetwork.send('Reach Target!') ori = (1 + (-1)**m) * 90 Target.setPosition(SPpos[(-1)**m], mode=viz.ABS_PARENT) Target.setEuler([ori, 0, 0], mode=viz.REL_LOCAL) if m < 3: info.visible(viz.ON) yield viztask.waitTime(3) info.visible(viz.OFF) else: sub_rt.write('\nend of block' + str(block_no)) info.setText('End of Block ' + str(block_no)) info.visible(viz.ON) yield viztask.waitTime(3) info.visible(viz.OFF)
def Collect(objName, objLoc, ScaleFac, tel): viz.MainWindow.setScene(1) #teleport to new location each trial? if tel: x, y = pol2cart(numpy.random.randint(12, radius), numpy.random.randint(0, 360)) viz.MainView.setPosition(x, 0, y) viz.MainView.setEuler(numpy.random.randint(0, 360), 0, 0) #add object obj = viz.addChild(objName + '.osgb') obj.setPosition(objLoc) obj.setScale([ScaleFac, ScaleFac, ScaleFac]) sensor = vizproximity.addBoundingBoxSensor(obj, scale=(1.5, 10, 1.5)) manager.addSensor(sensor) obj.visible(viz.ON) yield vizproximity.waitEnter(sensor) obj.remove() manager.removeSensor(sensor)
def trials(block_no, vis_dist, isDisks=False): info.setText("Hurrah!! Please wait for the experimenter.") for m in range(4): vis_pos = [0, real_tg - vis_dist, vis_dist] sensor_Target = vizproximity.Sensor( vizproximity.RectangleArea([6, 0.1], center=[0, real_tg_dist[(-1)**(m + 1)]]), None) manager.addSensor(sensor_Target) if isDisks: disks.remove() global disks disks = diskCreator(vis_tg) disks.setPosition([0, 0, -vis_dist]) yield viztask.waitNetwork(serverName) sub_rt.write('\nBlock ' + str(block_no) + ' Trial ' + str(m + 1)) vis_tg.color(viz.ORANGE) vis_tg.visible(viz.ON) myNetwork.send('Ready') yield viztask.waitNetwork(serverName) sound.play() myNetwork.send('Block ' + str(block_no) + ' Trial ' + str(m + 1)) colorChange = viztask.schedule(changeColor(vis_tg)) yield vizproximity.waitEnter(sensor_Target) alert.play() print str(block_no) + ' ' + str(m + 1) + ' ' + str( view.getPosition()) + ' ' + str(vis_tg.getPosition()) vis_tg.visible(viz.OFF) sound.stop() colorChange.kill() myNetwork.send('Reach Target!') ori = (1 + (-1)**m) * 90 vistg_p = vis_tg.getPosition() vis_tg.setPosition(vistg_p[0], vistg_p[1], vis_pos[(-1)**m], mode=viz.ABS_PARENT) vis_tg.setEuler([ori, 0, 0], mode=viz.REL_LOCAL) manager.clearSensors() if m < 3: info.visible(viz.ON) yield viztask.waitTime(3) info.visible(viz.OFF) else: sub_rt.write('\nend of block' + str(block_no)) info.setText('End of Block ' + str(block_no)) info.visible(viz.ON) yield viztask.waitTime(3) info.visible(viz.OFF) if isDisks: disks.remove()
def experiment(): for trialN in range(10): if trialN < 9: datafile = 'Trial0' + str(trialN + 1) + '.txt' respfile = 'RT_Trial0' + str(trialN + 1) + time.strftime( "_%d-%b-%y_%H-%M") + '.csv' else: datafile = 'Trial' + str(trialN + 1) + '.txt' respfile = 'RT_Trial' + str(trialN + 1) + time.strftime( "_%d-%b-%y_%H-%M") + '.csv' colors = [] with open(datafile, 'rb') as csvfile: csvreader = csv.reader(csvfile, delimiter=' ') for row in csvreader: colors.append(row) colors = numpy.asarray(colors, dtype=uInt8) # colors = colors[0] strobes = Strobes(x, 100) leds = LEDs(colors, 0.05, 0.9403) vizact.onkeydown('.', leds.recordResp) sensor_Target = vizproximity.Sensor( vizproximity.RectangleArea([4, 0.1], center=[0, real_tg_dist[(-1)**trialN]]), None) manager.addSensor(sensor_Target) # Show where the target is and ask them to face to the target yield viztask.waitKeyDown('a') standBy = viztask.schedule(leds.standby(trialN % 2)) # Turn of the LED to get the experiment ready to start yield viztask.waitKeyDown('s') standBy.kill() leds.all_off() leds.stop() monitor_record_Network.send('Start!') strobes.StartTask() f = viztask.schedule(leds.flashing()) monitor_record_Network.send('Start!') yield vizproximity.waitEnter( sensor_Target) # flash until they enter the target zone f.kill() # Once reach the target turn off both the LEDs and strobes strobes.StopTask() strobes.ClearTask() leds.all_off() leds.stop() leds.clear() # Save the data into a csv file leds.saveAsFile(respfile) manager.clearSensors() yield viztask.waitTime(10) viz.quit()
def walking(): yield viztask.waitKeyDown(' ') male.addAction(vizact.walkTo([1, 0, 0])) yield vizproximity.waitEnter(femaleSensor) female.state(3) yield viztask.waitTime(2) male.state(33) yield viztask.waitTime(3) male.addAction(vizact.walkTo([-4, 0, 0], walkAnim = 70, walkSpeed = 2)) yield vizproximity.waitExit(femaleSensor) female.state(8)
def destinationsTask(): # Action for hiding/showing text DelayHide = vizact.sequence( vizact.waittime(8), vizact.method.visible(False) ) Show = vizact.method.visible(True) yield viztask.waitTime(12) instructions.setText("Walk to the potted plant directly ahead on the opposite side of the courtyard.") instructions.runAction(DelayHide) yield vizproximity.waitEnter(plantSensor) instructions.runAction(Show) instructions.setText("Face the arch side of the courtyard. Walk to the piles of crates directly ahead.") instructions.runAction(DelayHide) yield vizproximity.waitEnter(cratesSensor) instructions.runAction(Show) instructions.setText("Walk into the cafe on the opposite side of the courtyard.") instructions.runAction(DelayHide) yield vizproximity.waitEnter(cafeSensor) instructions.runAction(Show) instructions.setText("Thank you for your participation.") #Show results of experiment print 'Avoided sitting avatar:',avoidSitting print 'Avoided standing avatar:',avoidStanding print 'Avoided dancing avatar:',avoidDancing
def testPhase(): results = [] trials = [3,2,0,4,1] for i in trials: #Check to see if participant is already in room center. If not #wait until the centerSensor is activated if centerSensor not in manager.getActiveSensors(): yield vizproximity.waitEnter(centerSensor) #Get sensor for this trial sensor = sphereSensors[i] #Instruct participant where to go instruction = 'Walk to the {} sphere'.format(sensor.name) info.setText(instruction) #store the time at which this trial started startTime = viz.tick() #The yielded command returns a viz.Data object with information #about the proximity event such as the sensor, target involved yield vizproximity.waitEnter(sensor) info.setText('Please return to the center of the room') #calculate the time it took for the subject to find the correct object elapsedTime = viz.tick() - startTime #save results results.append((sensor.name, elapsedTime)) info.setText('Thank You. You have completed the experiment') #return results viztask.returnValue(results)
def TrialTask(): """Task for individual trial. Returns whether BOMB was found.""" # Flash screen FlashScreen() # Wait until BOMB is found or time runs out wait_time = viztask.waitTask(TrialCountDownTask()) wait_find = vizproximity.waitEnter(sensor) #print wait_find wait_find2 = vizproximity.waitEnter(sensor2) wait_find3 = vizproximity.waitEnter(sensor3) wait_find4 = vizproximity.waitEnter(sensor4) wait_find5 = vizproximity.waitEnter(sensor5) wait_find6 = vizproximity.waitEnter(sensor6) wait_find7 = vizproximity.waitEnter(sensor7) data = yield viztask.waitAny([ wait_time, wait_find, wait_find2, wait_find3, wait_find4, wait_find5, wait_find6, wait_find7 ]) if data.condition == wait_find: manager.removeSensor(sensor) elif data.condition == wait_find2: manager.removeSensor(sensor2) elif data.condition == wait_find3: manager.removeSensor(sensor3) elif data.condition == wait_find4: manager.removeSensor(sensor4) elif data.condition == wait_find5: manager.removeSensor(sensor5) elif data.condition == wait_find6: manager.removeSensor(sensor6) elif data.condition == wait_find7: manager.removeSensor(sensor7) # Return whether bomb was found viztask.returnValue( data.condition is wait_find or data.condition is wait_find2 or data.condition is wait_find3 or data.condition is wait_find4 or data.condition is wait_find5 or data.condition is wait_find6 or data.condition is wait_find7)
def experiment(): for trial in range(10): sensor_Target = vizproximity.Sensor( vizproximity.RectangleArea([4, 0.1], center=[0, real_tg_dist[(-1)**trial]]), None) manager.addSensor(sensor_Target) yield viztask.waitNetwork(serverName) record = viztask.schedule(writing(trial)) yield viztask.waitTime(0.5) yield vizproximity.waitEnter(sensor_Target) winsound.Beep( 800, 1000 ) # Make a sound to notify the participant that he/she has reached the target. record.kill() manager.clearSensors()
def baseline(self): # set num_sphere positions of spheres randomly, spheres have to be touched then next sphere appears # baselines: # 1. spectrum (averaging 90% best 1s windows of the baseline period, has touches and walking but no 'task') # 2. ersp/connectivity: reaches without meaning but different visual feedback # set height of spheres to head - 20cm z_range = 3 # lab restrictions x_range = 2 # lab restrictions height = self.subject.head_sphere.getPosition()[1] - .2 # number of spheres to touch num_sphere = 7 self.log_exp_progress('type:baseline_start;') self.scene.poi_manager.addTarget(self.subject.right_hand_sphere_target) # spawn num_sphere balls and touch them consecutively for i in range(num_sphere): z_pos = random.randrange(0, 2 * z_range + 1) - z_range x_pos = random.randrange(0, 2 * x_range + 1) - x_range pos = [x_pos, height, z_pos] # make a sphere at a random position in the plusminus z and x range sphere = vizshape.addSphere(.1) sphere.color(viz.YELLOW) sphere.setPosition(pos) sphere_sensor = vizproximity.addBoundingSphereSensor(sphere) self.scene.poi_manager.addSensor(sphere_sensor) # yield wait enter hand sphere yield vizproximity.waitEnter(sphere_sensor) self.log_exp_progress('type:baseline_touch;number:' + str(i + 1) + ';') self.scene.poi_manager.removeSensor(sphere_sensor) sphere.remove() self.scene.poi_manager.removeTarget( self.subject.right_hand_sphere_target) self.log_exp_progress('type:baseline_end;')
def crystalBallSceneGo(): global crystalBall globals_oa.globeScene.enable(viz.RENDERING) # viz.fog(0.2) #add globe, spinning crystalBall = globals_oa.globeScene.getChild('crystalBall.osgb') crystalBall.alpha(.7) spinForever = vizact.spin(0,-1,0, 25, dur = viz.FOREVER) crystalBall.addAction(spinForever,0) # fadeInBall = vizact.fadeTo(.7, time = 60) # crystalBall.addAction(fadeInBall,1) globe = globals_oa.globeScene.getChild('earthGlobe.OSGB') spinSome = vizact.spin(0,-1,0, 30, dur=viz.FOREVER) globe.addAction(spinSome,2) yield fader.fadeInTask() #globals_oa.globeScene.playsound('background.wav') # spinForever2 = vizact.spin(0,1,0, 20, dur = viz.FOREVER) yield viztask.waitTime(5) fadeOutGlobe = vizact.fadeTo(0,time = 5) globe.addAction(fadeOutGlobe,3) yield viztask.waitTime(8) globe.remove() manager = vizproximity.Manager() manager.setDebug(False) #make true to see the outline of the proximity sensor rightHandTarget = vizproximity.Target(globals_oa.rightHand) leftHandTarget = vizproximity.Target(globals_oa.leftHand) ballSensor = vizproximity.Sensor(vizproximity.Sphere(1.5, center=[0,5.5,0]), source=crystalBall) manager.addTarget(rightHandTarget) manager.addTarget(leftHandTarget) manager.addSensor(ballSensor) yield vizproximity.waitEnter(ballSensor) # yield viztask.waitKeyDown('/') globals_oa.AUDIO_SUCCESS.play() yield fader.fadeOutTask() globals_oa.globeScene.remove() crystalBall.remove()
def proximityTask1(): yield vizproximity.waitEnter(cylinder1_sensor)
def crystalBallSceneGo(): # try: global crystalBall, skipKey viz.clip(.1,100000) globals_oa.globeScene.enable(viz.RENDERING) viz.fogcolor(viz.BLACK) viz.fog(0.2) #add globe and crystal ball, spinning crystalBall = globals_oa.globeScene.getChild('crystalBall.OSGB') crystalBall.alpha(.7) floor = globals_oa.globeScene.getChild('sceneFloor.osgb') #GenerateStarDome(150000,2,0,2000, 1, 0) spinForever = vizact.spin(0,-1,0, 25, dur = viz.FOREVER) crystalBall.addAction(spinForever,0) globe = globals_oa.globeScene.getChild('earthGlobe.OSGB') spinSome = vizact.spin(0,-1,0, 30, dur=viz.FOREVER) globe.addAction(spinSome,2) yield globals_oa.fader.fadeInTask() #play audio file globeAudio1 = globals_oa.GLOBE_SCENE_AUDIO1 globeAudio2 = globals_oa.GLOBE_SCENE_AUDIO2 globeAudio1.play() globeAudio2.play() if globals_oa.skippingActivated: raise MyException() # spinForever2 = vizact.spin(0,1,0, 20, dur = viz.FOREVER) # yield viztask.waitTime(20) yield viztask.waitAny([viztask.waitTime(20), skipKey]) crystalBall.visible(viz.OFF) fadeOutGlobe = vizact.fadeTo(0,time = 3) globe.addAction(fadeOutGlobe, 3) yield viztask.waitActionEnd(globe, fadeOutGlobe) globe.remove() crystalBall.visible(viz.ON) # yield viztask.waitTime(8) yield viztask.waitAny([viztask.waitTime(6), skipKey]) manager = vizproximity.Manager() manager.setDebug(False) #make true to see the outline of the proximity sensor rightHandTarget = vizproximity.Target(globals_oa.rightHand) leftHandTarget = vizproximity.Target(globals_oa.leftHand) ballSensor = vizproximity.Sensor(vizproximity.Sphere(3, center=[0,5.5,0]), source=crystalBall) manager.addTarget(rightHandTarget) manager.addTarget(leftHandTarget) manager.addSensor(ballSensor) yield viztask.waitTime(globeAudio2.getDuration()-33) failAudio = globals_oa.GLOBE_FAIL_AUDIO failTimer = vizact.ontimer(5 + failAudio.getDuration(), failAudio.play) yield vizproximity.waitEnter(ballSensor) # failTimer = vizact.ontimer(5 + failAudio.getDuration(),playWrapper, failAudio) failTimer.remove() # yield viztask.waitKeyDown('/') globals_oa.AUDIO_SUCCESS.play() yield globals_oa.fader.fadeOutTask() globals_oa.globeScene.disable(viz.RENDERING) globals_oa.GLOBE_SCENE_AUDIO1.stop() viz.fog(0)
def trials(block_no, isPoles='None', trialNo=10, trialtype='Offset', continued=False): info.setText("Hurrah!! Please wait for the experimenter.") if isPoles in ['flipped', 'staying']: poles, polelist = poleCreator(ground, pole_wd, pole_dep, pole_ht, pole_no) writePolePos(isPoles, polelist) for m in range(trialNo): # Set up the response recording file global sub_rt if continued: sub_rt = open( 'VRrt_' + str(id) + '_Block_' + str(block_no) + '_Trial_' + str(m + 9) + '_' + time.strftime("%d-%b-%y_%H-%M") + '.csv', 'a') else: sub_rt = open( 'VRrt_' + str(id) + '_Block_' + str(block_no) + '_Trial_' + str(m + 1) + '_' + time.strftime("%d-%b-%y_%H-%M") + '.csv', 'a') data = 'frameNo,Color,TimeStamp,Response' sub_rt.write('\n' + data) # Set up the real target sensor area sensor_Target = vizproximity.Sensor( vizproximity.RectangleArea([6, 0.1], center=[0, real_tg_dist[(-1)**(m + 1)]]), None) manager.addSensor(sensor_Target) # Set up poles if they change between trials if isPoles == 'changing': poles, polelist = poleCreator(ground, pole_wd, pole_dep, pole_ht, pole_no) writePolePos(isPoles, polelist) elif isPoles == 'flipped': poles.setEuler([(90 * (1 - (-1)**m)), 0, 0], mode=viz.ABS_PARENT) poles.setPosition([0, 0, polePos[(-1)**(m)]], mode=viz.ABS_PARENT) # Stand by yield viztask.waitNetwork(serverName) # choose target depending on walking direction if isPoles == 'flipped': if flippedTarget == 'BO': if m % 2 == 0: Target2.alpha(0) Target1.color(tg2Color) else: Target1.alpha(0) Target2.color(tg2Color) else: if m % 2 == 0: Target2.alpha(0) Target1.color(tg1Color) else: Target1.alpha(0) Target2.color(tg1Color) viz.window.screenCapture('flipped_Image_' + str(m) + '.jpg') else: if m % 2 == 0: Target2.alpha(0) Target1.color(tg1Color) else: Target1.alpha(0) Target2.color(tg2Color) viz.window.screenCapture(isPoles + '_Image_' + str(m) + '.jpg') ground.visible(viz.ON) labNetwork.send('Ready') # Start walking yield viztask.waitNetwork(serverName) metronome.play() if isPoles == 'flipped': if flippedTarget == 'BO': if m % 2 == 0: colorChange = viztask.schedule(changeColor2(Target1)) else: colorChange = viztask.schedule(changeColor2()) else: if m % 2 == 0: colorChange = viztask.schedule(changeColor1()) else: colorChange = viztask.schedule(changeColor1(Target2)) else: if m % 2 == 0: colorChange = viztask.schedule(changeColor1()) else: colorChange = viztask.schedule(changeColor2()) labNetwork.send('Block' + str(block_no) + ' Trial ' + str(m)) yield viztask.waitTime(0.25) # reach the target yield vizproximity.waitEnter(sensor_Target) alert.play() metronome.stop() viz.clearcolor(viz.BLACK) ground.visible(viz.OFF) colorChange.kill() labNetwork.send('Reach Target!') manager.clearSensors() print Target1.getPosition(viz.ABS_GLOBAL) print Target2.getPosition(viz.ABS_GLOBAL) # Set up the information for participants at the end of trial if m < trialNo - 1: info.visible(viz.ON) yield viztask.waitTime(3) info.visible(viz.OFF) if isPoles == 'changing': poles.remove() else: # finish writing the response info.setText('End of Block ' + str(block_no)) info.visible(viz.ON) yield viztask.waitTime(3) info.visible(viz.OFF) if isPoles != 'None': poles.remove() # reset the targets if m % 2 == 0: Target2.alpha(1) else: Target1.alpha(1)
def cityScene(): global city, skyDome2, CRYSTAL_EVENT, moleculeList, rightHandTarget, leftHandTarget global mole1, mole2, mole3 global mole4, mole5, mole6, mole7, mole8, mole9, mole10, mole11 print "city scene starting" globals_oa.CITY_SCENE_AMBIENT.play() city.enable(viz.RENDERING) viz.fog(0) arrow = city.getChild('greenArrow.OSGB') arrow.disable(viz.RENDERING) tube = city.getChild('yellowTube.OSGB') tube.disable(viz.RENDERING) yield globals_oa.fader.fadeInTask() # yield viztask.waitTime(3) yield viztask.waitAny([viztask.waitTime(3), skipKey]) # carAudio1 = globals_oa.CAR_SCENE1 # carAudio1.play() ## yield viztask.waitMediaEnd(carAudio1) # yield viztask.waitAny([viztask.waitTime(10), skipKey]) carAudio2 = globals_oa.CAR_SCENE2 carAudio2.play() arrow.enable(viz.RENDERING) fadeIn = vizact.fadeTo(1, time=1) fadeOut = vizact.fadeTo(0, time=1) sequence = vizact.sequence(fadeIn, fadeOut, viz.FOREVER) arrow.add(sequence) # yield viztask.waitMediaEnd(carAudio2) yield viztask.waitAny([viztask.waitTime(7), skipKey]) carAudio3 = globals_oa.CAR_SCENE3 carAudio3.play() arrow.disable(viz.RENDERING) manager = vizproximity.Manager() manager.setDebug(False) rightHandTarget = vizproximity.Target(globals_oa.rightHand) leftHandTarget = vizproximity.Target(globals_oa.leftHand) car1 = city.getChild('BlueCar.OSGB') exhaust = city.getChild('p_silencer-OFFSET') car1Sensor = vizproximity.Sensor(vizproximity.Box([0.5,0.7,0.4], center=[1.4,4.2,0]), source=exhaust) manager.addTarget(rightHandTarget) manager.addTarget(leftHandTarget) manager.addSensor(car1Sensor) tube.enable(viz.RENDERING) tube.add(sequence) # car1Sensor = vizproximity.Sensor(vizproximity.Box([3.3,1.6,1.8], center=[5,0.4,-10.5]), source=car1) if carAudio3.audioObj.getState() == viz.MEDIA_RUNNING: # yield viztask.waitMediaEnd(carAudio3) yield viztask.waitAny([viztask.waitTime(4), skipKey]) # manager.addTarget(rightHandTarget) # manager.addTarget(leftHandTarget) # manager.addSensor(car1Sensor) # CAR_TOUCHED = False failAudio = globals_oa.CAR_FAIL_AUDIO failAudio.stop() failTimer = vizact.ontimer(5 + failAudio.getDuration(), playWrapper, failAudio) #yield vizproximity.waitEnter(car1Sensor) def vibrateRightHand(): globals_oa.rhViveTracker.setVibration(0.004) def vibrateLeftHand(): globals_oa.lhViveTracker.setVibration(0.004) def onEnter(e): global rightHandTarget, leftHandTarget print 'working' if e.target == rightHandTarget: vizact.ontimer2(.004, 100, vibrateRightHand) if e.target == leftHandTarget: vizact.ontimer2(.004, 100, vibrateLeftHand) manager.onEnter(car1Sensor, onEnter) def startCar1(): global mole1, mole2, mole3, moleculeList mole1 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE1) moleculeList.append(mole1) mole1.setPosition([-1.2, 0.35, -0.08]) mole1.setScale([3,3,3]) mole1.setAnimationSpeed(3) mole1.setEuler(-90,0,0) mole2 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) moleculeList.append(mole2) mole2.setPosition([-1.1,0.3,0]) mole2.setScale([3,3,3]) mole2.setAnimationSpeed(2.1) mole2.setEuler(-90,0,0) mole3 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) moleculeList.append(mole3) mole3.setPosition([-1.05,0.29,-0.05]) mole3.setScale([3,3,3]) mole3.setAnimationSpeed(5) mole3.setEuler(-90,0,0) def floatersGo(): global mole4, mole5, mole6, mole7, mole8, mole9, mole10, mole11, moleculeList mole4 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE1) moleculeList.append(mole4) mole4.setPosition([-.2,2.9,0]) mole4.setEuler([0,-90,0]) mole4.setScale([3,3,3]) mole4.setAnimationSpeed(2) mole5 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) moleculeList.append(mole5) mole5.setPosition([-.2,2.9,0]) mole5.setEuler([90,-90,0]) mole5.setScale([3,3,3]) mole5.setAnimationSpeed(2) mole6 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE1) moleculeList.append(mole6) mole6.setPosition([-.2,2.9,0]) mole6.setEuler([180,-90,0]) mole6.setScale([3,3,3]) mole6.setAnimationSpeed(2) mole7 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) moleculeList.append(mole7) mole7.setPosition([-.2,2.9,0]) mole7.setEuler([-90,-90,0]) mole7.setScale([3,3,3]) mole7.setAnimationSpeed(2) mole8 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) moleculeList.append(mole8) mole8.setPosition([-.2,2.9,0]) mole8.setEuler([-45,-90,0]) mole8.setScale([3,3,3]) mole8.setAnimationSpeed(2) mole9 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) moleculeList.append(mole9) mole9.setPosition([-.2,2.9,0]) mole9.setEuler([45,-90,0]) mole9.setScale([3,3,3]) mole9.setAnimationSpeed(2) mole10 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) moleculeList.append(mole10) mole10.setPosition([-.2,2.9,0]) mole10.setEuler([-135,-90,0]) mole10.setScale([3,3,3]) mole10.setAnimationSpeed(2) mole11 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) moleculeList.append(mole11) mole11.setPosition([-.2,2.9,0]) mole11.setEuler([135,-90,0]) mole11.setScale([3,3,3]) mole11.setAnimationSpeed(2) def goSpecialMole(): global specialMole yield viztask.waitTime(1) specialMole = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE3) specialMole.setPosition([-1.33023,0.35456,-0.04151]) specialMole.setScale([4,4,4]) lowPolyMole = specialMole.getChild('singleCO2_noAnimation.OSGB') lowPolyMole.disable(viz.RENDERING) path = viz.addAnimationPath() path.addControlPoint(0, pos=[-1.33023,0.35456,-0.04151], euler=(90,0,0), scale= ([4,4,4])) path.addControlPoint(1, pos=[-1,0.4, 0], euler=(45,0,0), scale = ([4,4,4])) path.addControlPoint(2, pos=[-0.8,0.9,0.1], euler=(0,0,0), scale = ([4,4,4])) path.addControlPoint(3, pos=[-0.4,1.3,0.2], euler=(90,0,0), scale = ([4,4,4])) pathLink = viz.link(path, specialMole) path.play() def flyOut(): global specialMole, skipKey yield viztask.waitTime(1) path = viz.addAnimationPath() path.addControlPoint(0, pos=[-0.4,1.3,0.2], euler=(90,0,0), scale= ([4,4,4])) path.addControlPoint(1, pos=[-0.4,1.5,0.6], euler=(55,0,0), scale= ([4,4,4])) path.addControlPoint(2, pos=[-0.4,3.3,0.1], euler=(100,0,0), scale= ([4,4,4])) path.addControlPoint(3, pos=[-0.4,4.8,0.8], euler=(75,0,0), scale= ([4,4,4])) path.addControlPoint(50, pos=[-0.4,70,0.4], euler=(90,0,0), scale = ([4,4,4])) pathLink = viz.link(path, specialMole) path.play() # yield viztask.waitKeyDown('/') yield vizproximity.waitEnter(car1Sensor) failTimer.remove() tube.disable(viz.RENDERING) globals_oa.CAR_START.play() things = vizact.ontimer2(1,10, startCar1) yield things yield vizact.waittime(1.5) things2 = vizact.ontimer2(1,10, floatersGo) globals_oa.CAR_SCENE4.play() yield things2 yield vizact.waittime(1.5) # yield viztask.waitMediaEnd(globals_oa.CAR_SCENE4) yield viztask.waitAny([viztask.waitTime(15), skipKey]) yield goSpecialMole() viztask.waitTime(3) globals_oa.CAR_SCENE5.play() # yield viztask.waitMediaEnd(globals_oa.CAR_SCENE5) yield viztask.waitAny([viztask.waitTime(6), skipKey]) yield flyOut() yield viztask.waitTime(6) # childList = range(1,160) # for child in childList: # object = viz.VizChild(child) # object.remove() for mole in moleculeList: mole.remove() yield globals_oa.fader.fadeOutTask() globals_oa.CITY_SCENE_AMBIENT.stop() city.remove() print "sending city end event" viz.sendEvent(globals_oa.CITY_SCENE_END_EVENT)
def enterRoom(): yield vizproximity.waitEnter(sensor) vizact.ontimer(0, faceView) while True: yield spawnMan()
def cityScene(): global city, skyDome2 city.enable(viz.RENDERING) skyDome2.enable(viz.RENDERING) yield fader.fadeInTask() manager = vizproximity.Manager() manager.setDebug(False) rightHandTarget = vizproximity.Target(globals_oa.rightHand) leftHandTarget = vizproximity.Target(globals_oa.leftHand) car1 = city.getChild('BlueCar.OSGB') car1Sensor = vizproximity.Sensor(vizproximity.Box([3.3,1.6,1.8], center=[5,0.4,-10.5]), source=car1) manager.addTarget(rightHandTarget) manager.addTarget(leftHandTarget) manager.addSensor(car1Sensor) CAR_TOUCHED = False def startCar1(): mole1 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE1) mole1.setPosition([-1.2, 0.35, -0.08]) mole1.setScale([3,3,3]) mole1.setAnimationSpeed(3) mole1.setEuler(-90,0,0) mole2 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) mole2.setPosition([-1.1,0.3,0]) mole2.setScale([3,3,3]) mole2.setAnimationSpeed(2.1) mole2.setEuler(-90,0,0) mole3 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) mole3.setPosition([-1.05,0.29,-0.05]) mole3.setScale([3,3,3]) mole3.setAnimationSpeed(5) mole3.setEuler(-90,0,0) def floatersGo(): mole4 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE1) mole4.setPosition([-.2,2.9,0]) mole4.setEuler([0,-90,0]) mole4.setScale([3,3,3]) mole4.setAnimationSpeed(2) mole5 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) mole5.setPosition([-.2,2.9,0]) mole5.setEuler([90,-90,0]) mole5.setScale([3,3,3]) mole5.setAnimationSpeed(2) mole6 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE1) mole6.setPosition([-.2,2.9,0]) mole6.setEuler([180,-90,0]) mole6.setScale([3,3,3]) mole6.setAnimationSpeed(2) mole7 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) mole7.setPosition([-.2,2.9,0]) mole7.setEuler([-90,-90,0]) mole7.setScale([3,3,3]) mole7.setAnimationSpeed(2) mole8 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) mole8.setPosition([-.2,2.9,0]) mole8.setEuler([-45,-90,0]) mole8.setScale([3,3,3]) mole8.setAnimationSpeed(2) mole9 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) mole9.setPosition([-.2,2.9,0]) mole9.setEuler([45,-90,0]) mole9.setScale([3,3,3]) mole9.setAnimationSpeed(2) mole10 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) mole10.setPosition([-.2,2.9,0]) mole10.setEuler([-135,-90,0]) mole10.setScale([3,3,3]) mole10.setAnimationSpeed(2) mole11 = vizfx.addChild(globals_oa.FILE_PATH_TO_MOLECULE2) mole11.setPosition([-.2,2.9,0]) mole11.setEuler([135,-90,0]) mole11.setScale([3,3,3]) mole11.setAnimationSpeed(2) yield vizproximity.waitEnter(car1Sensor) globals_oa.AUDIO_SUCCESS.play() yield vizact.ontimer2(1,10, startCar1) yield vizact.waittime(1.5) yield vizact.ontimer2(1,10, floatersGo) yield viztask.waitTime(100)
def proximityTask1(): #Play beautiful music yield vizproximity.waitEnter(drum_tom_sensor)
def stageAxes(self, NAxes, relSpeed, holes): # Function for swinging the axes def swing(object, t, startAngle, endAngle): d = (math.sin(t[0]) + 1.0) / 2.0 angle = startAngle + d * (endAngle - startAngle) object.setEuler([90,0,angle]) t[0] += 0.03 * relSpeed # Add axes beginPosition = 400 endPosition = 6600 nrAxes = NAxes self.axes = [] self.axest = [] self.swoosh = [] for i in range(nrAxes): self.axes.append(viz.addChild('axe.OSGB', cache=viz.CACHE_CLONE)) self.axes[i].setPosition([beginPosition+i*(endPosition/nrAxes),750,0], viz.REL_LOCAL) self.axest.append([float(i)]) sound_node = viz.addGroup(pos=[beginPosition+i*(endPosition/nrAxes),75,0]) self.swoosh.append(sound_node.playsound('swoosh.wav')) self.swoosh[i].minmax(0, 20) vizact.ontimer(3.14/relSpeed, self.swoosh[i].play) vizact.ontimer(0.03, swing, self.axes[i], self.axest[i], 120, 240) # Add ducky self.newduck = viz.addAvatar('duck.cfg') self.newduck.setScale([170,170,170]) self.newduck.setPosition([7200,0,0],viz.REL_LOCAL) self.newduck.setEuler([-90,0,0]) # Add proximity sensors manager = vizproximity.Manager() target = vizproximity.Target(viz.MainView) manager.addTarget(target) self.axesensors = [] for i in range(nrAxes): self.axesensors.append(vizproximity.addBoundingBoxSensor(self.axes[i])) manager.addSensor(self.axesensors[i]) duckSensor = vizproximity.addBoundingBoxSensor(self.newduck,scale=(2.5,2.5,3)) manager.addSensor(duckSensor) # Boolean variables to store trial results self.axesHit = [] for i in range(nrAxes): self.axesHit.append(0) # for i in range(nrAxes): # sensors.append(vizproximity.addBoundingBoxSensor(self.axes[i])) # manager.addSensor(sensors[i]) holeCoordinates = [ [755,0,95], [755,0,-98], [1391,0,-1.5], [2017,0,98], [2503,0,-5], [2987,0,-108], [3776,0,-55], [4726,0,49], [5525,0,95], [5525,0,-104], [6011,0,-7]] self.holesensor = [] k=-1 for hole in holeCoordinates: k+=1 self.holesensor.append(vizproximity.Sensor(vizproximity.Box([50,300,100],center=hole),source=viz.Matrix.translate(0,0,0))) manager.addSensor(self.holesensor[k]) self.holesHit = [] for i in range(len(self.holesensor)): self.holesHit.append(0) # Called when we enter a proximity def EnterProximity(e): for i in range(nrAxes): if e.sensor == self.axesensors[i]: self.axesHit[i] += 1 print "Hit axe #" + str(i) + " " + str(self.axesHit[i]) + " times!" if holes: for i in range(len(self.holesensor)): if e.sensor == self.holesensor[i]: self.holesHit[i] += 1 print "Hit hole #" + str(i) + " " + str(self.holesHit[i]) + " times!" manager.onEnter(None,EnterProximity) #Add info panel to display messages to participant self.instructions = vizinfo.InfoPanel(icon=False,key=None) vizact.onkeydown('g',manager.setDebug,viz.TOGGLE) # Action for hiding/showing text DelayHide = vizact.sequence( vizact.waittime(8), vizact.method.visible(False) ) Show = vizact.method.visible(True) #instructions.setText("Reach the duck."+str(self.time)) self.startTime = viz.tick() print "done with scene, awaiting duck" print "----------Begin stage "+str(self.stage)+"----------" # When finished yield vizproximity.waitEnter(duckSensor) self.elapsedTime = viz.tick() - self.startTime self.elapsedTime = str(round(self.elapsedTime,2)) yayString = "Total number of axes hit: " if NAxes>0: yayString += str(self.axesHit[0]) for i in range(1, nrAxes): yayString += ", " + str(self.axesHit[i]) if holes: yayString += ".\nTotal number of holes hit: " for i in range(len(self.holesensor)): yayString += ", " + str(self.holesHit[i]) yayString += ".\nTime is: " + str(self.elapsedTime) print yayString self.tracking_data.write(yayString) print "----------End stage----------"
def proximityTask1(): yield vizproximity.waitEnter(left_plane_sensor)
def trial(self): # trial start marker with landmark positions start_pos = 'start_pos:' + str(self.maze.start_pos) + ';' end_pos = 'end_pos:' + str(self.maze.end_pos) + ';' global_pos = 'global_pos:' + str( self.maze.global_landmark.getPosition()) + ';' self.log_exp_progress('type:trial_start;' + start_pos + end_pos + global_pos) # baseline print '!!! BASELINE START !!!' yield self.baseline() print '!!! BASELINE END -> FIND START !!!' # show start of maze and let participant go there self.maze.maze_start_sphere.visible(viz.ON) self.maze.start_arrow.visible(viz.ON) self.maze.maze_start_ground.visible(viz.ON) # add to proximity manager self.scene.poi_manager.addSensor(self.maze.maze_start_sphere_sensor) self.scene.poi_manager.addTarget(self.subject.right_hand_sphere_target) # yield wait enter hand sphere yield vizproximity.waitEnter(self.maze.maze_start_sphere_sensor) self.log_exp_progress('type:arrived_at_start_position;') self.maze.maze_start_sphere.visible(viz.OFF) self.maze.start_arrow.visible(viz.OFF) self.maze.maze_start_ground.visible(viz.OFF) # remove from proximity manager self.scene.poi_manager.removeSensor(self.maze.maze_start_sphere_sensor) self.scene.poi_manager.removeTarget( self.subject.right_hand_sphere_target) # wait for experimenter to click window once via remote to start trial print '!!! CLICK MOUSE TO START EXPLORATION !!!' yield self.hide_inst_continue_left_mouse() yield self.scene.countdown(5) # countdown to start ### Trial Procedure Start ### self.log_exp_progress('type:navigation_start;') start = viz.tick() # enable collision viz.phys.enable() # start intersection check for both head and hand against the maze walls self.hand_t1_pos = self.subject.right_hand_sphere.getPosition() self.head_t1_pos = self.subject.head_sphere.getPosition() hand_feedback = vizact.onupdate(0, self.check_node_intersection, self.subject.right_hand_sphere, self.maze.walls) head_feedback = vizact.onupdate(0, self.check_node_intersection, self.subject.head_sphere, self.maze.walls) # add head sphere to proximity manager and register callbacks for end and start ground self.scene.poi_manager.addTarget(self.subject.head_sphere_target) self.scene.poi_manager.addSensor(self.maze.maze_start_position.ground) self.scene.poi_manager.addSensor(self.maze.maze_end_position.ground) head_landmark_enter = self.scene.poi_manager.onEnter( None, self.enter_local_landmark) head_landmark_exit = self.scene.poi_manager.onExit( None, self.exit_local_landmark) # [BPA 2019-04-29] make global landmark visible self.maze.global_landmark.visible(viz.ON) # now wait until subjects found the end of the maze yield vizproximity.waitEnter(self.maze.maze_end_position.ground) print '!!! END REACHED: POINTING TASK, PARTICIPANT NEEDS TO POINT AND CLICK WITH CONTROLLER !!!' # temporarily remove proximity target head while doing the pointing task when sensor is first entered self.scene.poi_manager.clearTargets() yield self.pointing(start) print '!!! POINTED BACK TO START NOW EXPLORE BACK TO START!!!' self.scene.poi_manager.addTarget(self.subject.head_sphere_target) # then wait till subjects returned to the start position yield vizproximity.waitEnter(self.maze.maze_start_position.ground) print '!!! START REACHED: RVD & REWALKING TASK COMING UP... PARTICIPANTS NEEDS TO CLICK TRIGGER TO START!!!' # performance measures for reward and analysis end = viz.tick() self.duration = end - start duration_return = end - self.start_return performance = 'type:navigation_end;duration:' + str(round(self.duration, 2)) + \ ';total_touches:' + str(self.hand_hits) + \ ';duration_return:' + str(round(duration_return, 2)) + ';' self.log_exp_progress(performance) # remove all the proximity sensors and the target and unregister the callbacks self.scene.poi_manager.clearTargets() self.scene.poi_manager.clearSensors() head_landmark_enter.remove() head_landmark_exit.remove() # remove wall collisions hand_feedback.remove() head_feedback.remove() # reset wall touches if self.feedback_hand is not None: self.reset_touching() # [BPA 2019-04-29] remove landmark self.scene.toggle_global_landmark(self.maze, "off") # show reward for 5 seconds self.log_exp_progress('type:reward_start;') yield self.scene.reward_feedback(self.head_hits, self.duration, 3) self.log_exp_progress('type:reward_end;') # start testaufgaben self.scene.change_instruction("Es folgen die Testaufgaben.\n" "weiter durch Klick!") yield self.hide_inst_continue_trigger() # start spatial tasks with turning around print '!!! REORIENTING... !!!' yield self.reorient() # RVD Task yield self.rvd_task() # walk maze task yield self.walk_maze_task() # trial end marker self.log_exp_progress('type:trial_end;') print '!!! TRIAL END !!!' ### Trial Procedure End ### if not self.current_maze is 'I' and self.current_trial_run < 3: # Beginn next trial mit Baseline print '!!! START NEXT RUN WITH N KEY !!!' self.scene.change_instruction("Bitte beim Versuchsleiter melden!") yield viztask.waitKeyDown('n') self.scene.hide_instruction()