marathon_routine.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 
5 from strands_executive_msgs import task_utils
6 from strands_executive_msgs.msg import Task
7 from strands_navigation_msgs.msg import TopologicalMap
8 from mongodb_store_msgs.msg import StringList
9 from mongodb_store.message_store import MessageStoreProxy
10 
11 from task_executor.task_routine import delta_between
12 from routine_behaviours.patrol_routine import PatrolRoutine, create_patrol_task
13 
14 import random
15 
16 
17 def create_simple_follow_task(waypoint_name, duration=rospy.Duration(300)):
18  task = Task(start_node_id=waypoint_name, end_node_id=waypoint_name, action='simple_follow', max_duration=duration)
19  task_utils.add_int_argument(task, duration.secs)
20  return task
21 
22 def create_rgbd_record_task(waypoint_name, duration=rospy.Duration(30), camera='head_xtion', with_depth=True, with_rgb=True):
23  task = Task(start_node_id=waypoint_name, end_node_id=waypoint_name, action='record_camera', max_duration=duration)
24  task_utils.add_string_argument(task, camera)
25  task_utils.add_bool_argument(task, with_depth)
26  task_utils.add_bool_argument(task, with_rgb)
27  return task
28 
29 def create_3d_scan_task(waypoint_name):
30  task = Task(start_node_id=waypoint_name, end_node_id=waypoint_name, action='ptu_pan_tilt_metric_map', max_duration=rospy.Duration(240))
31  task_utils.add_int_argument(task, '-160')
32  task_utils.add_int_argument(task, '20')
33  task_utils.add_int_argument(task, '160')
34  task_utils.add_int_argument(task, '-25')
35  task_utils.add_int_argument(task, '25')
36  task_utils.add_int_argument(task, '25')
37  return task
38 
39 def create_tweet_task(waypoint_name, tweet, image_topic):
40  task = Task(start_node_id=waypoint_name, end_node_id=waypoint_name, action='strands_image_tweets', max_duration=rospy.Duration(60))
41 
42  task_utils.add_string_argument(task, tweet)
43  task_utils.add_bool_argument(task, False)
44  task_utils.add_string_argument(task, image_topic)
45  return task
46 
47 
48 def create_mongodb_store_task(db, to_replicate, delete_after_move=True):
49  task = Task()
50  # no idea, let's say 2 hours for now -- this action server can't be preempted though, so this is cheating
51  task.max_duration = rospy.Duration(60 * 60 * 2)
52  task.action = 'move_mongodb_entries'
53 
54  # replicate from this db
55  task_utils.add_string_argument(task, db)
56 
57  # add arg for collectionst o replication
58  collections = StringList(to_replicate)
59  msg_store = MessageStoreProxy()
60  object_id = msg_store.insert(collections)
61  task_utils.add_object_id_argument(task, object_id, StringList)
62 
63  # move stuff over 24 hours old
64  task_utils.add_duration_argument(task, rospy.Duration(60 * 60 *24))
65 
66  # and delete afterwards
67  task_utils.add_bool_argument(task, delete_after_move)
68  return task
69 
70 
71 
73  """ Creates a routine that mixes specific tasks with patrolling nodes."""
74 
75  def __init__(self, daily_start, daily_end, tour_duration_estimate=None, idle_duration=rospy.Duration(5), charging_point = 'ChargingPoint'):
76  super(MarathonRoutine, self).__init__(daily_start=daily_start, daily_end=daily_end, tour_duration_estimate=tour_duration_estimate, idle_duration=idle_duration, charging_point=charging_point)
77 
78  def create_3d_scan_routine(self, waypoints=None, daily_start=None, daily_end=None, repeat_delta=None):
79  """
80  If waypoints now supplied, use all waypoints.
81 
82  """
83  if waypoints is None:
84  waypoints = self.get_nodes()
85  tasks = [ create_3d_scan_task(n) for n in waypoints ]
86  self.create_task_routine(tasks=tasks, daily_start=daily_start, daily_end=daily_end, repeat_delta=repeat_delta)
87 
88 
89  def create_simple_follow_routine(self, waypoints=None, duration=rospy.Duration(300), daily_start=None, daily_end=None, repeat_delta=None):
90  if waypoints is None:
91  waypoints = self.get_nodes()
92  tasks = [ create_simple_follow_task(n, duration=duration) for n in waypoints ]
93  self.create_task_routine(tasks=tasks, daily_start=daily_start, daily_end=daily_end, repeat_delta=repeat_delta)
94 
95  def create_rgbd_record_routine(self, waypoints=None, duration=rospy.Duration(30), camera='head_xtion', with_depth=True, with_rgb=True, daily_start=None, daily_end=None, repeat_delta=None):
96  if waypoints is None:
97  waypoints = self.get_nodes()
98  tasks = [ create_rgbd_record_task(n, duration=duration, camera=camera, with_depth=with_depth, with_rgb=with_rgb) for n in waypoints ]
99  self.create_task_routine(tasks=tasks, daily_start=daily_start, daily_end=daily_end, repeat_delta=repeat_delta)
100 
101 
102  def create_tweet_routine(self, twitter_waypoints, img_topic='/head_xtion/rgb/image_color', daily_start=None, daily_end=None, repeat_delta=None):
103  """
104  [[waypoint, tweet][waypoint, tweet]]
105  """
106  tasks = [ create_tweet_task(w, t, img_topic) for [w, t] in twitter_waypoints ]
107  self.create_task_routine(tasks=tasks, daily_start=daily_start, daily_end=daily_end, repeat_delta=repeat_delta)
108 
109  def message_store_entries_to_replicate(self, collections, db='message_store', delete_after_move=True):
110  # this is how you add something for when the robot is charging, but these tasks aren't allowed a location
111  mongodb_task = create_mongodb_store_task(db, collections, delete_after_move)
112  self.add_night_task(mongodb_task)
113 
114 
115  def on_idle(self):
116  # generate a random waypoint visit on idle
117  PatrolRoutine.on_idle(self)
118  # pass
def create_tweet_task(waypoint_name, tweet, image_topic)


routine_behaviours
Author(s): Nick Hawes
autogenerated on Tue Mar 17 2015 21:43:31