示例#1
0
    def __init__(self, osg_file):
        # the proxy instance allows us to talk to the display server
        self.ds_proxy = JSONStimulusOSGController()
        # create the observer
        self.observer = CarModelSocketObserver(self._observer_callback)
        # load the provided OSG file
        self.ds_proxy.set_stimulus_plugin('StimulusOSG')
        self.ds_proxy.load_osg(osg_file)

        self.expTrial = -1
        self.replicate = -1
        self.tSwitch = 0
        self.tExp = 0
        self.dateStart = ''

        # set starting position for stimuli
        self.rootPosition = np.zeros((1, 2))
        self.postPosition = np.zeros((numberPost, 2))
        self.postDistance = 5.0

        # set starting position of fly
        self.start_position = {'x': 0.0, 'y': 0.0, 'z': -0.07}
        self.ds_proxy.set_position(**self.start_position)

        # assign experiment a unique id
        self.expId = uuid.uuid4()
        # get experiment conditions from database
        self.getExperiment()
        # start every experiment with a no post condition
        self.updateStimuli(0)
        emailer.twitStatus(self.expId, status=0, t=self.tExp)
        self.running = True
        # event counter (number of times fly position is reset)
        self.cntr = 0
示例#2
0
    def loop(self):

        nStimuli = 0
        t0 = time.time()
        sl_t0 = time.time()

        lastMessage = True

        # write output file in specified directory
        path = pathDefine(pathData, self.expId)
        with open(path + '/results.csv', 'w') as output:
            while self.running:
                pos = self.observer.position
                direc = self.observer.azimuth
                t = time.time() - t0
                sl_t = time.time() - sl_t0

                if sl_t < 3:
                    self.observer.velocity = 0.0
                else:
                    self.observer.velocity = 0.20

                if t > self.tExp * 60 * .9 and lastMessage:

                    try:
                        emailer.twitStatus(self.expId,
                                           status=1,
                                           t=self.tExp * .1)
                    except:
                        pass
                    lastMessage = False

                if t > self.tExp * 60:
                    self.running = False
                    self.writeInDb()
                    emailer.twitStatus(self.expId, status=2, t=self.tExp)
                elif t > (nStimuli + 1) * self.tSwitch * 60:
                    nStimuli = nStimuli + 1
                    self.observer.reset_to(**self.start_position)
                    self.updateStimuli(nStimuli)
                    sl_t0 = time.time()
                    self.cntr = 0

                for nPost in range(0, 10):
                    if distance(pos, self.postPosition[nPost, :], True) < 0.5:
                        self.observer.reset_to(**self.start_position)
                        self.cntr += 1
                        sl_t0 = time.time()
                        break
                if distance(pos, self.start_position,
                            False) > self.postDistance:
                    self.observer.reset_to(**self.start_position)
                    self.cntr += 1
                    sl_t0 = time.time()

            #print "XYZ(%3.2f, %3.2f, %3.2f)" % (pos['x'], pos['y'], pos['z']), self.counter
            #print(t)
                output.write('%.8f, %.8f, %.8f, %.4f, %d, %.8f, %s\n' %
                             (pos['x'], pos['y'], pos['z'], direc, self.cntr,
                              t, str(nStimuli)))
                time.sleep(0.005)