コード例 #1
0
 def _send_breaks(self):
     t = time.time()
     tags_helper.send_tag(self.conn, t, t, "break",{'duration':sum(self.break_times)})
     appliance_helper.send_stop(self.conn)        
     for i, t in enumerate(self.break_times):
         #ugm_helper.send_text(self.conn, self.break_texts[i])
         ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.break_texts[i]+str(self.sequence.qsize()))
         time.sleep(t)
コード例 #2
0
 def _send_breaks(self):
     t = time.time()
     tags_helper.send_tag(self.conn, t, t, "break",{'duration':sum(self.break_times)})
     appliance_helper.send_stop(self.conn)        
     for i, t in enumerate(self.break_times):
         #ugm_helper.send_text(self.conn, self.break_texts[i])
         ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.break_texts[i]+str(self.sequence.qsize()))
         time.sleep(t)
コード例 #3
0
    def handle_message(self, mxmsg):
        if mxmsg.type == types.ROBOT_FEEDBACK_CONTROL:
            if mxmsg.message == 'start':
                self.logger.info("Got start message. Start robot feedback!!!")
                self.is_on = True
            elif mxmsg.message == 'stop':
                self.logger.info("Got stop message. Stop robot feedback!!!")
                self.is_on = False
                ugm_helper.send_logo(self.conn, 'obci.gui.ugm.resources.bci.png')#todo - CEBIT fix... should be done somewhere in logic, but to ensure that robot feed will not overwrite log do it here...
            else:
                self.logger.warning("Unrecognised control message:" + str(mxmsg.message))

        if DEBUG:
            self.debug.next_sample()
        diff = (time.time() - self._last_time)
        if not self.is_on:
            self.no_response()
            return
        elif diff > 1.0:
            self._last_time = time.time()
            self.logger.error("Last time bigger than 1.0... give it a chance next time. ...")
            self.no_response()
            return
        elif  diff > 0.2:
            self.logger.debug("Last time bigger than 0.2... don`t try read image for a while ...")
            self.no_response()
            return
        elif diff > 0.05:
            self._last_time = time.time()
            t = time.time()
            try:
                self.logger.debug("Start getting image...")
                image = self._robot.get_image(timeout=0.5)
                self.logger.debug("Succesful get_image time:"+str(time.time()-t))
            except:
                self.logger.error("UNSuccesful get_image time:"+str(time.time()-t))
                self.logger.error("Could not connect to ROBOT. Feedback is OFF!")
            else:
                try:
                    with open(self.imgpath, 'w') as fil:
                        fil.write(image)
                        fil.close()
                        ugm_helper.send_config_for(self.conn, self.robot_image_id, 'image_path', self.imgpath)
                        self.logger.debug("Robot image sent " + self.imgpath + ' id: ' + str(self.robot_image_id))
                        self.index = int(not self.index)
                        self.imgpath = self.paths[self.index]
                except Exception, e:
                    self.logger.error("An error occured while writing image to file!")
                    print(repr(e))
            self.no_response()
            return
コード例 #4
0
 def _show_configs(self, cfg, suffix=u""):
     text_id = int(self.config.get_param('ugm_text_id'))
     all_freqs = cfg['all_freqs'].split(';')
     all_means = cfg['all_means'].split(';')
     ugm_helper.send_config_for(
         self.conn, text_id, 'message',
         u''.join([self.config.get_param('show_freqs_text'),# i ich sila:,
                  '\n',
                  #' '.join([all_freqs[i]+" ("+all_means[i]+")" for i in range(len(all_freqs))]),
                   ' '.join([all_freqs[i] for i in range(len(all_freqs))]),
                  #'\n',
                  #u'Suggested buffer length: '+str(cfg['buffer'])+" secs",
                  '\n',
                  suffix
                  ])
         )
コード例 #5
0
 def _show_configs(self, cfg, suffix=u""):
     text_id = int(self.config.get_param('ugm_text_id'))
     all_freqs = cfg['all_freqs'].split(';')
     all_means = cfg['all_means'].split(';')
     ugm_helper.send_config_for(
         self.conn,
         text_id,
         'message',
         u''.join([
             u"Best frequencies:"  # i ich sila:",
             '\n',
             #' '.join([all_freqs[i]+" ("+all_means[i]+")" for i in range(len(all_freqs))]),
             ' '.join([all_freqs[i] for i in range(len(all_freqs))]),
             '\n',
             #u'Suggested buffer length: '+str(cfg['buffer'])+" secs",
             #'\n',
             suffix
         ]))
コード例 #6
0
    def run(self):
        index = 0
        imgpath = self.paths[index]

        while True:
            try:
                image = self._robot.get_image()
            except:
                self.logger.error("Could not connect to ROBOT. Feedback is OFF!")
            else:
                try:
                    with open(imgpath, 'w') as fil:
                        fil.write(image)
                        fil.close()
                        ugm_helper.send_config_for(self.conn, self.robot_image_id, 'image_path', imgpath)
                        self.logger.debug("Robot image sent " + imgpath + ' id: ' + str(self.robot_image_id))
                        index = int(not index)
                        imgpath = self.paths[index]
                except:
                    self.logger.error("An error occured while writing image to file!")
                time.sleep(0.05)
コード例 #7
0
    def run(self):
        index = 0
        imgpath = self.paths[index]

        while True:
            try:
                image = self._robot.get_image()
            except:
                self.logger.error("Could not connect to ROBOT. Feedback is OFF!")
            else:
                try:
                    with open(imgpath, 'w') as fil:
                        fil.write(image)
                        fil.close()
                        ugm_helper.send_config_for(self.conn, self.robot_image_id, 'image_path', imgpath)
                        self.logger.debug("Robot image sent " + imgpath + ' id: ' + str(self.robot_image_id))
                        index = int(not index)
                        imgpath = self.paths[index]
                except:
                    self.logger.error("An error occured while writing image to file!")
                time.sleep(0.05)
コード例 #8
0
ファイル: maze_engine.py プロジェクト: BrainTech/openbci
    def maze_move(self, direction):
        if self._curr == 2:
            if direction == 'LEFT':
                self._line = LEFT_LINE
            elif direction == 'RIGHT':
                self._line = RIGHT_LINE
            else:
                pass #bad move
        info = self._line[self._curr]
        if info['move'] == direction:
            #make move
            ugm_helper.send_config(self.conn, 
                                   str([{'id':'1986', 
                                         'maze_user_color':'#00FFFF',
                                         'maze_user_direction': info['dir'],
                                         'maze_user_x':info['x'], 
                                         'maze_user_y':info['y']}
                                        ]), 1)
            #add tooltip
            self._message = info['tooltip']
            self._update_letters()
            #send to robot
            self.robot(info['robot'])
            ugm_helper.send_config_for(self.conn, '1986', 'maze_user_color', '#222777')

            if len(self._line) > 4 and self._curr == len(self._line) - 2:
                self._maze_success = True
            self._curr = self._curr + 1
        else:
            ugm_helper.send_config_for(self.conn, '1986', 'maze_user_color', '#FF0000')
            time.sleep(0.5)
            ugm_helper.send_config_for(self.conn, '1986', 'maze_user_color', '#222777')
コード例 #9
0
    def run(self):
        self.logger.info("RUN!!!")
        #process intro
        #ugm_helper.send_text(self.conn, self.hi_text)
        ugm_helper.send_config(self.conn, self.ugm)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.hi_text)
        #keystroke.wait([" "])
        time.sleep(15)
        #ugm_helper.send_text(self.conn, self.trial_text)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.trial_text)
        time.sleep(15)
        #keystroke.wait([" "])
        ugm_helper.send_config(self.conn, self.ugm)
        appliance_helper.send_freqs(self.conn, self.all_freqs[:int(self.config.get_param("fields_count"))])
        #ugm_helper.send_config(self.conn, self.ugm)
        ugm_helper.send_config_for(self.conn, self.text_ids[1], 'message', self.feed_text)
        time.sleep(self.target_time)
        appliance_helper.send_stop(self.conn)
        #ugm_helper.send_text(self.conn, self.ready_text)
        ugm_helper.send_config(self.conn, self.ugm)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.ready_text)
        time.sleep(15)
        #keystroke.wait([" "])
        self.logger.info("Send begin config ...")
        #ugm_helper.send_config(self.conn, self.ugm)

        #process trials
        self._run()

        #process good bye
        appliance_helper.send_stop(self.conn)
        #ugm_helper.send_text(self.conn, self.bye_text)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.bye_text)
        #acquire some more data
        time.sleep(2)
        self.logger.info("Send finish saving and finish ...")
        acquisition_helper.send_finish_saving(self.conn)
コード例 #10
0
    def run(self):
        self.logger.info("RUN!!!")
        #process intro
        #ugm_helper.send_text(self.conn, self.hi_text)
        ugm_helper.send_config(self.conn, self.ugm)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.hi_text)
        #keystroke.wait([" "])
        time.sleep(15)
        #ugm_helper.send_text(self.conn, self.trial_text)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.trial_text)
        time.sleep(15)
        #keystroke.wait([" "])
        ugm_helper.send_config(self.conn, self.ugm)
        appliance_helper.send_freqs(self.conn, self.all_freqs[:int(self.config.get_param("fields_count"))])
        #ugm_helper.send_config(self.conn, self.ugm)
        ugm_helper.send_config_for(self.conn, self.text_ids[1], 'message', self.feed_text)
        time.sleep(self.target_time)
        appliance_helper.send_stop(self.conn)
        #ugm_helper.send_text(self.conn, self.ready_text)
        ugm_helper.send_config(self.conn, self.ugm)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.ready_text)
        time.sleep(15)
        #keystroke.wait([" "])
        self.logger.info("Send begin config ...")
        #ugm_helper.send_config(self.conn, self.ugm)

        #process trials
        self._run()

        #process good bye
        appliance_helper.send_stop(self.conn)
        #ugm_helper.send_text(self.conn, self.bye_text)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.bye_text)
        #acquire some more data
        time.sleep(2)
        self.logger.info("Send finish saving and finish ...")
        acquisition_helper.send_finish_saving(self.conn)
コード例 #11
0
    def run(self):
        #process intro
        ugm_helper.send_text(self.conn, self.hi_text)
        #keystroke.wait([" "])
        time.sleep(90)

        ugm_helper.send_config(self.conn, self.ugm)

        time.sleep(3)
        """
        #keystroke.wait([" "])
        #ugm_helper.send_text(self.conn, self.trial_text)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.trial_text)
        #keystroke.wait([" "])
        time.sleep(3)
        ugm_helper.send_config(self.conn, self.ugm)
        appliance_helper.send_freqs(self.conn, self.all_freqs[:int(self.config.get_param("fields_count"))])
        #ugm_helper.send_config(self.conn, self.ugm)
        ugm_helper.send_config_for(self.conn, self.text_ids[1], 'message', self.feed_text)
        time.sleep(self.target_time)
        appliance_helper.send_stop(self.conn)
        #ugm_helper.send_text(self.conn, self.ready_text)
        ugm_helper.send_config(self.conn, self.ugm)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.ready_text)
        time.sleep(3)
        #keystroke.wait([" "])
        self.logger.info("Send begin config ...")
        #ugm_helper.send_config(self.conn, self.ugm)
        """
        #process trials
        self._run()

        #process good bye
        appliance_helper.send_stop(self.conn)
        #ugm_helper.send_text(self.conn, self.bye_text)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message',
                                   self.bye_text)
コード例 #12
0
    def run(self):
        # process intro
        ugm_helper.send_text(self.conn, self.hi_text)
        # keystroke.wait([" "])
        time.sleep(90)

        ugm_helper.send_config(self.conn, self.ugm)

        time.sleep(3)
        """
        #keystroke.wait([" "])
        #ugm_helper.send_text(self.conn, self.trial_text)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.trial_text)
        #keystroke.wait([" "])
        time.sleep(3)
        ugm_helper.send_config(self.conn, self.ugm)
        appliance_helper.send_freqs(self.conn, self.all_freqs[:int(self.config.get_param("fields_count"))])
        #ugm_helper.send_config(self.conn, self.ugm)
        ugm_helper.send_config_for(self.conn, self.text_ids[1], 'message', self.feed_text)
        time.sleep(self.target_time)
        appliance_helper.send_stop(self.conn)
        #ugm_helper.send_text(self.conn, self.ready_text)
        ugm_helper.send_config(self.conn, self.ugm)
        ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.ready_text)
        time.sleep(3)
        #keystroke.wait([" "])
        self.logger.info("Send begin config ...")
        #ugm_helper.send_config(self.conn, self.ugm)
        """
        # process trials
        self._run()

        # process good bye
        appliance_helper.send_stop(self.conn)
        # ugm_helper.send_text(self.conn, self.bye_text)
        ugm_helper.send_config_for(self.conn, self.text_id, "message", self.bye_text)
コード例 #13
0
    def maze_move(self, direction):
        if self._curr == 2:
            if direction == 'LEFT':
                self._line = LEFT_LINE
            elif direction == 'RIGHT':
                self._line = RIGHT_LINE
            else:
                pass  #bad move
        info = self._line[self._curr]
        if info['move'] == direction:
            #make move
            ugm_helper.send_config(
                self.conn,
                str([{
                    'id': '1986',
                    'maze_user_color': '#00FFFF',
                    'maze_user_direction': info['dir'],
                    'maze_user_x': info['x'],
                    'maze_user_y': info['y']
                }]), 1)
            #add tooltip
            self._message = info['tooltip']
            self._update_letters()
            #send to robot
            self.robot(info['robot'])
            ugm_helper.send_config_for(self.conn, '1986', 'maze_user_color',
                                       '#222777')

            if len(self._line) > 4 and self._curr == len(self._line) - 2:
                self._maze_success = True
            self._curr = self._curr + 1
        else:
            ugm_helper.send_config_for(self.conn, '1986', 'maze_user_color',
                                       '#FF0000')
            time.sleep(0.5)
            ugm_helper.send_config_for(self.conn, '1986', 'maze_user_color',
                                       '#222777')
コード例 #14
0
ファイル: logic_give_id.py プロジェクト: BrainTech/openbci
 def run(self):
     ugm_helper.send_config(self.conn, self.ugm)
     ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.ID)
コード例 #15
0
    def handle_message(self, mxmsg):
        if mxmsg.type == types.ROBOT_FEEDBACK_CONTROL:
            if mxmsg.message == 'start':
                self.logger.info("Got start message. Start robot feedback!!!")
                self.is_on = True
            elif mxmsg.message == 'stop':
                self.logger.info("Got stop message. Stop robot feedback!!!")
                self.is_on = False
                ugm_helper.send_logo(
                    self.conn, 'obci.gui.ugm.resources.bci.png'
                )  #todo - CEBIT fix... should be done somewhere in logic, but to ensure that robot feed will not overwrite log do it here...
            else:
                self.logger.warning("Unrecognised control message:" +
                                    str(mxmsg.message))

        if DEBUG:
            self.debug.next_sample()
        diff = (time.time() - self._last_time)
        if not self.is_on:
            self.no_response()
            return
        elif diff > 1.0:
            self._last_time = time.time()
            self.logger.error(
                "Last time bigger than 1.0... give it a chance next time. ...")
            self.no_response()
            return
        elif diff > 0.2:
            self.logger.debug(
                "Last time bigger than 0.2... don`t try read image for a while ..."
            )
            self.no_response()
            return
        elif diff > 0.05:
            self._last_time = time.time()
            t = time.time()
            try:
                self.logger.debug("Start getting image...")
                image = self._robot.get_image(timeout=0.5)
                self.logger.debug("Succesful get_image time:" +
                                  str(time.time() - t))
            except:
                self.logger.error("UNSuccesful get_image time:" +
                                  str(time.time() - t))
                self.logger.error(
                    "Could not connect to ROBOT. Feedback is OFF!")
            else:
                try:
                    with open(self.imgpath, 'w') as fil:
                        fil.write(image)
                        fil.close()
                        ugm_helper.send_config_for(self.conn,
                                                   self.robot_image_id,
                                                   'image_path', self.imgpath)
                        self.logger.debug("Robot image sent " + self.imgpath +
                                          ' id: ' + str(self.robot_image_id))
                        self.index = int(not self.index)
                        self.imgpath = self.paths[self.index]
                except Exception, e:
                    self.logger.error(
                        "An error occured while writing image to file!")
                    print(repr(e))
            self.no_response()
            return
コード例 #16
0
ファイル: logic_finish.py プロジェクト: vjenissr/openbci
 def run(self):
     ugm_helper.send_config(self.conn, self.ugm)
     ugm_helper.send_config_for(self.conn, self.text_id, 'message',
                                self.text)