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')
def blinking_stopped(self): time.sleep(1) ugm_helper.send_text(self.conn, self.break_text) time.sleep(self.break_duration) ugm_helper.send_config(self.conn, self.blinking_ugm) time.sleep(1) ugm_helper.send_start_blinking(self.conn)
def _send_fancy_target(self, target_ind): t = time.time() target_config = str([self.raw_ugm.get_config_for(self.text_ids[target_ind])]) while time.time() - t < self.target_time: self._curr_fancy_x += (random.random()-0.5)/25.0 self._curr_fancy_y += (random.random()-0.5)/25.0 if self._curr_fancy_x < 0.4: self._curr_fancy_x = 0.4 elif self._curr_fancy_x > 0.6: self._curr_fancy_x = 0.6 if self._curr_fancy_y < 0.4: self._curr_fancy_y = 0.4 elif self._curr_fancy_y > 0.6: self._curr_fancy_y = 0.6 l_str_config = str([ {'id':self.text_ids[target_ind], 'message':self.feed_text, 'position_horizontal_type':'relative', 'position_vertical_type':'relative', 'position_horizontal':self._curr_fancy_x, 'position_vertical':self._curr_fancy_y, #'font_size':15, 'message':self.feed_text } ]) ugm_helper.send_config(self.conn, l_str_config, 1) time.sleep(0.1) ugm_helper.send_config(self.conn, target_config, 1)
def handle_message(self, mxmsg): if mxmsg.type == types.ETR_CALIBRATION_RESULTS: res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) data = res.channels self.logger.debug("GOT ETR CALIBRATION RESULTS: "+str(data)) self.handle_calibration_mesage(data) elif mxmsg.type == types.ETR_SIGNAL_MESSAGE: l_msg = variables_pb2.Sample2D() l_msg.ParseFromString(mxmsg.message) self.logger.debug("GOT MESSAGE: "+str(l_msg)) dec, ugm = self.handle_etr_message(l_msg) if dec >= 0: self.logger.debug("Sending dec message...") self.conn.send_message(message = str(dec), type = types.DECISION_MESSAGE, flush=True) elif ugm is not None: self.logger.debug("Sending ugm message...") ugm_helper.send_config(self.conn, ugm, 1) else: self.logger.info("Got notihing from manager...") self.no_response()
def handle_message(self, mxmsg): if mxmsg.type == types.ETR_CALIBRATION_RESULTS: res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) data = res.channels self.logger.debug("GOT ETR CALIBRATION RESULTS: " + str(data)) self.handle_calibration_mesage(data) elif mxmsg.type == types.ETR_SIGNAL_MESSAGE: l_msg = variables_pb2.Sample2D() l_msg.ParseFromString(mxmsg.message) self.logger.debug("GOT MESSAGE: " + str(l_msg)) dec, ugm = self.handle_etr_message(l_msg) if dec >= 0: self.logger.debug("Sending dec message...") self.conn.send_message(message=str(dec), type=types.DECISION_MESSAGE, flush=True) elif ugm is not None: self.logger.debug("Sending ugm message...") ugm_helper.send_config(self.conn, ugm, 1) else: self.logger.info("Got notihing from manager...") self.no_response()
def begin(self): ugm_helper.send_text(self.conn, self.hi_text) #keystroke.wait([" "]) time.sleep(5) self.logger.info("Send begin config ...") ugm_helper.send_config(self.conn, self.blinking_ugm) self.logger.info("Send start blinking on begin ...") ugm_helper.send_start_blinking(self.conn)
def handle_message(self, mxmsg): #~ self.logger.info("EtrAnalysis\n") if mxmsg.type == types.ETR_CALIBRATION_RESULTS: #### What to do when receive ETR_MATRIX information res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) self.logger.debug("GOT ETR CALIBRATION RESULTS: "+str(res.channels)) #process blinks only when hold_time passed if self._last_dec_time > 0: t = time.time() - self._last_dec_time if t > self.hold_after_dec: self._last_dec_time = 0 else: self.no_response() return # What to do after everything is done... if mxmsg.type == types.DECISION_MESSAGE: self._last_dec_time = time.time() if mxmsg.type == types.ETR_SIGNAL_MESSAGE: #### What to do when receive ETR_SIGNAL information msg = variables_pb2.Sample2D() msg.ParseFromString(mxmsg.message) self.logger.debug("GOT MESSAGE: "+str(msg)) # Save positions x, y = msg.x, msg.y self._update_buffor(np.array([[x],[y]])) # Turn position into heatmap m = self._calc_metric(x,y) self._update_heatmap(m) ugm = self.ugm_mgr.get_ugm_updates(self.feeds, msg) ugm_helper.send_config(self.conn, ugm, 1) self.nCount += 1 if self.nCount % self.nRefresh == 0: # Calc heatmap as probabilty density pdf = self._calc_pdf() # Send results to decision modul self._send_results() #~ elif mxmsg.type == types.BLINK_MESSAGE: #### What to do when receive BLINK_NO information #~ blink = variables_pb2.Blink() #~ blink.ParseFromString(mxmsg.message) #~ self.logger.debug("GOT BLINK: "+str(blink.index)+" / "+str(blink.timestamp)) self.no_response()
def _update_letters(self): l_config = [] l_letters = self._curr_letters for i, i_letters in enumerate(l_letters): l_conf = {'id': self.text_ids[i], 'message': i_letters} l_config.append(l_conf) l_config.append({'id': self.text_id, 'message': self._message}) l_str_config = str(l_config) self.logger.info("UPDATE: " + l_str_config) ugm_helper.send_config(self.conn, l_str_config, 1)
def _update_letters(self): l_config = [] l_letters = self._curr_letters for i, i_letters in enumerate(l_letters): l_conf = {'id':self.text_ids[i], 'message':i_letters} l_config.append(l_conf) l_config.append({'id':self.text_id, 'message':self._message}) l_str_config = str(l_config) self.logger.info("UPDATE: "+l_str_config) ugm_helper.send_config(self.conn, l_str_config, 1)
def _send_feedback(self, dec, dec_time): while True: t = time.time() - dec_time if t > self.feed_time: ugm_config = self.feed_manager.update_ugm(dec, -1) ugm_helper.send_config(self.conn, ugm_config, 1) break else: self.logger.debug("t="+str(t)+"FEED: "+str(t/self.feed_time)) ugm_config = self.feed_manager.update_ugm(dec, 1-(t/self.feed_time)) ugm_helper.send_config(self.conn, ugm_config, 1) time.sleep(0.05)
def _send_feedback(self, dec, dec_time): while True: t = time.time() - dec_time if t > self.feed_time: ugm_config = self.feed_manager.update_ugm(dec, -1) ugm_helper.send_config(self.conn, ugm_config, 1) break else: self.logger.debug("t=" + str(t) + "FEED: " + str(t / self.feed_time)) ugm_config = self.feed_manager.update_ugm( dec, 1 - (t / self.feed_time)) ugm_helper.send_config(self.conn, ugm_config, 1) time.sleep(0.05)
def begin(self): ugm_helper.send_config(self.conn, self.status_ugm) ugm_helper.send_status(self.conn, self.hi_text) time.sleep(5) ugm_helper.send_status(self.conn, self.hi_text_2) time.sleep(8) ugm_helper.send_status(self.conn, self.hi_text_3) time.sleep(3) ugm_helper.send_status(self.conn, "") self.logger.info("Send begin config ...") ugm_helper.send_config(self.conn, self.blinking_ugm) self.logger.info("Send start blinking on begin ...") ugm_helper.send_start_blinking(self.conn)
def _update_letters(self): """Sent to self._server current logic data: - current message, """ self.logger.info("UPDATE MESSAGE: " + self._message) l_config = [] l_letters = self._compute_current_letters() for i, i_letters in enumerate(l_letters): l_conf = {'id': self.text_ids[i], 'message': i_letters} l_config.append(l_conf) l_config.append({'id': self.text_id, 'message': self._message}) l_str_config = str(l_config) self.logger.info("UPDATE: " + l_str_config) ugm_helper.send_config(self.conn, l_str_config, 1)
def _send_feed(self, target_ind): if self.feed_time <= 0: return # prepare and send feed text l_config = [{"id": self.text_ids[target_ind], "message": self.feed_text}] l_str_config = str(l_config) ugm_helper.send_config(self.conn, l_str_config, 1) t = time.time() tags_helper.send_tag(self.conn, t, t, "feedback", {"field": target_ind, "duration": self.feed_time}) # wait time.sleep(self.feed_time) # remove feed l_config[0]["message"] = "" l_str_config = str(l_config) ugm_helper.send_config(self.conn, l_str_config, 1)
def _update_letters(self): """Sent to self._server current logic data: - current message, """ self.logger.info("UPDATE MESSAGE: "+self._message) l_config = [] l_letters = self._compute_current_letters() for i, i_letters in enumerate(l_letters): l_conf = {'id':self.text_ids[i], 'message':i_letters} l_config.append(l_conf) l_config.append({'id':self.text_id, 'message':self._message}) l_str_config = str(l_config) self.logger.info("UPDATE: "+l_str_config) ugm_helper.send_config(self.conn, l_str_config, 1)
def _send_feed(self, target_ind): if self.feed_time <= 0: return #prepare and send feed text l_config = [{'id':self.text_ids[target_ind], 'message':self.feed_text}] l_str_config = str(l_config) ugm_helper.send_config(self.conn, l_str_config, 1) t = time.time() tags_helper.send_tag(self.conn, t, t, "feedback", {'field':target_ind, 'duration':self.feed_time }) #wait time.sleep(self.feed_time) #remove feed l_config[0]['message'] = "" l_str_config = str(l_config) ugm_helper.send_config(self.conn, l_str_config, 1)
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')
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)
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)
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)
def run(self): ugm_helper.send_config(self.conn, self.ugm) ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.ID)
def _send_ugm(self): ugm_helper.send_config(self.conn, self.ugm) t = time.time() tags_helper.send_tag(self.conn, t, t, "trial",{'duration':self.feed_time+self.target_time})
def end(self): ugm_helper.send_config(self.conn, self.status_ugm) ugm_helper.send_status(self.conn, self.bye_text) #acquire some more data time.sleep(2) acquisition_helper.send_finish_saving(self.conn)
def run(self): ugm_helper.send_config(self.conn, self.ugm) ugm_helper.send_config_for(self.conn, self.text_id, 'message', self.text)