示例#1
0
 def init(self):
     PygameFeedback.init(self)
     # color, pos, width and height of the paddle
     self.color = [255, 0, 128]
     self.pos = 100
     self.width = 20
     self.height = 100
示例#2
0
 def init(self):
     PygameFeedback.init(self)
     # color, pos, width and height of the paddle
     self.color = [255, 0, 128]
     self.pos = 100
     self.width = 20
     self.height = 100
示例#3
0
 def init(self):
     """
     Initializes variables etc., but not pygame itself.
     """
     PygameFeedback.init(self)
     self.caption = 'Brain Pong'
     self.send_parallel(self.START_EXP)
     #self.logger.debug("on_init")
     
     self.durationPerTrial = 0 # if 0, duration last until a miss
     self.trials = 20
     self.pauseAfter = 10
     self.pauseDuration = 3000
     self.availableDirections = ['left', 'right']
     self.FPS = 60
     self.fullscreen = False
     self.screenSize[0] = 1200
     self.screenSize[1] = 700
     self.countdownFrom = 3
     self.hitMissDuration = 1500
     self.timeUntilNextTrial = 500
     self.control = "relative"
     self.g_rel = 0.2
     self.g_abs = 0.7
     self.jitter = 0.0          # jitter to force ball out of the predefined "left-right"-path
     self.bowlSpeed = 2.7       # time from ceiling to bar
     self.barWidth = 30         # in percent of the width of the playing field
     self.bowlDiameter = 20     # in percent of the width of the bar
     self.showCounter = True
     self.showGameOverDuration = 5000
     
     # Feedback state booleans
     self.quit, self.quitting = False, False
     self.pause, self.shortPause = False, False
     self.gameover, self.hit, self.miss = False, False, False
     self.countdown, self.firstTickOfTrial = True, True
     self.showsPause, self.showsShortPause = False, False
    
     self.elapsed, self.trialElapsed, self.countdownElapsed = 0,0,0
     self.hitMissElapsed, self.shortPauseElapsed, self.completedTrials = 0,0,0
     self.showsHitMiss = False
     
     self.resized = False
     self.f = 0.0
     self.hitMiss = [0,0]
     
     # Colours
     self.fontColor = (100, 100, 200)        #(0,150,150)
     self.countdownColor = self.fontColor    #(237, 100, 148)
     
     # Bowl direction
     self.left = True
     self.down = True
     
     # HitMissCounter
     self.counterSize = self.screenSize[1]/15
     self.hitmissCounterColor = (100, 100, 200) #(120, 120, 255)
     self.missstr = " Miss: "
     self.hitstr = "Hit: "
     self.x_transl = 0.8
    def init(self):

        PygameFeedback.init(self)

        ########################################################################

        self.FPS = 200
        #self.screenPos = [1280, 0]
        #self.screenSize = [1280, 1024]
        self.screenPos = [0, 0]
        self.screenSize = [1280, 1024]
        self.screen_center = [self.screenSize[0] / 2, self.screenSize[1] / 2]
        self.caption = "IntentionBeep"

        self.spot_size = (self.screenSize[1] / 6, self.screenSize[1] / 6)
        self.spot_states = ('', 'yellow')

        self.background_color = [127, 127, 127]
        self.text_fontsize = 75
        self.text_color = [64, 64, 64]
        self.char_fontsize = 100
        self.char_color = [0, 0, 0]

        self.prompt_text = 'Were you about to press?'
        self.pause_text = 'Paused. Press pedal to continue...'
        self.paused = True
        self.on_trial = False

        ########################################################################

        self.duration_spot_yellow = 500
        self.duration_cross = 2500
        self.min_waittime = 1500

        self.marker_keyboard_press = 255 - 199
        self.marker_quit = 255 - 255
        self.marker_base_start = 255 - 10
        self.marker_base_interruption = 255 - 20
        self.marker_trial_end = 255 - 30

        self.marker_identifier = {
            self.marker_base_interruption: 'beep move silent',
            self.marker_base_interruption + 1: 'beep move',
            self.marker_base_interruption + 2: 'beep idle'
        }

        ########################################################################
        # MAIN PARAMETERS TO BE SET IN MATLAB

        self.listen_to_keyboard = 1
        self.make_interruptions = 1
        self.pause_every_x_events = 6
        self.end_after_x_events = 6
        self.end_pause_counter_type = 1  # 1 - button presses, 2 - move lights, 3 - idle lights, 4 - seconds
        self.bci_delayed_idle = 0
        self.trial_assignment = [2, 2, 2, 2, 2, 2, 2]  # 1 - move, 2 - idle
        self.ir_idle_waittime = [
            3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0
        ]
示例#5
0
    def init(self):

        PygameFeedback.init(self)
        
        ########################################################################
        
        self.FPS = 200
        self.screenPos = [1280, 0]
        self.screenSize = [1280, 1024]
        self.screen_center = [self.screenSize[0]/2,self.screenSize[1]/2]
        self.caption = "TrafficLight"
        
        self.trafficlight_size = (self.screenSize[1]/6, self.screenSize[1]/2)
        self.trafficlight_states = ('','green','red','yellow')
        
        self.background_color = [127, 127, 127]
        self.text_fontsize = 75
        self.text_color = [64,64,64]
        self.char_fontsize = 100
        self.char_color = [0,0,0]
        
        self.pause_text = 'Paused. Press pedal to continue...'
        self.paused = True
        self.on_trial = False
        
        ########################################################################
        
        self.delay_before_trialend = 1500
        self.duration_light_on = 500
        self.duration_cross = 2500
        self.min_waittime = 1500
        self.max_waittime = 10000
        
        self.marker_keyboard_press = 199
        self.marker_quit = 255
        self.marker_trial_start = 10
        self.marker_base_interruption = 20
        self.marker_trial_end = 30
                
        self.marker_identifier = {self.marker_base_interruption+1 : 'random red light',
                                  self.marker_base_interruption+2 : 'random green light',
                                  self.marker_base_interruption+3 : 'random yellow light',
                                  self.marker_base_interruption+4 : 'move red light',
                                  self.marker_base_interruption+5 : 'move green light',
                                  self.marker_base_interruption+6 : 'move yellow light',
                                  self.marker_base_interruption+7 : 'idle red light',
                                  self.marker_base_interruption+8 : 'idle green light',
                                  self.marker_base_interruption+9 : 'idle yellow light'}
        
        ########################################################################
        # MAIN PARAMETERS TO BE SET IN MATLAB
        
        self.mode = 1 # 1 - self-paced, 2 - traffic light (no BCI), 3 - traffic light (BCI)
        self.trial_assignment = [4,5,6,4,5,6] # 1 - random red, 2 - random green, 3 - random yellow, 4 - move red, 5 - move green, 6 - move yellow, 7 - idle red, 8 - idle green, 9 - idle yellow
        self.cue_waittime = [3000.0,3000.0,3000.0,3000.0,3000.0,3000.0]
        self.pause_every_x_events = 3
        self.end_after_x_events = 6
        self.end_pause_counter_type = 1 # 1 - pedal presses, 2 - move lights, 3 - idle lights, 4 - seconds, 5 - trials, 6 - random lights, 7 - BCI lights
        self.listen_to_keyboard = 1
示例#6
0
 def init(self):
     PygameFeedback.init(self)
     self.caption = "Trivial Pong"
     # set the initial speeds for ball and bar
     self.barspeed = [3, 0]
     self.speed = [2, 2]
     # set initial value for cl output
     self.val = 0.0
 def init(self):
     PygameFeedback.init(self)
     self.caption = "Trivial Pong"
     # set the initial speeds for ball and bar
     self.barspeed = [3, 0]
     self.speed = [2, 2]
     # set initial value for cl output
     self.val = 0.0
 def pre_mainloop(self):
     PygameFeedback.pre_mainloop(self)
     self.font_text = pygame.font.Font(None, self.text_fontsize)
     self.font_char = pygame.font.Font(None, self.char_fontsize)
     self.reset_trial_states()
     self.on_pause()
     self.set_dist_training_data()
     self.render_text(self.pause_text)
示例#9
0
    def init(self):
        PygameFeedback.init(self)

        ########################################################################
        self.FPS = 200
        self.screenPos = [0, 0]
        self.screenSize = [1000, 1000]
        self.screen_center = [self.screenSize[0] / 2, self.screenSize[1] / 2]
        self.caption = "ReadinessFeedback"

        self.background_color = [127, 127, 127]
        self.text_fontsize = 75
        self.text_color = [64, 64, 64]
        self.char_fontsize = 100
        self.char_color = [0, 0, 0]

        self.pause_text = 'Pause. Press pedal to continue...'
        self.paused = True
        self.on_trial = False

        ########################################################################

        self.marker_keyboard_press = 199
        self.marker_quit = 255
        self.marker_base_start = 10
        self.marker_base_interruption = 20
        self.marker_trial_end = 30
        self.marker_prompt = 40

        ########################################################################
        # Parameters to the bars visuals
        self.clf_input = 0
        self.clf_input_prev = 0
        self.dist = 0
        self.stat_bar_loc = 0
        self.bars_num = 15
        self.bars_values = np.zeros((self.bars_num))
        self.bars_colors = np.zeros((self.bars_num, 3))
        ########################################################################
        # MAIN PARAMETERS TO BE SET IN MATLAB

        self.listen_to_keyboard = 1
        self.pause_every_x_events = 2
        self.end_after_x_events = 6

        ########################################################################
        # logic parameters
        # self.max_history = 10
        self.emg_history = []
        self.eeg_history = []

        ########################################################################
        # TESTING PURPOSES ONLY.
        self.add_ones = False
示例#10
0
 def pre_mainloop(self):
     PygameFeedback.pre_mainloop(self)
     self.font_text = pygame.font.Font(None, self.text_fontsize)
     self.font_char = pygame.font.Font(None, self.char_fontsize)
     self.trial_counter = 0
     self.block_counter = 0
     self.move_counter = 0
     self.idle_counter = 0
     self.pedalpress_counter = 0
     self.reset_trial_states()
     self.on_pause()
示例#11
0
 def init(self):
     PygameFeedback.init(self)
     # your init code goes here
     # set the initial position of the polygon
     self.positions = []
     for i in range(6):
         self.positions.append([random.randint(0, self.screenSize[0]), random.randint(0, self.screenSize[1])])
     # set the initial speed vectors
     self.speed = []
     for i in range(6):
         self.speed.append([random.random(), random.random()])
     # set the initial color
     self.color = [0, 255, 128]
示例#12
0
 def pre_mainloop(self):
     PygameFeedback.pre_mainloop(self)
     self.generate_d2list()
     self.generate_symbols()
     # Initialize the logic
     self.current_index = 0
     # The errors: e1: errors of omission (missing characters that should have been crossed out, 
     #             e2: errors of commission (crossing out characters that shout have not been crossed out
     self.e1 = 0
     self.e2 = 0
     # And here we go...
     pygame.time.set_timer(pygame.QUIT, self.number_of_symbols * self.seconds_per_symbol * 1000)
     self.clock.tick()
     self.present_stimulus()
示例#13
0
 def init(self):
     PygameFeedback.init(self)
     self.caption = "Test D2"
     self.random_seed = 1234
     # Standard D2 configuration
     self.number_of_symbols = 47 * 14
     self.seconds_per_symbol = 20 / 47.
     self.targets_percent = 45.45
     # Color of the symbols
     self.color = [0, 0, 0]
     self.backgroundColor = [127, 127, 127]
     # Fontheight in pixels
     self.fontheight = 200
     self.key_target = "f"
     self.key_nontarget = "j"
示例#14
0
 def init(self):
     PygameFeedback.init(self)
     # your init code goes here
     # set the initial position of the polygon
     self.positions = []
     for i in range(6):
         self.positions.append([
             random.randint(0, self.screenSize[0]),
             random.randint(0, self.screenSize[1])
         ])
     # set the initial speed vectors
     self.speed = []
     for i in range(6):
         self.speed.append([random.random(), random.random()])
     # set the initial color
     self.color = [0, 255, 128]
示例#15
0
    def init(self):
        PygameFeedback.init(self)
        self.transparent = (0, 0, 0)
        self.rhomb_bg_color = (255, 255, 255)
        self.rhomb_fg_color = (255, 0, 0)

        self.w, self.h = 800, 600
        self.FPS = 30

        self.angle = 173
        self.duration = 1000.0 # 3s from left to right

        self.random_angle = 5 # degrees

        # TODO: move this to init_graphics
        self.v = (self.w * 1000) / (self.duration * self.FPS)
 def pre_mainloop(self):
     PygameFeedback.pre_mainloop(self)
     self.font_text = pygame.font.Font(None, self.text_fontsize)
     self.font_char = pygame.font.Font(None, self.char_fontsize)
     self.trial_counter = 0
     self.block_counter = 0
     self.move_counter = 0
     self.idle_counter = 0
     self.pedalpress_counter = 0
     self.time_recording_start = pygame.time.get_ticks()
     if self.make_interruptions:
         self.queue_waittime = deque(self.ir_idle_waittime)
         self.queue_trial = deque(self.trial_assignment)
     self.reset_trial_states()
     self.load_images()
     self.on_pause()
示例#17
0
 def post_mainloop(self):
     elapsed_seconds = self.clock.tick() / 1000.
     PygameFeedback.post_mainloop(self)
     # Total number of items processed
     tn = self.current_index + 1
     error = self.e1 + self.e2
     error_rate = 100. * error / tn
     correctly_processed = tn - error
     # concentration performance := correctly_processed - e2 
     cp = correctly_processed - self.e2
     # Average reaction time:
     rt_avg = elapsed_seconds / tn
     print "Results:"
     print "========"
     print
     print "Processed symbols: %i of %i" % (tn, self.number_of_symbols)
     print "Elapsed time: %f sec" % elapsed_seconds
     print "Correctly processed symbols: %i" % (correctly_processed)
     print "Percentage of Errors: %f" % (error_rate)
     print "Errors:  %i" % error
     print "... errors of omission: %i" % self.e1
     print "... errors of commission: %i" % self.e2
     print "Concentration Performance: %i" % cp
     print "Average reaction time: %f sec" % rt_avg
 def post_mainloop(self):
     self.logger.debug("on_quit")
     PygameFeedback.post_mainloop(self)
     self.send_parallel(self.GAME_OVER)
 def pre_mainloop(self):
     PygameFeedback.pre_mainloop(self)
     self.logger.debug("on_play")
     self.send_parallel(self.GAME_STATUS_PLAY)
示例#20
0
 def post_mainloop(self):
     #self.logger.debug("Quitting pygame.")
     self.send_parallel(self.END_EXP)
     PygameFeedback.post_mainloop(self)
示例#21
0
    def init(self):
        """
        Initializes the variables and stuff, but not pygame itself.
        """
        PygameFeedback.init(self)

        if __name__ == '__main__':
            self.screenPos = [200, 200, 600, 400]
        else:
            self.screenPos = [0, 0, 1280, 800] #[0, 0, 1920, 1200]

        self.TODAY_DIR = 'l:/data/bbciRaw/'
        self.writeClassifierLog = 1
        self.classifier_log = []
        self.cls_evolution_log = []

        self.revolutionTime = 4000  # time the clock hand needs for one revolution (in ms)
        self.quarterTime = self.revolutionTime/4
        self.nRev = 2               # number of clockhand revolutions per trial
        self.intertrialInterval = [2500, 3500]     # (in ms)
        self.showClassifier = 'random'   # 'none', 'random', 'feedback'
        self.cls_move_prob = 0.25  # probability that classifier is true at a target
                                  # (only applies  if self.showClassifier=='random')
        self.trials = 50
        self.pauseAfter = 10
        self.pauseDuration = 9000      # (in ms)
        self.kp_perfect_tol = 15       # (in ms)
        self.FPS = 50
        self.fullscreen =  False
        self.screenWidth =  self.screenPos[2]#900
        self.screenHeight =  self.screenPos[3]#600
        self.countdownFrom = 3
        self.threshold = 0
        self.redClockDuration = self.revolutionTime/8
        self.SADuration = 1000
        self.cls_ival = (-400, -200)
        self.keypress_tolerance = 50     # time deviation tolerate (in ms) of the keypress from
                                         # when the clockhand actually is at the target

        self.pause = False
        self.quit = True
        self.quitting = True

        self.gameover = False
        self.countdown = True
        self.hit = False
        self.miss = False
        self.shortPause = False
        self.end_of_trial = False
        self.start_animation = False
        self.firstTickOfTrial = True

        self.showsPause, self.showsShortPause = False, False
        self.showsHitMiss, self.showsGameover = False, False

        self.elapsed, self.trialElapsed, self.countdownElapsed, self.redClockElapsed = 0,0,0,0
        self.shortPauseElapsed, self.trialSAElapsed, self.endOfTrialElapsed = 0,0,0

        self.f = 0
        self.hitMiss = [0,0]
        self.it = 0

        self.backgroundColor = (64,64,100)
        self.clockColor = (50,50,200)
        self.redClockColor = (200,0,0)
        self.fontColor = (237, 100, 148)
        self.fb_color_good = (0, 180, 0)
        self.fb_color_bad = (200, 0, 0)
        self.countdownColor = (237, 100, 148)

        self.completedTrials = 0
        self.validTrials = 0
        self.infostr = ''
        self.infocolor = self.fb_color_good
示例#22
0
    def init(self):
        """
        Initializes the variables and stuff, but not pygame itself.
        """
        PygameFeedback.init(self)

        if __name__ == '__main__':
            self.screenPos = [200, 200, 600, 400]
        else:
            self.screenPos = [0, 0, 1280, 800]  #[0, 0, 1920, 1200]

        self.TODAY_DIR = 'l:/data/bbciRaw/'
        self.writeClassifierLog = 1
        self.classifier_log = []
        self.cls_evolution_log = []

        self.revolutionTime = 4000  # time the clock hand needs for one revolution (in ms)
        self.quarterTime = self.revolutionTime / 4
        self.nRev = 2  # number of clockhand revolutions per trial
        self.intertrialInterval = [2500, 3500]  # (in ms)
        self.showClassifier = 'random'  # 'none', 'random', 'feedback'
        self.cls_move_prob = 0.25  # probability that classifier is true at a target
        # (only applies  if self.showClassifier=='random')
        self.trials = 50
        self.pauseAfter = 10
        self.pauseDuration = 9000  # (in ms)
        self.kp_perfect_tol = 15  # (in ms)
        self.FPS = 50
        self.fullscreen = False
        self.screenWidth = self.screenPos[2]  #900
        self.screenHeight = self.screenPos[3]  #600
        self.countdownFrom = 3
        self.threshold = 0
        self.redClockDuration = self.revolutionTime / 8
        self.SADuration = 1000
        self.cls_ival = (-400, -200)
        self.keypress_tolerance = 50  # time deviation tolerate (in ms) of the keypress from
        # when the clockhand actually is at the target

        self.pause = False
        self.quit = True
        self.quitting = True

        self.gameover = False
        self.countdown = True
        self.hit = False
        self.miss = False
        self.shortPause = False
        self.end_of_trial = False
        self.start_animation = False
        self.firstTickOfTrial = True

        self.showsPause, self.showsShortPause = False, False
        self.showsHitMiss, self.showsGameover = False, False

        self.elapsed, self.trialElapsed, self.countdownElapsed, self.redClockElapsed = 0, 0, 0, 0
        self.shortPauseElapsed, self.trialSAElapsed, self.endOfTrialElapsed = 0, 0, 0

        self.f = 0
        self.hitMiss = [0, 0]
        self.it = 0

        self.backgroundColor = (64, 64, 100)
        self.clockColor = (50, 50, 200)
        self.redClockColor = (200, 0, 0)
        self.fontColor = (237, 100, 148)
        self.fb_color_good = (0, 180, 0)
        self.fb_color_bad = (200, 0, 0)
        self.countdownColor = (237, 100, 148)

        self.completedTrials = 0
        self.validTrials = 0
        self.infostr = ''
        self.infocolor = self.fb_color_good
示例#23
0
文件: GoalKeeper.py 项目: svsobh/pyff
    def init(self):
        """
        Initializes variables etc., but not pygame itself.
        """
        #self.logger.debug("on_init")
        ### TESTING
        PygameFeedback.init(self)
        self.caption = 'Goal Keeper'
        self.keyboard = 1
        if __name__ == '__main__':
            self.testing = 1
            print('WARNING: Testing Option ON!')
            self.TODAY_DIR = 'C:/'
            self.keyboard = 0
            self.counter = 0  # for sinewavy mu-rhythm feedback
        else:
            self.testing = 0
        ### end ###

        self.durationPerTrial = [2000, 2000]    # time of the trial at the beginning and the end
                                                # (linear interpolation in between); unused if
                                                # self.adaptive_trial_time = True

        ### adaptation specific settings (used only if self.adaptive_trial_time = True) ###
        self.adaptive_trial_time = True
        if self.adaptive_trial_time and not self.keyboard:
            self.read_log()
        self.log_written = 0
        self.max_durationPerTrial = 2500
        self.endtimes = []          # trial endtimes for log-file
        self.stepsize = 5           # stepsize of the adaptive procedure
                                    # (in percent of the initial trial time (=self.durationPerTrial[0])
        ### end ###

        ### mu-rhythm settings (used only if mu_fb = 1) ###
        self.mu_fb = 1
        self.mu_left, self.mu_right = 1,1
        self.mu_bound_left = [0,1]
        self.mu_bound_right = [0,1]
        self.colorbar = list()
        for n in range(101):
            self.colorbar.append((int(round(255*(n/100.0))), int(round(255*(1-n/100.0))),0))
        ### end ###

        self.trials = 2
        self.pauseAfter = 20
        self.pauseDuration = 15000
        self.FPS = 40
        self.fullscreen = False
        self.screenPos = [100, 100]
        self.screenSize = [640, 480]
        self.countdownFrom = 2  # should be 7
        self.hitMissDuration = 1000
        self.timeUntilNextTrial = [500, 1000]  # randomly between the two values
        self.showGameOverDuration = 3000
        self.timeOfStartAnimation = 2000
        self.showTrialStartAnimation = True
        self.showCounter = True
        self.control = "relative"  # or "absolute"
        self.iBorder = 1.0 # maximal (&-min) value of the classifier output integration
        self.iTimeUntilThreshold = 500  # minimal integration time needed to reach threshold [in ms]
        self.timeUntilIntegration = 500  # time to wait at trial start before integrating [in ms]
        self.g_abs = 1
        self.showRedBallDuration = 500       # in ms
        self.continueAfterMiss = True
        self.playTimeAfterMiss = 1500        # in ms
        self.distanceBetweenHalfBalls = 25             # in percent of the screen width


        # Feedback state booleans
        self.shortPause = False
        self.gameover, self.hit, self.miss, self.false = False, False, False, False
        self.countdown, self.firstTickOfTrial = True, True
        self.showsShortPause = False
        self.trialStartAnimation, self.waitBeforeTrial = False, False

        self.elapsed, self.trialElapsed, self.countdownElapsed = 0, 0, 0
        self.hitMissElapsed, self.shortPauseElapsed, self.completedTrials = 0, 0, 0
        self.animationElapsed, self.continueAfterMissElapsed, self.waitBeforeTrialElapsed = 0, 0, 0
        self.showsHitMiss = False

        self.f = 0.0
        self.hitMissFalse = [0, 0, 0]
        self.resized = False
        self.barX = 0
        self.memoResize = False
        self.c = 0
        self.directionToDigit = {'left': - 1, 'middle':0, 'right':1}
        self.digitToDirection = { - 1:'left', 0:'middle', 1:'right'}
        self.X = 0
        self.Y = 1
        self.eps = 0.5


        # Colour settings
        self.backgroundColor = (50, 50, 50)
        self.fontColor = (0, 150, 150)
        self.countdownColor = (200, 80, 118)
        self.fixcrossColor = (130,130,130)

        # Keeper specifications
        self.contKeeperMotion = 750   # if 0:  jump between the three positions
                                      # if >0: move in a continuous fashion
                                      #        (self.contKeeperMotion=duration of the movement in seconds)
        self.noReturn = True          # if self.threshold of the classifier bar is passed, the keeper
                                      # will move to this direction without reacting to further changes
        self.tol = 5           # tolerance in pixels between the keeper and the midbottom x-coordinate
                               # of the ball for which the trial still counts as a 'hit'

        # Classifier threshold for keeper position change
        self.threshold = 1

        # HitMissCounter
        self.hitmissCounterColor = self.fontColor #(100, 100, 100)
        self.hitstr = ""    # "Hit: "
        self.missstr = ":"  #" Miss: "
        self.falsestr = ":" # " False: "
        self.x_transl = 0.95
示例#24
0
文件: GoalKeeper.py 项目: bsdlab/pyff
 def pre_mainloop(self):
     # self.logger.debug("on_play")
     PygameFeedback.pre_mainloop(self)
     # self.load_images()  # this is done in init_graphics
     self.init_run()
     self.gameover = False
示例#25
0
 def post_mainloop(self):
     self.logger.debug("on_quit")
     PygameFeedback.post_mainloop(self)
     self.send_parallel(self.GAME_OVER)
 def post_mainloop(self):
     PygameFeedback.post_mainloop(self)
示例#27
0
文件: GoalKeeper.py 项目: bsdlab/pyff
    def init(self):
        """
        Initializes variables etc., but not pygame itself.
        """
        # self.logger.debug("on_init")
        ### TESTING
        PygameFeedback.init(self)
        self.caption = "Goal Keeper"
        self.keyboard = 1
        if __name__ == "__main__":
            self.testing = 1
            print ("WARNING: Testing Option ON!")
            self.TODAY_DIR = "C:/"
            self.keyboard = 0
            self.counter = 0  # for sinewavy mu-rhythm feedback
        else:
            self.testing = 0
        ### end ###

        self.durationPerTrial = [2000, 2000]  # time of the trial at the beginning and the end
        # (linear interpolation in between); unused if
        # self.adaptive_trial_time = True

        ### adaptation specific settings (used only if self.adaptive_trial_time = True) ###
        self.adaptive_trial_time = True
        if self.adaptive_trial_time and not self.keyboard:
            self.read_log()
        self.log_written = 0
        self.max_durationPerTrial = 2500
        self.endtimes = []  # trial endtimes for log-file
        self.stepsize = 5  # stepsize of the adaptive procedure
        # (in percent of the initial trial time (=self.durationPerTrial[0])
        ### end ###

        ### mu-rhythm settings (used only if mu_fb = 1) ###
        self.mu_fb = 1
        self.mu_left, self.mu_right = 1, 1
        self.mu_bound_left = [0, 1]
        self.mu_bound_right = [0, 1]
        self.colorbar = list()
        for n in range(101):
            self.colorbar.append((int(round(255 * (n / 100.0))), int(round(255 * (1 - n / 100.0))), 0))
        ### end ###

        self.trials = 2
        self.pauseAfter = 20
        self.pauseDuration = 15000
        self.FPS = 40
        self.fullscreen = False
        self.screenPos = [100, 100]
        self.screenSize = [640, 480]
        self.countdownFrom = 2  # should be 7
        self.hitMissDuration = 1000
        self.timeUntilNextTrial = [500, 1000]  # randomly between the two values
        self.showGameOverDuration = 3000
        self.timeOfStartAnimation = 2000
        self.showTrialStartAnimation = True
        self.showCounter = True
        self.control = "relative"  # or "absolute"
        self.iBorder = 1.0  # maximal (&-min) value of the classifier output integration
        self.iTimeUntilThreshold = 500  # minimal integration time needed to reach threshold [in ms]
        self.timeUntilIntegration = 500  # time to wait at trial start before integrating [in ms]
        self.g_abs = 1
        self.showRedBallDuration = 500  # in ms
        self.continueAfterMiss = True
        self.playTimeAfterMiss = 1500  # in ms
        self.distanceBetweenHalfBalls = 25  # in percent of the screen width

        # Feedback state booleans
        self.shortPause = False
        self.gameover, self.hit, self.miss, self.false = False, False, False, False
        self.countdown, self.firstTickOfTrial = True, True
        self.showsShortPause = False
        self.trialStartAnimation, self.waitBeforeTrial = False, False

        self.elapsed, self.trialElapsed, self.countdownElapsed = 0, 0, 0
        self.hitMissElapsed, self.shortPauseElapsed, self.completedTrials = 0, 0, 0
        self.animationElapsed, self.continueAfterMissElapsed, self.waitBeforeTrialElapsed = 0, 0, 0
        self.showsHitMiss = False

        self.f = 0.0
        self.hitMissFalse = [0, 0, 0]
        self.resized = False
        self.barX = 0
        self.memoResize = False
        self.c = 0
        self.directionToDigit = {"left": -1, "middle": 0, "right": 1}
        self.digitToDirection = {-1: "left", 0: "middle", 1: "right"}
        self.X = 0
        self.Y = 1
        self.eps = 0.5

        # Colour settings
        self.backgroundColor = (50, 50, 50)
        self.fontColor = (0, 150, 150)
        self.countdownColor = (200, 80, 118)
        self.fixcrossColor = (130, 130, 130)

        # Keeper specifications
        self.contKeeperMotion = 750  # if 0:  jump between the three positions
        # if >0: move in a continuous fashion
        #        (self.contKeeperMotion=duration of the movement in seconds)
        self.noReturn = True  # if self.threshold of the classifier bar is passed, the keeper
        # will move to this direction without reacting to further changes
        self.tol = 5  # tolerance in pixels between the keeper and the midbottom x-coordinate
        # of the ball for which the trial still counts as a 'hit'

        # Classifier threshold for keeper position change
        self.threshold = 1

        # HitMissCounter
        self.hitmissCounterColor = self.fontColor  # (100, 100, 100)
        self.hitstr = ""  # "Hit: "
        self.missstr = ":"  # " Miss: "
        self.falsestr = ":"  # " False: "
        self.x_transl = 0.95
    def init(self):
        """
        Initializes the variables and stuff, but not pygame itself.
        """
        PygameFeedback.init(self)
        self.logger.debug("on_init")
        self.caption = 'Cursor Arrow Feedback'
        self.send_parallel(self.INIT_FEEDBACK)

        self.durationUntilBorder = 1000
        self.durationPerTrial = 4000
        self.durationIndicateGoal = 1000
        self.trials = 20
        self.pauseAfter = 4
        self.pauseDuration = 9000
        self.availableDirections = ['right', 'foot']
        self.FPS = 50
        self.fullscreen = False
        self.screenWidth = 1000
        self.screenHeight = 700
        self.countdownFrom = 2
        self.hitMissDuration = 1000
        self.dampedMovement = False
        self.showPunchline = True
        #self.damping = 'linear'
        self.damping = 'distance'

        self.pause = False
        self.quit = True
        self.quitting = True

        self.gameover = False
        self.countdown = True
        self.hit = False
        self.miss = False
        self.shortPause = False
        self.indicateGoal = False

        self.firstTickOfTrial = True

        self.showsPause, self.showsShortPause = False, False
        self.showsHitMiss, self.showsGameover = False, False

        self.elapsed, self.trialElapsed, self.countdownElapsed = 0, 0, 0
        self.hitMissElapsed, self.shortPauseElapsed, self.indicateGoalElapsed = 0, 0, 0

        self.completedTrials = 0

        self.f = 0
        self.hitMiss = [0, 0]
        self.resized = False
        self.pos = 0
        self.targetDirection = 0

        self.arrowPointlist = [(.5, 0), (.5, .33), (1, .33), (1, .66),
                               (.5, .66), (.5, 1), (0, .5)]
        self.arrowColor = (127, 127, 127)
        self.borderColor = self.arrowColor
        self.backgroundColor = (64, 64, 64)
        self.cursorColor = (100, 149, 237)
        self.fontColor = self.cursorColor
        self.countdownColor = (237, 100, 148)
        self.punchLineColor = self.cursorColor
        self.punchLineColorImpr = (100, 200, 100)  # if punchline is improved

        self.punchlineThickness = 5  # in pixels
        self.borderWidthRatio = 0.4  # in pixels
        self.punchlinePos1, self.punchlinePos2 = 0, 0

        #=============
        # NOTE: only one of the following variables should be True
        self.hitIfLateral = True
        self.reject = False
        #=============

        # How many degrees counter clockwise to turn an arrow pointing to the
        # left to point at left, right and foot
        self.LEFT, self.RIGHT, self.DOWN, self.UP = 'left', 'right', 'foot', 'up'
        self.directions = {
            self.LEFT: 0,
            self.RIGHT: 180,
            self.DOWN: 90,
            self.UP: 270
        }
    def init(self):
        PygameFeedback.init(self)

        ########################################################################

        self.screenPos = [1280, 0]
        # self.screenPos = [1920, 0]
        self.screenSize = [1280, 1024]
        #self.screenPos = [0, 0]
        #self.screenSize = [1000, 1000]
        self.screen_center = [self.screenSize[0] / 2, self.screenSize[1] / 2]
        self.caption = "ReadinessFeedback"

        self.background_color = [127, 127, 127]
        self.text_fontsize = 75
        self.text_color = [64, 64, 64]
        self.char_fontsize = 100
        self.char_color = [0, 0, 0]
        self.white_color = [255, 255, 255]
        self.red_color = [225, 0, 0]
        self.radius = 25
        self.cross_length = 25

        self.pause_text = 'Paused. Press pedal to start...'
        self.end_text = 'Finished. Session has ended...'
        self.paused = True
        self.on_trial = False
        self.searching_rp = False

        self.block_counter = 1
        self.trial_counter = 0

        ########################################################################

        self.marker_identifier = {
            10: "Trial starts: " + str(self.trial_counter),
            11: "Trial ends",
            20: "block starts: " + str(self.block_counter),
            21: "block ends",
            30: "feedback",
            255: "quit condition reached"
        }

        self.marker_trial_start = 10
        self.marker_trial_end = 11
        self.marker_block_start = 20
        self.marker_block_end = 21
        self.marker_rp_shown = 30
        self.marker_quit_condition = 255

        ########################################################################
        # MAIN PARAMETERS TO BE SET IN MATLAB

        self.listen_to_keyboard = 0
        self.show_feedback = False
        self.end_after_x_bps = 10
        self.pause_every_x_bps = 5
        self.data_dir = '/tmp'
        self.block_name = 'session_tmp'
        self.phase1_cout = []

        ########################################################################

        # logic parameters
        self.emg_history = []
        self.eeg_history = []
        self.last_cross_shown = pygame.time.get_ticks()
        self.last_circle_shown = pygame.time.get_ticks()
        self.last_pedal_pressed = pygame.time.get_ticks()
        self.one_std_val = 15
        self.mean_value = 50
示例#30
0
文件: GoalKeeper.py 项目: bsdlab/pyff
 def post_mainloop(self):
     PygameFeedback.post_mainloop()
     self.send_parallel(self.END_EXP)
 def pre_mainloop(self):
     PygameFeedback.pre_mainloop(self)
     self.logger.debug("on_play")
 def post_mainloop(self):
     self.logger.debug("on_quit")
     PygameFeedback.post_mainloop(self)
     self.send_udp(str(self.CALIBRATION_STATUS_QUIT))
示例#33
0
 def pre_mainloop(self):
     PygameFeedback.pre_mainloop(self)
     self.stopping, self.stop = False, False
     # for now...
     self.rhomb = self.rhomb_left
    def init(self):
        #print "Feedback successfully loaded."
        self.logger.debug('Feedback successfully loaded')

        # self._ov_tcp_tag_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        # self._ov_tcp_tag_socket.connect((self.ov_tcp_tag_host, self.ov_tcp_tag_port))

        # PyGame init style
        PygameFeedback.init(self)

        self.screenPos = [1400,20]
        self.screenSize = [1000,800]
        # screen = gtk.window()
        # if screen.get_n_monitors == 2 :
        #     second_monitor_info = screen.get_monitor_geometry(1)
        #     self.screenPos = [second_monitor_info.x,second_monitor_info.y]
        #     self.screenSize = [second_monitor_info.width,second_monitor_info.height]
        #socket init for send udp
        #self._udp_markers_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)


        self.logger.debug("on_init")
        self.caption = 'Motor Imagery Calibration'
        # self.send_udp(str(self.INIT_CALIBRATION))

        # events Durations
        self.durationPerTrial = 8000 #8 seconds
        self.trials = 75 #Number of trials per run / class
        self.pauseAfter = 15 #Number of trials required before a pause
        self.pauseDuration = 20000 #20 seconds
        self.cueDuration = 4000 #4seconds
        self.preCueDuration = 2000 #2 seconds
        self.postCueDuration = 2000 #2 seconds
        self.countdownFrom = 2  # PRE_RUN Duration in seconds
        self.stopAt = 5 #Number of blocks per run
        self.blocks = 0


        #pygame feedback attiributes
        self.availableDirections = ['left', 'right','foot']
        self.FPS = 50
        self.fullscreen = False
        self.screenWidth = 1000
        self.screenHeight = 700

        self.pause = False
        self.quit = False
        self.quitting = False

        #ticks boolean variables
        self.countdown = True
        self.fixationCross = False
        self.cue = False
        self.postCue = False

        self.showsPause, self.showsShortPause = False, False

        self.elapsed, self.cueElapsed, self.countdownElapsed, \
        self.preCueElapsed, self.postCueElapsed,self.pauseElapsed = 0, 0, 0, 0, 0, 0
        self.completedTrials = 0

        self.f = 0

        self.resized = False
        self.pos = 0
        self.targetDirection = 0

        self.arrowPointlist = [(.5, 0), (.5, .33), (1, .33), (1, .66), (.5, .66), (.5, 1), (0, .5)]
        self.arrowColor = (127, 127, 127)
        self.borderColor = self.arrowColor
        self.backgroundColor = (64, 64, 64)
        self.cursorColor = (100, 149, 237)
        self.fontColor = self.cursorColor
        self.countdownColor = (237, 100, 148)

        self.borderWidthRatio = 0.4

                # How many degrees counter clockwise to turn an arrow pointing to the
        # left to point at left, right and foot
        self.LEFT, self.RIGHT, self.UP, self.DOWN = 'left', 'right', 'foot', 'tonge'
        self.directions = {self.LEFT: 0, self.RIGHT: 180, self.UP: 270, self.DOWN: 90}

        #Random sequence of cues
        self.cueSequence = list(np.repeat([0,1,2],self.pauseAfter / len(self.availableDirections)))
        random.shuffle(self.cueSequence)
    def init(self):

        PygameFeedback.init(self)

        ########################################################################

        self.FPS = 200
        self.screenPos = [1280, 0]
        self.screenSize = [1280, 1024]
        self.screen_center = [self.screenSize[0] / 2, self.screenSize[1] / 2]
        self.caption = "TrafficLight"

        self.trafficlight_size = (self.screenSize[1] / 6,
                                  self.screenSize[1] / 2)
        self.trafficlight_states = ('', 'green', 'red', 'yellow',
                                    'yellowgreen', 'yellowred')

        self.background_color = [127, 127, 127]
        self.text_fontsize = 75
        self.text_color = [64, 64, 64]
        self.char_fontsize = 100
        self.char_color = [0, 0, 0]

        self.prompt_text = 'Were you about to press?'
        self.pause_text = 'Pause. Press pedal to continue...'
        self.paused = True
        self.on_trial = False

        ########################################################################

        self.duration_light_yellow = 1000
        self.duration_light_redgreen = 1300
        self.duration_prompt = 1500
        self.duration_cross = 3000
        self.min_waittime = 1500

        self.marker_keyboard_press = 199
        self.marker_quit = 255
        self.marker_base_start = 10
        self.marker_base_interruption = 20
        self.marker_trial_end = 30
        self.marker_prompt = 40

        self.marker_identifier = {
            20: 'move silent light',
            21: 'move red light',
            22: 'move green light',
            23: 'idle red light',
            24: 'idle green light',
            40: 'prompt'
        }

        ########################################################################
        # MAIN PARAMETERS TO BE SET IN MATLAB

        self.listen_to_keyboard = 1
        self.make_interruptions = 1
        self.make_prompts = 0
        self.pause_every_x_events = 20
        self.end_after_x_events = 60
        self.end_pause_counter_type = 4  # 1 - button presses, 2 - move lights, 3 - idle lights, 4 - seconds
        self.bci_delayed_idle = 0
        self.trial_assignment = [
            4, 3, 4, 3, 4, 3
        ]  # 1 - move red, 2 - move green, 3 - idle red, 4 - idle green
        self.ir_idle_waittime = [
            3000.0, 3000.0, 3000.0, 3000.0, 3000.0, 3000.0
        ]
示例#36
0
文件: GoalKeeper.py 项目: svsobh/pyff
 def pre_mainloop(self):
     #self.logger.debug("on_play")
     PygameFeedback.pre_mainloop(self)
     #self.load_images()  # this is done in init_graphics
     self.init_run()
     self.gameover = False
示例#37
0
 def pre_mainloop(self):
     PygameFeedback.pre_mainloop(self)
     self.logger.debug("on_play")
     self.send_parallel(self.GAME_STATUS_PLAY)
示例#38
0
文件: GoalKeeper.py 项目: svsobh/pyff
 def post_mainloop(self):
     PygameFeedback.post_mainloop()
     self.send_parallel(self.END_EXP)
示例#39
0
    def init(self):
        """
        Initializes the variables and stuff, but not pygame itself.
        """
        PygameFeedback.init(self)
        self.logger.debug("on_init")
        self.caption = 'Cursor Arrow Feedback'
        self.send_parallel(self.INIT_FEEDBACK)

        self.durationUntilBorder = 1000
        self.durationPerTrial = 4000
        self.durationIndicateGoal = 1000
        self.trials = 20
        self.pauseAfter = 4
        self.pauseDuration = 9000
        self.availableDirections =  ['right', 'foot']
        self.FPS =  50
        self.fullscreen =  False
        self.screenWidth =  1000
        self.screenHeight =  700
        self.countdownFrom = 2
        self.hitMissDuration =  1000
        self.dampedMovement = False
        self.showPunchline = True
        #self.damping = 'linear'
        self.damping = 'distance'

        self.pause = False
        self.quit = True
        self.quitting = True

        self.gameover = False
        self.countdown = True
        self.hit = False
        self.miss = False
        self.shortPause = False
        self.indicateGoal = False

        self.firstTickOfTrial = True

        self.showsPause, self.showsShortPause = False, False
        self.showsHitMiss, self.showsGameover = False, False

        self.elapsed, self.trialElapsed, self.countdownElapsed = 0,0,0
        self.hitMissElapsed, self.shortPauseElapsed, self.indicateGoalElapsed = 0,0,0

        self.completedTrials = 0

        self.f = 0
        self.hitMiss = [0,0]
        self.resized = False
        self.pos = 0
        self.targetDirection = 0

        self.arrowPointlist = [(.5,0), (.5,.33), (1,.33), (1,.66), (.5,.66), (.5,1), (0,.5)]
        self.arrowColor = (127, 127, 127)
        self.borderColor = self.arrowColor
        self.backgroundColor = (64, 64, 64)
        self.cursorColor = (100, 149, 237)
        self.fontColor = self.cursorColor
        self.countdownColor = (237, 100, 148)
        self.punchLineColor = self.cursorColor
        self.punchLineColorImpr = (100, 200 , 100)  # if punchline is improved

        self.punchlineThickness = 5   # in pixels
        self.borderWidthRatio = 0.4     # in pixels
        self.punchlinePos1, self.punchlinePos2 = 0,0

        #=============
        # NOTE: only one of the following variables should be True
        self.hitIfLateral = True
        self.reject = False
        #=============


        # How many degrees counter clockwise to turn an arrow pointing to the
        # left to point at left, right and foot
        self.LEFT, self.RIGHT, self.DOWN, self.UP = 'left', 'right', 'foot', 'up'
        self.directions = {self.LEFT: 0, self.RIGHT: 180, self.DOWN: 90, self.UP: 270}
示例#40
0
    def init(self):
        PygameFeedback.init(self)

        ########################################################################
        self.FPS = 200
        self.screenPos = [0, 0]
        self.screenSize = [1000, 1000]
        self.screen_center = [self.screenSize[0] / 2, self.screenSize[1] / 2]
        self.caption = "ReadinessFeedback"

        self.background_color = [127, 127, 127]
        self.text_fontsize = 75
        self.text_color = [64, 64, 64]
        self.char_fontsize = 100
        self.char_color = [0, 0, 0]
        self.white_color = [255, 255, 255]
        self.red_color = [225, 0, 0]
        self.radius = 100

        self.pause_text = 'Press pedal to start...'
        self.paused = True
        self.on_trial = False
        self.searching_rp = False
        self.training_counter = 0

        ########################################################################

        self.marker_keyboard_press = 199
        self.marker_quit = 255
        self.marker_base_start = 10
        self.marker_base_interruption = 20
        self.marker_trial_end = 30
        self.marker_prompt = 40

        ########################################################################
        # MAIN PARAMETERS TO BE SET IN MATLAB

        self.listen_to_keyboard = 1
        self.pause_every_x_events = 2
        self.end_after_x_events = 6

        ########################################################################

        # logic parameters
        self.emg_history = []
        self.eeg_history = []
        self.rp_history = []
        self.last_cross_shown = pygame.time.get_ticks()
        self.last_circle_shown = pygame.time.get_ticks()
        self.one_std_val = 25
        self.mean_value = 50

        self.rp_dist_init = [
            3.40158, 5.91582, 8.72199, 2.09857, 1.57752, 2.13866, 1.31238,
            0.6742, -0.860305, 0.869217, -2.20397, -0.427483, 3.09122,
            -3.15091, 6.29236, 3.96954, -2.99037, -0.372976, 3.0263, 3.8923,
            -0.655221, 1.86118, 2.16084, -0.00743317, -10.7251, 0.493279,
            0.844872, 2.12802, 4.46754, 2.9867, 2.67655, 4.06675, 1.01152,
            2.13234, 3.17019, -0.483233, 2.92781, 3.2214, -3.94281, -1.15404,
            4.38632, 1.29367, 4.01247, -0.0690076, 6.65976, 6.36116, -0.479293,
            6.05266, 5.24286, 4.2689, -3.3575, 4.44705, 1.55116, 2.94615,
            2.08329, 4.34001, 2.62014, 5.26946, 1.24628, 2.23645, 1.19922,
            -0.454266, 5.87512, 4.72588, 6.4719, 6.14339, 6.07847, 8.75295,
            7.29186, 5.12702, 11.5874, 1.30933, 1.30272, -1.92392, -2.79681,
            0.776014, 7.42855, 0.952247, -0.469118, 5.27124, 3.45942, 1.59118,
            3.96028, 3.67294, 3.03981, 1.52358, 2.41185, 2.48132, 2.03066,
            6.84007, 4.25418, 3.03598, 2.84473, 3.6167, 1.53169, 6.81807,
            2.31844, 1.12883
        ]
        self.rp_dist_init = sorted(self.rp_dist_init)
        self.rect = pygame.Surface((50, 0))
        self.clf_input = 0