def worker(self): self.run_condition.acquire() while True: with self.lock: self.paused = False self.topics['events'].publish(Event('idle', 0)) self.run_condition.wait() with self.lock: nodes = [ Node.createNode(node, self, self.start_time) for node in self.running_nodes ] self.topics['events'].publish(Event('running', self.start_time)) if len(nodes) == 0: continue running = True while running: with self.lock: run_time = self.get_run_time() if not self.running: self.topics['events'].publish( Event('finished', run_time)) break elif self.paused: continue running = False # checks if any nodes still running for node in nodes: running = node.run(run_time) or running self.run_condition.release()
def worker(self): self.run_condition.acquire() while True: with self.lock: self.paused = False self.running = False self.topics['events'].publish(Event('idle', 0)) self.run_condition.wait() self.topics['events'].publish(Event('running', self.start_time)) if len(self.running_performances) == 0: continue behavior = True for i, performance in enumerate(self.running_performances): nodes = [Node.createNode(node, self, self.start_time, performance.get('id', '')) for node in performance['nodes']] pid = performance.get('id', '') pause = self.get_property(os.path.dirname(pid), 'pause_behavior') # Pause must be either enabled or not set (by default all performances are # pausing behavior if its not set) if (pause or pause is None) and behavior: # Only pause behavior if its already running. Otherwise Pause behavior have no effect if rospy.get_param("/behavior_enabled"): self.topics['interaction'].publish('btree_off') behavior = False with self.lock: if not self.running: break running = True finished = None while running: with self.lock: run_time = self.get_run_time() if not self.running: self.topics['events'].publish(Event('finished', run_time)) break running = False # checks if any nodes still running for node in nodes: running = node.run(run_time) or running if finished is None: # true if all performance nodes are already finished finished = not running with self.lock: autopause = self.autopause and i < len(self.running_performances) - 1 if not finished and autopause: self.pause() while self.paused: continue if not behavior: self.topics['interaction'].publish('btree_on')
def worker(self): while True: with self.lock: self.paused = False self.topics['events'].publish(Event('idle', 0)) nodes = self.queue.get() self.topics['events'].publish(Event('running', self.start_time)) if len(nodes) == 0: continue running = True while running: with self.lock: run_time = self.get_run_time() if not self.running: self.topics['events'].publish( Event('finished', run_time)) break elif self.paused: continue running = False for node in nodes: running = node.run(run_time) or running
def resume(self): self.duration = 0 self.runner.resume() self.runner.topics['events'].publish(Event('chat_end', 0)) if self.subscriber: self.subscriber.unregister() self.subscriber = False
def pause(self): with self.lock: if self.running and not self.paused: self.pause_time = time.time() self.paused = True self.topics['events'].publish(Event('paused', self.get_run_time())) return True else: return False
def add_turn(self): self.turns += 1 self.last_turn_at = time.time() if self.turns < self.dialog_turns and not ( self.timeout_mode == 'whole' and time.time() - self.started_at >= self.timeout): self.runner.topics['events'].publish(Event('chat', 0)) else: self.resume()
def resume(self): success = False with self.lock: if self.running and self.paused: run_time = self.get_run_time() self.paused = False self.start_timestamp = time.time() - run_time self.start_time = 0 self.topics['events'].publish(Event('resume', run_time)) success = True return success
def start(self, run_time): self.runner.pause() self.last_turn_at = time.time() if self.enable_chatbot: self.start_chatbot_session() def input_callback(event): self.respond( self.get_chatbot_response(event.data) if self.enable_chatbot else self.match_response(event.data)) self.subscriber = rospy.Subscriber('/' + self.runner.robot_name + '/nodes/listen/input', String, input_callback) self.runner.topics['events'].publish(Event('chat', 0)) self.runner.register('speech_events', self.speech_event_callback)
def start(self, run_time): self.runner.pause() if self.enable_chatbot: self.start_chatbot_session() def input_callback(event): self.respond( self.get_chatbot_response(event.data) if self. enable_chatbot else self.match_response(event.data)) if 'dialog_turns' not in self.data or int( self.data['dialog_turns']) <= self.turns: self.resume() self.subscriber = rospy.Subscriber( '/' + self.runner.robot_name + '/nodes/listen/input', String, input_callback) self.runner.topics['events'].publish(Event('chat', 0))
def worker(self): self.run_condition.acquire() while True: with self.lock: self.paused = False self.running = False self.topics['events'].publish(Event('idle', 0)) self.run_condition.wait() self.topics['events'].publish(Event('running', self.start_time)) with self.lock: if not self.running_performance: continue behavior = True offset = 0 timelines = self.running_performance[ 'timelines'] if 'timelines' in self.running_performance else [ self.running_performance ] for i, timeline in enumerate(timelines): if 'enabled' in timeline and not timeline['enabled']: continue # check if performance is finished without starting running = True self.running_nodes = [ Node.createNode(node, self, self.start_time - offset, timeline.get('id', '')) for node in timeline['nodes'] ] pid = timeline.get('id', '') finished = None run_time = 0 pause = pid and self.get_property(os.path.dirname(pid), 'pause_behavior') # Pause must be either enabled or not set (by default all performances are # pausing behavior if its not set) if (pause or pause is None) and behavior: # Only pause behavior if its already running. Otherwise Pause behavior have no effect behavior_enabled = False try: behavior_enabled = rospy.get_param("/behavior_enabled") except KeyError: pass if behavior_enabled: self.topics['interaction'].publish('btree_off') behavior = False with self.lock: if not self.running: break while running: with self.lock: run_time = self.get_run_time() if not self.running: self.topics['events'].publish( Event('finished', run_time)) break if self.paused: continue running = False # checks if any nodes still running for k, node in enumerate(self.running_nodes): running = node.run(run_time - offset) or running if finished is None: # true if all performance nodes are already finished finished = not running logger.info('Performance finished at :{0}'.format(run_time)) offset += self.get_timeline_duration(timeline) with self.lock: autopause = self.autopause and finished is False and i < len( timelines) - 1 if autopause: self.pause() if not behavior: self.topics['interaction'].publish('btree_on')
def respond(self, response): self.runner.topics['events'].publish(Event('chat_end', 0)) self.talking = True self.runner.topics['tts']['default'].publish(String(response))