task_routine_node.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import actionlib
5 from strands_executive_msgs.msg import Task
6 from strands_executive_msgs import task_utils
7 from task_executor.msg import *
8 from topological_navigation.msg import GotoNodeAction
9 from task_executor import task_routine
10 from datetime import *
11 from threading import Thread
12 import mongodb_store_msgs.srv as dc_srv
13 from mongodb_store_msgs.msg import StringPair
14 import mongodb_store.util as dc_util
15 from mongodb_store.message_store import MessageStoreProxy
16 from geometry_msgs.msg import Pose, Point, Quaternion
17 from dateutil.tz import tzlocal
18 
19 
20 
21 def dummy_task():
22  """
23  Create an example of a task which we'll copy for other tasks later.
24  This is a good example of creating a task with a variety of arguments.
25  """
26  # need message store to pass objects around
27  msg_store = MessageStoreProxy()
28 
29  # get the pose of a named object
30  pose_name = "my favourite pose"
31 
32  # get the pose if it's there
33  message, meta = msg_store.query_named(pose_name, Pose._type)
34  # if it's not there, add it in
35  if message == None:
36  message = Pose(Point(0, 1, 2), Quaternion(3, 4, 5, 6))
37  pose_id = msg_store.insert_named(pose_name, message)
38  else:
39  pose_id = meta["_id"]
40 
41  master_task = Task(action='test_task')
42  task_utils.add_string_argument(master_task, 'hello world')
43  task_utils.add_object_id_argument(master_task, pose_id, Pose)
44  task_utils.add_int_argument(master_task, 24)
45  task_utils.add_float_argument(master_task, 63.678)
46  return master_task
47 
48 
49 
50 if __name__ == '__main__':
51 
52  rospy.init_node("task_routine", log_level=rospy.INFO)
53 
54  # wait for simulated time to kick in as rospy.get_rostime() is 0 until first clock message received
55  while not rospy.is_shutdown() and rospy.get_rostime().secs == 0:
56  pass
57 
58  localtz = tzlocal()
59 
60  start = time(8,30, tzinfo=localtz)
61  ten = time(10,00, tzinfo=localtz)
62  midday = time(12,00, tzinfo=localtz)
63  end = time(17,00, tzinfo=localtz)
64  morning = (start, midday)
65  afternoon = (midday, end)
66 
67  task = dummy_task()
68 
69  routine = task_routine.DailyRoutine(start, end)
70  routine.repeat_every_hour(task, hours=2)
71 
72  # all these should except
73  # routine.add_tasks([task], midday, start)
74  # routine.add_tasks([task], start, start)
75  # task.max_duration = 60 * 60 * 12;
76  # routine.add_tasks([task], start, midday)
77 
78 
79  # routine = task_routine.DailyRoutineRunner(start, end)
80  # task.max_duration = rospy.Duration(timedelta(seconds=60).total_seconds());
81  # routine.add_tasks([([task, task], morning), ([task, task], afternoon)])
82 
83  rospy.spin()
84 


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