Esempio n. 1
0
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()
Esempio n. 2
0
 def __init__(self, plane, planepos, escena, next, sound):
     self.plane = viz.addChild(plane, scene=escena)
     self.plane.setScale(2.5, 2.5, 2.5)
     self.plane.setPosition(planepos[0], planepos[1])
     self.sensorPlane = vizproximity.Sensor(
         vizproximity.RectangleArea(
             [2, 10], center=[self.plane.getPosition(0)[0], 0]), None)
     self.chimesound = sound
     self.next = next
Esempio n. 3
0
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()
Esempio n. 4
0
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 __init__(self, name, edge_length, position, proximity_manager):
        """

            Args:
                name:
                edge_length:
                position:
                proximity_manager:

        """

        self.name = name
        self.edge_length = edge_length
        self.proximity_manager = proximity_manager
        self.position = position

        # remove y position for proximity sensor which continues indefinitely along y axis
        self.pos_xz = self.position[0], self.position[2]

        # create ground wall proximity sensor / 0.6 added due to wall thickness
        self.ground = vizproximity.Sensor(
            vizproximity.RectangleArea([edge_length, edge_length],
                                       center=self.pos_xz), None)
Esempio n. 6
0
#-----------Info panel set up--------------------
import vizinfo
#Add info panel to display messages to participant
instructions = vizinfo.InfoPanel(icon=False, key=None)
#------------------------------------------------

#-----------Sensor creation----------------------
import vizproximity
target = vizproximity.Target(viz.MainView)

viewPath = []
inTime = 0

MainViewApproaches = 0
sensor1 = vizproximity.Sensor(
    vizproximity.RectangleArea([3, 1], center=[-4, 0.375]), None)
sensor2 = vizproximity.Sensor(
    vizproximity.RectangleArea([2.25, 2.25], center=[-4, 2.5]), None)
sensor3 = vizproximity.Sensor(
    vizproximity.RectangleArea([3, 1], center=[-4, 4.75]), None)
sensor4 = vizproximity.Sensor(
    vizproximity.RectangleArea([2.25, 1.5], center=[-4, 6.75]), None)
sensor5 = vizproximity.Sensor(vizproximity.CircleArea(0.75, center=[2, 7.5]),
                              None)
sensor6 = vizproximity.Sensor(
    vizproximity.RectangleArea([2.5, 2.5], center=[0, 7.5]), None)
sensor7 = vizproximity.Sensor(vizproximity.CircleArea(0.75, center=[-2, 7.5]),
                              None)
sensor8 = vizproximity.Sensor(
    vizproximity.RectangleArea([2.25, 1.5], center=[4, 6.75]), None)
sensor9 = vizproximity.Sensor(
Esempio n. 7
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)