example_task_routine.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import mongodb_store_msgs.srv as dc_srv
5 from mongodb_store_msgs.msg import StringPair
6 import mongodb_store.util as dc_util
7 from mongodb_store.message_store import MessageStoreProxy
8 from geometry_msgs.msg import Pose, Point, Quaternion
9 import StringIO
10 
11 from strands_executive_msgs import task_utils
12 from strands_executive_msgs.msg import Task
13 from strands_executive_msgs.srv import AddTasks, SetExecutionStatus
14 # import strands_executive_msgs
15 
16 import rospy
17 import actionlib
18 from strands_executive_msgs.msg import Task
19 from task_executor.msg import *
20 from topological_navigation.msg import GotoNodeAction
21 from copy import deepcopy
22 from random import random
23 from dateutil.tz import *
24 from datetime import *
25 from task_executor import task_routine
26 from task_executor.utils import TestTaskAction
27 
28 
30  # get services necessary to do the jon
31  add_tasks_srv_name = '/task_executor/add_tasks'
32  set_exe_stat_srv_name = '/task_executor/set_execution_status'
33  rospy.loginfo("Waiting for task_executor service...")
34  rospy.wait_for_service(add_tasks_srv_name)
35  rospy.wait_for_service(set_exe_stat_srv_name)
36  rospy.loginfo("Done")
37  add_tasks_srv = rospy.ServiceProxy(add_tasks_srv_name, AddTasks)
38  set_execution_status = rospy.ServiceProxy(set_exe_stat_srv_name, SetExecutionStatus)
39  return add_tasks_srv, set_execution_status
40 
41 def create_wait_task(max_duration):
42  master_task = Task(action='wait_action',start_node_id='WayPoint2',end_node_id='WayPoint3', max_duration=max_duration)
43  task_utils.add_time_argument(master_task, rospy.Time())
44  task_utils.add_duration_argument(master_task, max_duration)
45  return master_task
46 
47 def create_master_task(max_duration):
48  """
49  Create an example of a task which we'll copy for other tasks later.
50  This is a good example of creating a task with a variety of arguments.
51  """
52  # need message store to pass objects around
53  msg_store = MessageStoreProxy()
54 
55  # get the pose of a named object
56  pose_name = "my favourite pose"
57 
58  # get the pose if it's there
59  message, meta = msg_store.query_named(pose_name, Pose._type)
60  # if it's not there, add it in
61  if message == None:
62  message = Pose(Point(0, 1, 2), Quaternion(3, 4, 5, 6))
63  pose_id = msg_store.insert_named(pose_name, message)
64  else:
65  pose_id = meta["_id"]
66 
67 
68  master_task = Task(action='test_task',start_node_id='WayPoint2',end_node_id='WayPoint3', max_duration=max_duration)
69  task_utils.add_string_argument(master_task, 'hello world')
70  task_utils.add_object_id_argument(master_task, pose_id, Pose)
71  task_utils.add_int_argument(master_task, 24)
72  task_utils.add_float_argument(master_task, 63.678)
73  return master_task
74 
75 
76 if __name__ == '__main__':
77  rospy.init_node("example_task_routine")
78  # wait for simulated time to kick in as rospy.get_rostime() is 0 until first clock message received
79  while not rospy.is_shutdown() and rospy.get_rostime().secs == 0:
80  pass
81 
82 
83  # Perform my own actions
84  actual_action_duration = rospy.Duration(60)
85  if True:
86  action_server = TestTaskAction(expected_action_duration=actual_action_duration, expected_drive_duration=actual_action_duration)
87 
88 
89  # create a task we will copy later
90  task = create_master_task(actual_action_duration)
91  # task = create_wait_task(actual_action_duration)
92 
93  # get services to call into execution framework
94  add_tasks, set_execution_status = get_services()
95 
96 
97  # some useful times
98  localtz = tzlocal()
99  # the time the robot will be active
100  start = time(07,00, tzinfo=localtz)
101  end = time(20,00, tzinfo=localtz)
102  midday = time(12,00, tzinfo=localtz)
103 
104  morning = (start, midday)
105  afternoon = (midday, end)
106 
107  routine = task_routine.DailyRoutine(start, end)
108  # do this task every day
109  # routine.repeat_every_day(task)
110  # and every two hours during the day
111  # routine.repeat_every_hour(task, hours=2)
112  # once in the morning
113  # routine.repeat_every(task, *morning)
114  # and twice in the afternoon
115  # routine.repeat_every(task, *afternoon, times=2)
116 
117  routine.repeat_every_hour(task, times=10)
118 
119  # create the object which will talk to the scheduler
120  runner = task_routine.DailyRoutineRunner(start, end, add_tasks)
121  # pass the routine tasks on to the runner which handles the daily instantiation of actual tasks
122  runner.add_tasks(routine.get_routine_tasks())
123 
124  # # Set the task executor is running
125  set_execution_status(True)
126 
127  rospy.spin()
def create_wait_task(max_duration)
def create_master_task(max_duration)


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