Example #1
0
def main():
    if GameLogic.Object['closed']:
        return

    # get controller
    controller = GameLogic.getCurrentController()

    nmouse = 1
    mkey = 'm%dconn' % (nmouse) 
    if mkey in GameLogic.Object.keys():
        t1, dt1, x1, y1 = gu.read32(GameLogic.Object[mkey])
        gu.keep_conn([GameLogic.Object[mkey]])
    else:
        t1, dt1, x1, y1 = 0, 0, np.array([0,]), np.array([0,])
    nmouse = 2
    mkey = 'm%dconn' % (nmouse) 
    if mkey in GameLogic.Object.keys():
        t2, dt2, x2, y2 = gu.read32(GameLogic.Object[mkey])
        gu.keep_conn([GameLogic.Object[mkey]])
    else:
        t2, dt2, x2, y2 = 0, 0, np.array([0,]), np.array([0,])

    
    # move according to ball readout:
    movement(controller, (x1, y1, x2, y2, t1, t2, dt1, dt2))
Example #2
0
def main():
    if GameLogic.Object['closed']:
        return
    # get controller
    controller = GameLogic.getCurrentController()
    gu.keep_conn([conn1, conn2])
    
    obj = controller.owner
    pos = obj.localPosition
    ori = obj.localOrientation
    try:
        arduino = serial.Serial('/dev/arduino_ethernet', 9600)
    
        if x1_in <= pos[0] <= x_out and y_in <= pos[1] <= y_out:
            arduino.write(b'A')
        elif -x1_in >= pos[0] >= -x_out and -y_in >= pos[1] >= -y_out:
            arduino.write(b'B')
        else:
            arduino.write(b'L')    
    except:
        print("No reward")
    
    if conn1 is not None:
        # get mouse movement
        t1, dt1, x1, y1 = gu.read32(conn1)
        t2, dt2, x2, y2 = gu.read32(conn2)
    else:
        t1, dt1, x1, y1 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])
        t2, dt2, x2, y2 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])   
    # move according to ball readout:
    movement(controller, (x1, y1, x2, y2, t1, t2, dt1, dt2))
Example #3
0
def main():
    if GameLogic.Object['closed']:
        return

    # get controller
    controller = GameLogic.getCurrentController()

    nmouse = 1
    mkey = 'm%dconn' % (nmouse)
    if mkey in GameLogic.Object.keys():
        t1, dt1, x1, y1 = gu.read32(GameLogic.Object[mkey])
        gu.keep_conn([GameLogic.Object[mkey]])
    else:
        t1, dt1, x1, y1 = 0, 0, np.array([
            0,
        ]), np.array([
            0,
        ])
    nmouse = 2
    mkey = 'm%dconn' % (nmouse)
    if mkey in GameLogic.Object.keys():
        t2, dt2, x2, y2 = gu.read32(GameLogic.Object[mkey])
        gu.keep_conn([GameLogic.Object[mkey]])
    else:
        t2, dt2, x2, y2 = 0, 0, np.array([
            0,
        ]), np.array([
            0,
        ])

    # move according to ball readout:
    movement(controller, (x1, y1, x2, y2, t1, t2, dt1, dt2))
Example #4
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    start = time.time()
    while time.time() - start < duration:
        time.sleep(float(sys.argv[2]))
        gu.keep_conn([conn1, conn2])
        if conn1 is not None:
            t1, dt1, x1, y1 = gu.read32(conn1)
            t2, dt2, x2, y2 = gu.read32(conn2)
        else:
            t1, dt1, x1, y1 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])
            t2, dt2, x2, y2 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])
        z = (float(y1.sum())-float(y2.sum()))/2/1000*2.54 # distance
        dt = float(dt1.sum())
        v = z/dt
        if v > float(sys.argv[1]):
            try:
                arduino.write(b'L')
            except:
                print("no pump")
            print('%.2f'%(time.time()-start), '%.2f'%v, 'cm/s', '%.2f'%dt, 's')
            ct = 0
            while ct < float(sys.argv[3]):
                time.sleep(1)
                ct = ct + 1
                gu.keep_conn([conn1,conn2])
                t1, dt1, x1, y1 = gu.read32(conn1)
                t2, dt2, x2, y2 = gu.read32(conn2)
            print('Ready for next reward')
    print("Finished")
Example #5
0
def main():
    if GameLogic.Object['closed']:
        return
    else:

        gu.keep_conn([conn1, conn2])
        controller = GameLogic.getCurrentController()
        obj = controller.owner
        ori = obj.localOrientation
        pos = obj.localPosition
        
        if conn1 is not None:
            t1, dt1, x1, y1 = gu.read32(conn1)
            t2, dt2, x2, y2 = gu.read32(conn2)
        else:
            t1, dt1, x1, y1 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])
            t2, dt2, x2, y2 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])
    movement(controller, (x1, y1, x2, y2, t1, t2, dt1, dt2))
Example #6
0
def main():
    if GameLogic.Object['closed']:
        return
    else:
        # check if time is up
        proceeding = GameLogic.Object['last'] - GameLogic.Object['start']
        if proceeding > GameLogic.Object['duration'] - 0.005:
            GameLogic.Object['closed'] = True
            print(proceeding)
            dropboxdao.upload_file(GameLogic.Object['trial_file'], '/trial.txt')
            dropboxdao.upload_file(GameLogic.Object['trajectory_file'], \
                '/trajectory&event/trajectory_%s.txt'%str(trial_id))
            
            line = '%s %.3f\n' % ('end', GameLogic.Object['last']-GameLogic.Object['start'])
            dropboxdao.update_file(GameLogic.Object['event_file'], line, 'a')
            dropboxdao.upload_file(GameLogic.Object['event_file'], \
                '/trajectory&event/event_%s.txt'%str(trial_id))
            GameLogic.endGame()
        
        
        gu.keep_conn([conn1, conn2])
        controller = GameLogic.getCurrentController()
        obj = controller.owner
        ori = obj.localOrientation
        pos = obj.localPosition
        
        # check timestampe & if inserting trajectory point 
        current_time = time.time()
        if (current_time - GameLogic.Object['last']) > GameLogic.Object['timestamp'] - 0.005:
            GameLogic.Object['last'] = current_time
            line = '%.3f %.3f %.3f %.3f\n' % (pos[0],pos[1],ori[0][0],ori[1][0])
            dropboxdao.update_file(GameLogic.Object['trajectory_file'], line, 'a')
                
        # check if pumping reward
        if arduino:
            last_pos = GameLogic.Object['last_position']
            area = (pos[0] < 0 and -0.1 <= pos[1] <= 0.1)
            last_area = (last_pos[0] < 0 and -0.1 <= last_pos[1] <= 0.1)

            if not area and not last_area and GameLogic.Object['reward_done']:
                GameLogic.Object['reward_done'] = False

            elif area and not last_area:
                print('enter reward area')
                GameLogic.Object['entry_time'] = time.time()
                line = '%s %.3f\n' % ('enter', GameLogic.Object['entry_time'] - GameLogic.Object['start'])
                dropboxdao.update_file(GameLogic.Object['event_file'], line, 'a')
                
            elif not area and last_area:
                print('exit reward area')
                line = '%s %.3f\n' % ('exit', time.time()-GameLogic.Object['start'])
                dropboxdao.update_file(GameLogic.Object['event_file'], line, 'a')
            
            elif area and last_area and not GameLogic.Object['reward_done']:
                GameLogic.Object['stay_time'] = time.time()
                duration = GameLogic.Object['stay_time'] - GameLogic.Object['entry_time']
                if  duration > 2.995:
                    print('reward: %.3f'%duration)
                    arduino.write(b'L')
                    GameLogic.Object['reward_done'] = True
                    line = '%s %.3f\n' % ('reward', GameLogic.Object['stay_time']-GameLogic.Object['start'])
                                              
            
        GameLogic.Object['last_position'] = [pos[0],pos[1]]

        if conn1 is not None:
            t1, dt1, x1, y1 = gu.read32(conn1)
            t2, dt2, x2, y2 = gu.read32(conn2)
        else:
            t1, dt1, x1, y1 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])
            t2, dt2, x2, y2 = np.array([0,]), np.array([0,]), np.array([0,]), np.array([0,])
        
        movement(controller, (y1, y2, t1, t2, dt1, dt2))