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 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 baseline(block_no, trialNo=6): yield viztask.waitNetwork(serverName) info.setText('Block ' + str(block_no)) info.visible(viz.ON) yield viztask.waitTime(2) info.visible(viz.OFF) yield trials(block_no, 'None', trialNo, 'baseline')
def Practice(block_no, node): ground = GroundCreator() ground.setParent(Target) ground.setPosition([0, -1.5, -1], viz.REL_PARENT) yield viztask.waitNetwork(serverName) info.setText('Block ' + str(block_no)) info.visible(viz.ON) yield viztask.waitTime(2) info.visible(viz.OFF) yield trialSetting_Exp(block_no, node) ground.remove()
def experiment(): yield viztask.waitNetwork(serverName) # the first baseline yield baseline(1) # following offset and baseline conditions yield testing() # finish the experiment info.setText('End of the Experiment.') info.visible(viz.ON) yield viztask.waitTime(45) viz.quit()
def Direction_Exp(offset): #offset = 1 or 3 for i in range(len(Room_Sequence)): block = (i + offset) * 2 if Room_OffsetOrder == 'LR': if i % 2 == 0: viewLink.preEuler([-10, 0, 0], target=viz.LINK_ORI_OP) else: viewLink.preEuler([10, 0, 0], target=viz.LINK_ORI_OP) else: if i % 2 == 0: viewLink.preEuler([10, 0, 0], target=viz.LINK_ORI_OP) else: viewLink.preEuler([-10, 0, 0], target=viz.LINK_ORI_OP) global vis_tg vis_tg = TargetCreator(vis_tg_ht_near, vis_tg_r) vis_tg.setPosition([0, 0, vis_tg_dist_near]) vis_tg.visible(viz.OFF) room_env = room(room_ht, room_wd, room_dep) room_env.setParent(vis_tg) if Room_Sequence[i] == 'C' or Room_Sequence[i] == 'c': room_direction = [45, 0, 0] elif Room_Sequence[i] == 'M' or Room_Sequence[i] == 'm': room_direction = [22.5, 0, 0] elif Room_Sequence[i] == 'F' or Room_Sequence[i] == 'f': room_direction = [0, 0, 0] room_env.setEuler(room_direction, viz.ABS_PARENT) room_env.setPosition( 0, 0, -0.5 * room_wd / np.cos(np.radians(room_direction[0])), viz.REL_PARENT) yield viztask.waitNetwork(serverName) info.setText('Block ' + str(block)) info.visible(viz.ON) yield viztask.waitTime(2) info.visible(viz.OFF) yield trials(block, vis_tg_dist_near) room_env.remove() vis_tg.remove() viewLink.reset(viz.RESET_OPERATORS) yield Baseline(block + 1)
def Distance_Exp(offset): #offset = 1 or 4 for i in range(len(Distance_Sequence)): block = (i + offset) * 2 if Distance_OffsetOrder == 'LR': if i % 2 == 0: viewLink.preEuler([-10, 0, 0], target=viz.LINK_ORI_OP) else: viewLink.preEuler([10, 0, 0], target=viz.LINK_ORI_OP) else: if i % 2 == 0: viewLink.preEuler([10, 0, 0], target=viz.LINK_ORI_OP) else: viewLink.preEuler([-10, 0, 0], target=viz.LINK_ORI_OP) global vis_tg if Distance_Sequence[i] == 'F' or Distance_Sequence[i] == 'f': vis_tg = TargetCreator(vis_tg_ht_far, vis_tg_r_far) vis_tg_dist = vis_tg_dist_far else: vis_tg = TargetCreator(vis_tg_ht_near, vis_tg_r) vis_tg_dist = vis_tg_dist_near vis_tg.visible(viz.OFF) vis_tg.setPosition([0, 0, vis_tg_dist]) global ground ground = GroundCreator(vis_tg) global disks disks = diskCreator(vis_tg) disks.setPosition([0, 0, -vis_tg_dist]) yield viztask.waitNetwork(serverName) info.setText('Block ' + str(block)) info.visible(viz.ON) yield viztask.waitTime(2) info.visible(viz.OFF) yield trials(block, vis_tg_dist, isDisks=True) ground.remove() if disks in globals(): disks.remove() vis_tg.remove() viewLink.reset(viz.RESET_OPERATORS) yield Baseline(block + 1)
def Baseline(block_no): global vis_tg vis_tg = TargetCreator(vis_tg_ht_near, vis_tg_r) vis_tg.setPosition([0, 0, vis_tg_dist_near]) vis_tg.visible(viz.OFF) ground = GroundCreator(vis_tg) yield viztask.waitNetwork(serverName) info.setText('Block ' + str(block_no)) info.visible(viz.ON) yield viztask.waitTime(2) info.visible(viz.OFF) yield trials(block_no, vis_tg_dist_near) ground.remove() vis_tg.remove()
def experiment(): yield viztask.waitNetwork(serverName) yield Baseline(1) if Exp_Sequence == 'RP': yield Direction_Exp(1) yield Distance_Exp(4) else: yield Distance_Exp(1) yield Direction_Exp(3) info.setText('End of the Experiment.') info.visible(viz.ON) yield viztask.waitTime(60) viz.quit()
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 testing(): for i in range(1, 6, 2): block_no = i + 1 currCondition = sceneOrder[block_no/2 - 1] currOffset = offsetOrder[block_no/2 - 1] viewLink.preEuler(offsets[currOffset], target = viz.LINK_ORI_OP) # start the block yield viztask.waitNetwork(serverName) info.setText('Block' + str(block_no)) info.visible(viz.ON) yield viztask.waitTime(2) info.visible(viz.OFF) yield trials(block_no, conditions[currCondition]) # remove offset viewLink.reset(viz.RESET_OPERATORS) yield baseline(block_no + 1)
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 experiment(side): yield viztask.waitNetwork(serverName) yield Practice(1, Target) for i in range(len(Sequence)): block = (i + 1) * 2 if side == 'LR': if i == 0 or i == 2: viewLink.preEuler([-10, 0, 0], target=viz.LINK_ORI_OP) else: viewLink.preEuler([10, 0, 0], target=viz.LINK_ORI_OP) else: if i == 0 or i == 2: viewLink.preEuler([10, 0, 0], target=viz.LINK_ORI_OP) else: viewLink.preEuler([-10, 0, 0], target=viz.LINK_ORI_OP) if Sequence[i] == 'C' or Sequence[i] == 'c': clouds = flashingCloud(3, 12, 12, 1, 5250, Target, freq) refresh = viztask.schedule(refreshing(clouds)) yield viztask.waitNetwork(serverName) info.setText('Block ' + str(block)) info.visible(viz.ON) yield viztask.waitTime(2) info.visible(viz.OFF) yield trialSetting_Exp(block, Target) for c in clouds: c.remove() refresh.kill() elif Sequence[i] == 'L' or Sequence[i] == 'l': yield viztask.waitNetwork(serverName) info.setText('Block ' + str(block)) info.visible(viz.ON) yield viztask.waitTime(2) info.visible(viz.OFF) yield trialSetting_Exp(block, Target) elif Sequence[i] == 'O' or Sequence[i] == 'o': Target.alpha(0) door = door_line(2.5, 0.5, 2) door.setParent(Target) door.setPosition([0, -1.5, 0], viz.REL_PARENT) door.zoffset(-1) outlineRoom = room_line(3, 12, 12, 2) outlineRoom.setParent(Target) outlineRoom.setPosition([0, -1.5, 0], viz.REL_PARENT) yield viztask.waitNetwork(serverName) info.setText('Block ' + str(block)) info.visible(viz.ON) yield viztask.waitTime(2) info.visible(viz.OFF) yield trialSetting_Exp(block, door) door.remove() outlineRoom.remove() Target.alpha(1) elif Sequence[i] == 'F' or Sequence[i] == 'f': Target.alpha(0) door = doorway(2.5, 0.5, 0.025) door.setParent(Target) door.setPosition([0, -1.5, 0], viz.REL_PARENT) door.zoffset(-1) room_env = RoomCreator(12, 12, 3, 1) room_env.setParent(Target) room_env.setPosition([0, -1.5, -11], viz.REL_PARENT) yield viztask.waitNetwork(serverName) info.setText('Block ' + str(block)) info.visible(viz.ON) yield viztask.waitTime(2) info.visible(viz.OFF) yield trialSetting_Exp(block, door) room_env.remove() door.remove() Target.alpha(1) viewLink.reset(viz.RESET_OPERATORS) yield Practice(block + 1, Target) info.setText('End of the Experiment.') info.visible(viz.ON) yield viztask.waitTime(90) viz.quit()