fifo_task_executor.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 from Queue import Queue, Empty
5 from strands_executive_msgs.msg import Task
6 from task_executor.base_executor import AbstractTaskExecutor
7 
8 
10  def __init__(self):
11  # init node first, must be done before call to super init for service advertising to work
12  # rospy.init_node("task_executor", log_level=rospy.DEBUG)
13  rospy.init_node("task_executor" )
14  # init superclasses
15  super( FIFOTaskExecutor, self ).__init__()
16  self.tasks = Queue()
17  self.advertise_services()
18 
19 
20  def add_tasks(self, tasks):
21  """ Called with a new task for the executor """
22  rospy.loginfo('Called with %s tasks' % len(tasks))
23  for task in tasks:
24  self.tasks.put(task)
25  rospy.loginfo('Queued %s tasks' % len(tasks))
26 
27  def task_demanded(self, previously_active_task):
28  """ Called when a task is demanded. self.active_task is the demanded task (and is being executed) and previously_active_task was the task that was being executed (which could be None) """
29  if previously_active_task:
30  self.add_tasks([previously_active_task])
31 
32  def run_executor(self):
33  r = rospy.Rate(1) # 1hz
34 
35  while not rospy.is_shutdown():
36 
37  if self.executing:
38  if not self.active_task:
39  print "need a task"
40  try:
41  task = self.tasks.get(False)
42  self.execute_task(task)
43  except Empty, e:
44  pass
45  else:
46  print "executing task %s" % self.active_task
47 
48  r.sleep()
49 
50 
51 if __name__ == '__main__':
52  executor = FIFOTaskExecutor()
53  executor.run_executor()
def task_demanded(self, previously_active_task)


task_executor
Author(s): Nick Hawes
autogenerated on Tue Mar 17 2015 20:08:13