Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 PKG = 'continuous_ops_web'
00038 NAME = 'task_list_server'
00039 import time
00040 import roslib; roslib.load_manifest(PKG)
00041
00042 from continuous_ops_msgs.srv import *
00043 from continuous_ops_msgs.msg import *
00044 import rospy
00045
00046 tasks = {}
00047
00048 def get_tasks(req):
00049 print "getting task list"
00050 resp = GetTaskListResponse()
00051 for i in range(10):
00052 task = Task()
00053 task.name = 'task%d' % i
00054 task.task_id = '%d' % i
00055 task.image_file = '/wg/bwi/eitan/ros/dev/continuous_ops/continuous_ops_web/src/continuous_ops_web/images/cont.jpg'
00056 resp.tasks.append(task)
00057 available_pub.publish(resp.tasks)
00058 return resp
00059
00060 def add_task(req):
00061 print "adding a task: %s" % req.task_id
00062 time.sleep(1)
00063 print "done sleeping"
00064 tasks['run%s' % req.task_id] = req.task_id
00065 resp = AddTaskResponse()
00066 resp.run_id = 'run%s' % req.task_id
00067 for key in tasks.keys():
00068 task = Task()
00069 task.name = 'task%s' % tasks[key]
00070 task.task_id = tasks[key]
00071 task.run_id = key
00072 resp.tasks.append(task)
00073 print resp
00074 return resp
00075
00076 def remove_task(req):
00077 print "removing task: %s" % req.run_id
00078 time.sleep(1)
00079 del tasks[req.run_id]
00080 resp = ChangeTaskResponse()
00081 for key in tasks.keys():
00082 task = Task()
00083 task.name = 'task%s' % tasks[key]
00084 task.task_id = tasks[key]
00085 task.run_id = key
00086 resp.tasks.append(task)
00087 print resp
00088 return resp
00089
00090 def get_scheduled_tasks(req):
00091 print "serving scheduled tasks"
00092 resp = GetTaskListResponse()
00093 for key in tasks.keys():
00094 task = Task()
00095 task.name = 'task%s' % tasks[key]
00096 task.task_id = tasks[key]
00097 task.run_id = key
00098 resp.tasks.append(task)
00099 print resp
00100 return resp
00101
00102 def reorder_tasks(req):
00103 print "reorder"
00104 time.sleep(1)
00105 print req
00106 resp = ReorderTaskListResponse()
00107 for key in tasks.keys():
00108 task = Task()
00109 task.name = 'task%s' % tasks[key]
00110 task.task_id = tasks[key]
00111 task.run_id = key
00112 resp.tasks.append(task)
00113 print resp
00114 return resp
00115
00116 def task_list_server():
00117 rospy.init_node(NAME)
00118 get = rospy.Service('get_available_tasks', GetTaskList, get_tasks)
00119 get_s = rospy.Service('get_scheduled_tasks', GetTaskList, get_scheduled_tasks)
00120 reorder = rospy.Service('reorder_tasks', ReorderTaskList, reorder_tasks)
00121 add = rospy.Service('add_task', AddTask, add_task)
00122 remove = rospy.Service('remove_task', ChangeTask, remove_task)
00123
00124 global available_pub
00125 available_pub = rospy.Publisher('available_tasks', Tasks, None, False, True)
00126 rospy.spin()
00127
00128 if __name__ == "__main__":
00129 task_list_server()