robocup_knowledge
robotics_testlabs/common.py
Go to the documentation of this file.
1 # COMMON KNOWLEDGE FILE ROBOTICS TESTLABS
2 from __future__ import print_function
3 
4 female_names = ["anna", "beth", "carmen", "jennifer", "jessica", "kimberly", "kristina", "laura", "mary", "sarah"]
5 male_names = ["alfred", "charles", "daniel", "james", "john", "luis", "paul", "richard", "robert", "steve"]
6 
7 names = female_names + male_names
8 
9 # This dict holds all locations
10 locations = [
11  {'name': 'couch_table', 'room': 'livingroom', 'category': 'table', 'manipulation': 'yes'},
12  {'name': 'dinner_table', 'room': 'livingroom', 'category': 'table', 'manipulation': 'yes'},
13  {'name': 'bookcase', 'room': 'livingroom', 'category': 'shelf', 'manipulation': 'yes'},
14  {'name': 'panda_table', 'room': 'livingroom', 'category': 'table', 'manipulation': 'yes'},
15 
16  {'name': 'cabinet', 'room': 'kitchen', 'category': 'shelf', 'manipulation': 'yes'},
17  {'name': 'trashbin', 'room': 'kitchen', 'category': 'utility', 'manipulation': 'no'},
18  {'name': 'couch', 'room': 'kitchen', 'category': 'utility', 'manipulation': 'no'},
19 
20  {'name': 'workbench', 'room': 'workshop', 'category': 'table', 'manipulation': 'yes'},
21 
22  {'name': 'hallway_table', 'room': 'hallway', 'category': 'table', 'manipulation': 'yes'},
23  {'name': 'bar', 'room': 'hallway', 'category': 'table', 'manipulation': 'yes'},
24  {'name': 'paperbin', 'room': 'hallway', 'category': 'utility', 'manipulation': 'no'}
25 ]
26 
27 location_rooms = list(set([ o["room"] for o in locations ]))
28 location_categories = list(set([ o["category"] for o in locations ]))
29 location_names = list(set([ o["name"] for o in locations ]))
30 manipulation_locations = list(set([ o["name"] for o in locations if o["manipulation"] == "yes" ]))
31 
32 rooms = location_rooms + ["workshop"]
33 
34 objects = [
35  {'category': 'food', 'name': 'apple', 'color': 'green', 'volume': 301, 'weight': 100}, # fruit
36  {'category': 'food', 'name': 'banana', 'color': 'yellow', 'volume': 320, 'weight': 100}, # fruit
37  {'category': 'food', 'name': 'mango', 'color': 'red', 'volume': 254, 'weight': 100}, # fruit
38  {'category': 'food', 'name': 'orange', 'color': 'orange', 'volume': 352, 'weight': 100}, # fruit
39  {'category': 'food', 'name': 'cereal', 'color': 'green', 'volume': 1485, 'weight': 100},
40  {'category': 'food', 'name': 'corn', 'color': 'yellow', 'volume': 240, 'weight': 100},
41  {'category': 'food', 'name': 'crackers', 'color': 'blueish', 'volume': 300, 'weight': 100},
42  {'category': 'food', 'name': 'peas', 'color': 'green', 'volume': 239, 'weight': 100},
43  {'category': 'food', 'name': 'pepper', 'color': 'black', 'volume': 110, 'weight': 100},
44  {'category': 'food', 'name': 'salt', 'color': 'white', 'volume': 110, 'weight': 100},
45  {'category': 'container', 'name': 'basket', 'color': 'green', 'volume': 3487, 'weight': 100},
46  {'category': 'container', 'name': 'bowl', 'color': 'blue', 'volume': 617, 'weight': 100},
47  {'category': 'container', 'name': 'cup', 'color': 'orangish', 'volume': 427, 'weight': 100},
48  {'category': 'container', 'name': 'plate', 'color': 'grey', 'volume': 147, 'weight': 100},
49  {'category': 'drink', 'name': 'beer', 'color': 'brown', 'volume': 388, 'weight': 100},
50  {'category': 'drink', 'name': 'bifrutas', 'color': 'blue', 'volume': 378, 'weight': 100},
51  {'category': 'drink', 'name': 'coke', 'color': 'red', 'volume': 376, 'weight': 335},
52  {'category': 'drink', 'name': 'fanta', 'color': 'orange', 'volume': 376, 'weight': 335},
53  {'category': 'drink', 'name': 'ice_tea', 'color': 'yellow', 'volume': 376, 'weight': 335},
54  {'category': 'drink', 'name': 'tea', 'color': 'green', 'volume': 877, 'weight': 100},
55  {'category': 'drink', 'name': 'water', 'color': 'transparent', 'volume': 400, 'weight': 100},
56  {'category': 'snack', 'name': 'cookies', 'color': 'brownish', 'volume': 442, 'weight': 100},
57  {'category': 'snack', 'name': 'mentos', 'color': 'blue', 'volume': 235, 'weight': 100},
58  {'category': 'snack', 'name': 'pringles', 'color': 'orange', 'volume': 1125, 'weight': 100},
59  {'category': 'cleaning_stuff', 'name': 'brush', 'color': 'brown', 'volume': 315, 'weight': 100},
60  {'category': 'cleaning_stuff', 'name': 'cloth', 'color': 'yellow', 'volume': 161, 'weight': 100},
61  {'category': 'cleaning_stuff', 'name': 'deodorant', 'color': 'pink', 'volume': 314, 'weight': 100},
62  {'category': 'cleaning_stuff', 'name': 'hair_gel', 'color': 'transparent', 'volume': 238, 'weight': 100},
63  {'category': 'cleaning_stuff', 'name': 'hairspray', 'color': 'blue', 'volume': 490, 'weight': 100},
64  {'category': 'cleaning_stuff', 'name': 'sponge', 'color': 'yellow', 'volume': 234, 'weight': 100},
65  {'category': 'cleaning_stuff', 'name': 'toothpaste', 'color': 'blue', 'volume': 106, 'weight': 100},
66  {'category': 'cleaning_stuff', 'name': 'towel', 'color': 'pink', 'volume': 243, 'weight': 100},
67  {'category': 'cutlery', 'name': 'fork', 'color': 'brownish', 'volume': 4, 'weight': 100},
68  {'category': 'cutlery', 'name': 'spoon', 'color': 'brownish', 'volume': 4, 'weight': 100},
69  {'category': 'cutlery', 'name': 'knife', 'color': 'brownish', 'volume': 5, 'weight': 100},
70  {'category': 'cutlery', 'name': 'chopsticks', 'color': 'brownish', 'volume': 20, 'weight': 100}
71 ]
72 
73 object_names = list(set([ o["name"] for o in objects ]))
74 object_categories = list(set([ o["category"] for o in objects ]))
75 object_color = list(set([ o["color"] for o in objects ]))
76 object_size = list(set([ o["volume"] for o in objects ]))
77 object_weight = list(set([ o["weight"] for o in objects ]))
78 # object_groups = list(set([ o["group"] for o in objects ]))
79 # object_known_objects = list(set([ o["name"] for o in objects ]))
80 
81 category_locations = {
82  "food": {"bookcase": "on_top_of"},
83  "snack": {"bookcase": "on_top_of"},
84  "container": {"flight_case": "in"},
85  "drink": {"dinner_table": "on_top_of"},
86  "cleaning_stuff": {"cabinet": "on_top_of"},
87  "cutlery": {"bar": "on_top_of"}
88 }
89 
90 inspect_areas = {
91  "bookcase": ["shelf1", "shelf2", "shelf3", "shelf4", "shelf5"]
92 }
93 
94 inspect_positions = {
95 }
96 
97 default_target_radius = 0.2
98 
99 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100 
101 most_probable_location_in_room_map = {
102  'livingroom': 'dinner_table',
103  'bedroom': 'nightstand',
104  'workshop': 'workbench',
105  'kitchen': 'cabinet',
106  'hallway': 'hallway_table'
107 }
108 
109 
110 def get_location_from_room(room_id):
111  if room_id in most_probable_location_in_room_map:
112  return most_probable_location_in_room_map[room_id]
113  return None
114 
115 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
116 
117 def object_names_of_category(category):
118  return [obj['name'] for obj in objects if obj['category'] == category]
119 
120 drink_names = object_names_of_category('drink')
121 drink_spec = "T['drink': O] -> OPTIONS[O]\n\n"
122 for dn in drink_names:
123  drink_spec += "OPTIONS['{drink}'] -> {drink}\n".format(drink=dn)
124 
125 ''' colors from printing on screen '''
126 class bcolors:
127  HEADER = '\033[95m'
128  OKBLUE = '\033[94m'
129  OKGREEN = '\033[92m'
130  WARNING = '\033[93m'
131  FAIL = '\033[91m'
132  ENDC = '\033[0m'
133  BOLD = '\033[1m'
134  UNDERLINE = '\033[4m'
135 
136 
137 '''
138 General function for printing shortcuts
139 name: name of the program that instantiates make_prints
140 sentence: sentence to be displayed
141 
142 Ex: "[<EXECUTIVE NAME>] <SENTENCE TO BE DISPLAYED>"
143 '''
144 
145 
146 def make_prints(name):
147 
148  prefix = bcolors.HEADER + name + bcolors.ENDC
149 
150  def printOk(sentence):
151  print(prefix + bcolors.OKBLUE + sentence + bcolors.ENDC)
152 
153  def printError(sentence):
154  print(prefix + bcolors.FAIL + sentence + bcolors.ENDC)
155 
156  def printWarning(sentence):
157  print(prefix + bcolors.WARNING + sentence + bcolors.ENDC)
158 
159  return printOk, printError, printWarning
160 
161 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
162 
163 def is_location(location):
164  for loc in locations:
165  if loc["name"] == location:
166  return True
167  return False
168 
169 
170 def get_room(location):
171  for loc in locations:
172  if loc["name"] == location:
173  return loc["room"]
174  return None
175 
176 
177 def is_room(entity_id):
178  return (entity_id in rooms)
179 
180 
181 def get_inspect_areas(location):
182  if location in inspect_areas:
183  return inspect_areas[location]
184  else:
185  return ["on_top_of"]
186 
187 
188 def get_inspect_position(location, area=""):
189  if location in inspect_positions and area in inspect_positions[location]:
190  return inspect_positions[location][area]
191  else:
192  return "in_front_of"
193 
194 
195 def is_pick_location(location):
196  for loc in locations:
197  if loc["name"] == location and loc["manipulation"] == "yes":
198  return True
199  return False
200 
201 
202 def is_place_location(location):
203  for loc in locations:
204  if loc["name"] == location and (loc["manipulation"] == "yes" or loc["manipulation"] == "only_putting"):
205  return True
206  return False
207 
208 
209 def get_locations(room=None, pick_location=None, place_location=None):
210  return [loc["name"] for loc in locations
211  if (room == None or loc["room"] == room) and \
212  (pick_location == None or pick_location == is_pick_location(loc["name"])) and \
213  (place_location == None or place_location == is_place_location(loc["name"]))]
214 
215 def is_known_object(obj):
216  for o in objects:
217  if o["name"] == obj:
218  return True
219  return False
220 
221 def get_objects(category=None):
222  return [obj["name"] for obj in objects
223  if category == None or category == obj["category"]]
224 
225 
226 def get_object_category(obj):
227  for o in objects:
228  if o["name"] == obj:
229  return o["category"]
230  return None
231 
232 def get_object_color(obj):
233  for o in objects:
234  if o["name"] == obj:
235  return o["color"]
236  return None
237 
238 def get_object_size(obj):
239  for o in objects:
240  if o["name"] == obj:
241  return o["volume"]
242  return None
243 
244 def get_object_weight(obj):
245  for o in objects:
246  if o["name"] == obj:
247  return o["weight"]
248  return None
249 
250 # Returns (location, area_name)
251 def get_object_category_location(obj_cat):
252  location, area_name = next(iter(category_locations[obj_cat].items()))
253  return location, area_name
254 
255 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
256 
257 
258 if __name__ == "__main__":
259  print("\n-----------------------------------------------------------------------------")
260  for obj in get_objects():
261  cat = get_object_category(obj)
262  (location, area_name) = get_object_category_location(cat)
263  print("object '{}'".format(obj))
264  print(" category: '{}'".format(cat))
265  print(" found '{} {}'".format(area_name, location))
266 
267  print("\n-----------------------------------------------------------------------------")
268  for loc in get_locations():
269  print("location '{}', room: '{}'".format(loc, get_room(loc)))
270 
271  print("\n-----------------------------------------------------------------------------")
272  print("Pick locations:")
273  for loc in get_locations(pick_location=True):
274  print(" {}".format(loc))
275 
276  print("\n-----------------------------------------------------------------------------")
277  print("Place locations:")
278  for loc in get_locations(place_location=True):
279  print(" {}".format(loc))
280 
281  print("\n-----------------------------------------------------------------------------")
282  print("None-manipulation locations:")
283  for loc in get_locations(pick_location=False, place_location=False):
284  print(" {}".format(loc))
challenge_person_recognition.printOk
def printOk(sentence)
Definition: reo2016/challenge_person_recognition.py:26
common.get_inspect_position
def get_inspect_position(location, area="")
Definition: demo/common.py:103
challenge_person_recognition.printError
def printError(sentence)
Definition: reo2016/challenge_person_recognition.py:29
common.is_pick_location
def is_pick_location(location)
Definition: demo/common.py:110
common.get_location_from_room
def get_location_from_room(room_id)
Definition: impuls/common.py:106
common.get_object_weight
def get_object_weight(obj)
Definition: impuls/common.py:240
common.get_room
def get_room(location)
Definition: demo/common.py:87
common.get_object_category_location
def get_object_category_location(obj_cat)
Definition: demo/common.py:143
common.get_inspect_areas
def get_inspect_areas(location)
Definition: demo/common.py:96
common.get_object_size
def get_object_size(obj)
Definition: impuls/common.py:234
common.is_place_location
def is_place_location(location)
Definition: demo/common.py:117
common.is_room
def is_room(entity_id)
Definition: impuls/common.py:173
common.get_objects
def get_objects(category=None)
Definition: demo/common.py:131
common.is_location
def is_location(location)
Definition: demo/common.py:80
common.make_prints
def make_prints(name)
Definition: demo/common.py:62
common.get_object_color
def get_object_color(obj)
Definition: impuls/common.py:228
common.get_object_category
def get_object_category(obj)
Definition: demo/common.py:136
common.get_locations
def get_locations(room=None, pick_location=None, place_location=None)
Definition: demo/common.py:124
common.is_known_object
def is_known_object(obj)
Definition: impuls/common.py:211
common.object_names_of_category
def object_names_of_category(category)
Definition: impuls/common.py:112
challenge_person_recognition.printWarning
def printWarning(sentence)
Definition: reo2016/challenge_person_recognition.py:32