robocup_knowledge
rgo2019/common.py
Go to the documentation of this file.
1 # COMMON KNOWLEDGE FILE RGO2019
2 
3 from __future__ import print_function
4 
5 # Names
6 
7 female_names = ["sophia","isabella","emma","olivia","ava","emily","abigail","madison","mia","chloe"]
8 male_names = ["james","john","robert","michael","william","david","richard","charles","joseph","thomas"]
9 
10 names = female_names + male_names
11 
12 # This dict holds all locations
13 locations = [
14  {'name': 'bed', 'room': 'bedroom', 'category': 'utility', 'manipulation': 'no'},
15  {'name': 'desk', 'room': 'bedroom', 'category': 'table', 'manipulation': 'yes'},
16  {'name': 'side_table', 'room': 'bedroom', 'category': 'table', 'manipulation': 'yes'},
17 
18  {'name': 'kitchen_table', 'room': 'kitchen', 'category': 'table', 'manipulation': 'yes'},
19  {'name': 'kitchen_cabinet', 'room': 'kitchen', 'category': 'shelf', 'manipulation': 'yes'},
20  {'name': 'dishwasher', 'room': 'kitchen', 'category': 'utility', 'manipulation': 'yes'},
21  {'name': 'cabinet', 'room': 'kitchen', 'category': 'shelf', 'manipulation': 'yes'},
22  {'name': 'white_drawer', 'room': 'kitchen', 'category': 'shelf', 'manipulation': 'yes'},
23  {'name': 'trash_can', 'room': 'kitchen', 'category': 'utility', 'manipulation': 'yes'},
24 
25  {'name': 'tv_table', 'room': 'living_room', 'category': 'table', 'manipulation': 'yes'},
26  {'name': 'tv', 'room': 'living_room', 'category': 'utility', 'manipulation': 'no'},
27  {'name': 'bookcase', 'room': 'living_room', 'category': 'shelf', 'manipulation': 'yes'},
28  {'name': 'couch', 'room': 'living_room', 'category': 'utility', 'manipulation': 'no'},
29  {'name': 'left_armchair', 'room': 'living_room', 'category': 'utility', 'manipulation': 'no'},
30  {'name': 'right_armchair', 'room': 'living_room', 'category': 'utility', 'manipulation': 'no'},
31  {'name': 'coffee_table', 'room': 'living_room', 'category': 'table', 'manipulation': 'yes'},
32  {'name': 'sideboard', 'room': 'living_room', 'category': 'table', 'manipulation': 'yes'},
33  {'name': 'high_table', 'room': 'living_room', 'category': 'table', 'manipulation': 'yes'},
34  {'name': 'trash_bin', 'room': 'living_room', 'category': 'utility', 'manipulation': 'yes'},
35  {'name': 'coathanger', 'room': 'living_room', 'category': 'utility', 'manipulation': 'no'},
36 
37 
38  {'name': 'bar_table', 'room': 'bar', 'category': 'table', 'manipulation': 'yes'},
39  {'name': 'cupboard', 'room': 'bar', 'category': 'shelf', 'manipulation': 'yes'},
40  {'name': 'sofa', 'room': 'bar', 'category': 'utility', 'manipulation': 'no'}
41 ]
42 
43 location_rooms = list(set([ o["room"] for o in locations ]))
44 location_categories = list(set([ o["category"] for o in locations ]))
45 location_names = list(set([ o["name"] for o in locations ]))
46 manipulation_locations = list(set([ o["name"] for o in locations if o["manipulation"] == "yes" ]))
47 
48 rooms = location_rooms + ['hallway']
49 
50 objects = [
51  {'category': 'other', 'name': 'trashbag', 'color': 'black', 'volume': 100, 'weight': 22},
52 
53  {'category': 'kitchen_stuff', 'name': 'bowl', 'color': 'green', 'volume': 458, 'weight': 65},
54  {'category': 'kitchen_stuff', 'name': 'cup', 'color': 'yellow', 'volume': 300, 'weight': 50},
55  {'category': 'kitchen_stuff', 'name': 'fork', 'color': 'orange', 'volume': 22, 'weight': 10},
56  {'category': 'kitchen_stuff', 'name': 'knife', 'color': 'green', 'volume': 22, 'weight': 10},
57  {'category': 'kitchen_stuff', 'name': 'plate', 'color': 'blue', 'volume': 672, 'weight': 70},
58  {'category': 'kitchen_stuff', 'name': 'spoon', 'color': 'blue', 'volume': 23, 'weight': 10},
59 
60  {'category': 'drink', 'name': 'apple_juice', 'color': 'brown', 'volume': 216, 'weight': 200},
61  {'category': 'drink', 'name': 'big_coke', 'color': 'brownish', 'volume': 270, 'weight': 222},
62  {'category': 'drink', 'name': 'big_lemon_juice', 'color': 'transparent', 'volume': 270, 'weight': 222},
63  {'category': 'drink', 'name': 'big_water', 'color': 'transparent', 'volume': 270, 'weight': 222},
64  {'category': 'drink', 'name': 'iso_drink', 'color': 'blue', 'volume': 404, 'weight': 325},
65  {'category': 'drink', 'name': 'milk', 'color': 'blue', 'volume': 216, 'weight': 200},
66  {'category': 'drink', 'name': 'orange_juice', 'color': 'orange', 'volume': 216, 'weight': 200},
67  {'category': 'drink', 'name': 'red_spritzer', 'color': 'red', 'volume': 270, 'weight': 222},
68  {'category': 'drink', 'name': 'sparkling_water', 'color': 'transparent', 'volume': 270, 'weight': 222},
69 
70  {'category': 'fruit', 'name': 'lemon', 'color': 'yellow', 'volume': 360, 'weight': 85},
71  {'category': 'fruit', 'name': 'orange', 'color': 'orange', 'volume': 380, 'weight': 140},
72 
73  {'category': 'care', 'name': 'shower_gel', 'color': 'blue', 'volume': 336, 'weight': 21},
74  {'category': 'care', 'name': 'soap', 'color': 'ivory', 'volume': 297, 'weight': 85},
75  {'category': 'care', 'name': 'toothpaste', 'color': 'whitegreen', 'volume': 223, 'weight': 113},
76 
77  {'category': 'food', 'name': 'bouillon', 'color': 'orange', 'volume': 336, 'weight': 21},
78  {'category': 'food', 'name': 'corn', 'color': 'yellow', 'volume': 223, 'weight': 113},
79  {'category': 'food', 'name': 'noodles', 'color': 'yellowish', 'volume': 297, 'weight': 85},
80  {'category': 'food', 'name': 'pepper', 'color': 'blue', 'volume': 336, 'weight': 21},
81  {'category': 'food', 'name': 'salt', 'color': 'whiteorange', 'volume': 297, 'weight': 85},
82  {'category': 'food', 'name': 'sauerkraut', 'color': 'whitegreen', 'volume': 223, 'weight': 113},
83  {'category': 'food', 'name': 'seasoning_mix', 'color': 'orange', 'volume': 297, 'weight': 85},
84  {'category': 'food', 'name': 'tomatoes', 'color': 'blue', 'volume': 223, 'weight': 113},
85 
86  {'category': 'container', 'name': 'basket', 'color': 'white', 'volume': 3487, 'weight': 43},
87  {'category': 'container', 'name': 'tray', 'color': 'gray', 'volume': 4508, 'weight': 120},
88 
89  {'category': 'cleaning_stuff', 'name': 'cloth', 'color': 'yellow', 'volume': 315, 'weight': 37},
90  {'category': 'cleaning_stuff', 'name': 'dishwasher_tab', 'color': 'yellowish', 'volume': 100, 'weight': 22},
91 
92  {'category': 'snack', 'name': 'cereal_bar_chocolate', 'color': 'blue', 'volume': 243, 'weight': 28},
93  {'category': 'snack', 'name': 'cereal_bar_chocolate_banana', 'color': 'yellow', 'volume': 4080, 'weight': 200},
94  {'category': 'snack', 'name': 'cracker', 'color': 'redwhite', 'volume': 1125, 'weight': 156},
95  {'category': 'kitchen_stuff', 'name': 'fruit_bar_apple', 'color': 'green', 'volume': 458, 'weight': 65},
96  {'category': 'kitchen_stuff', 'name': 'fruit_bar_forest_fruit', 'color': 'blue', 'volume': 300, 'weight': 50},
97  {'category': 'kitchen_stuff', 'name': 'get_it', 'color': 'orange', 'volume': 22, 'weight': 10},
98  {'category': 'kitchen_stuff', 'name': 'nut_fruit_mix', 'color': 'redwhite', 'volume': 22, 'weight': 10},
99  {'category': 'kitchen_stuff', 'name': 'peanut_bits', 'color': 'red', 'volume': 672, 'weight': 70}
100 ]
101 
102 object_names = list(set([ o["name"] for o in objects ]))
103 object_categories = list(set([ o["category"] for o in objects ]))
104 object_color = list(set([ o["color"] for o in objects ]))
105 object_size = list(set([ o["volume"] for o in objects ]))
106 object_weight = list(set([ o["weight"] for o in objects ]))
107 # object_groups = list(set([ o["group"] for o in objects ]))
108 # object_known_objects = list(set([ o["name"] for o in objects ]))
109 
110 category_locations = {
111  "cleaning_stuff": {"dishwasher": "on_top_of"},
112  "snack": {"coffee_table": "on_top_of"},
113  "drink": {"kitchen_table": "on_top_of"},
114  "food": {"bookcase": "shelf2"},
115  "care": {"side_table": "on_top_of"},
116  "container": {"end_table": "on_top_of"},
117  "fruit": {"bar_table": "on_top_of"},
118  "kitchen_stuff": {"kitchen_cabinet": "on_top_of"},
119 }
120 
121 inspect_areas = {
122  "bookcase": ["shelf1", "shelf2"]
123 }
124 
125 inspect_positions = {
126 }
127 
128 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
129 
130 most_probable_location_in_room_map = {
131  'bedroom': 'side_table', # educated guess
132  'kitchen': 'kitchen_cabinet', # educated guess
133  'bar': 'bar_table', # educated guess
134  'living_room': 'bookcase' # educated guess
135 }
136 
137 def get_location_from_room(room_id):
138  if room_id in most_probable_location_in_room_map:
139  return most_probable_location_in_room_map[room_id]
140  return None
141 
142 
143 drink_names = [obj['name'] for obj in objects if obj['category'] == 'drink']
144 drink_spec = "T['drink': O] -> OPTIONS[O]\n\n"
145 for dn in drink_names:
146  drink_spec += "OPTIONS['{drink}'] -> {drink}\n".format(drink=dn)
147 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
148 
149 ''' colors from printing on screen '''
150 class bcolors:
151  HEADER = '\033[95m'
152  OKBLUE = '\033[94m'
153  OKGREEN = '\033[92m'
154  WARNING = '\033[93m'
155  FAIL = '\033[91m'
156  ENDC = '\033[0m'
157  BOLD = '\033[1m'
158  UNDERLINE = '\033[4m'
159 
160 
161 '''
162 General function for printing shortcuts
163 name: name of the program that instantiates make_prints
164 sentence: sentence to be displayed
165 
166 Ex: "[<EXECUTIVE NAME>] <SENTENCE TO BE DISPLAYED>"
167 '''
168 
169 
170 def make_prints(name):
171  prefix = bcolors.HEADER + name + bcolors.ENDC
172 
173  def printOk(sentence):
174  print(prefix + bcolors.OKBLUE + sentence + bcolors.ENDC)
175 
176  def printError(sentence):
177  print(prefix + bcolors.FAIL + sentence + bcolors.ENDC)
178 
179  def printWarning(sentence):
180  print(prefix + bcolors.WARNING + sentence + bcolors.ENDC)
181 
182  return printOk, printError, printWarning
183 
184 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
185 
186 def is_location(location):
187  for loc in locations:
188  if loc["name"] == location:
189  return True
190  return False
191 
192 
193 def get_room(location):
194  for loc in locations:
195  if loc["name"] == location:
196  return loc["room"]
197  return None
198 
199 
200 def is_room(entity_id):
201  return (entity_id in rooms)
202 
203 
204 def get_inspect_areas(location):
205  if location in inspect_areas:
206  return inspect_areas[location]
207  else:
208  return ["on_top_of"]
209 
210 
211 def get_inspect_position(location, area=""):
212  if location in inspect_positions and area in inspect_positions[location]:
213  return inspect_positions[location][area]
214  else:
215  return "in_front_of"
216 
217 
218 def is_pick_location(location):
219  for loc in locations:
220  if loc["name"] == location and loc["manipulation"] == "yes":
221  return True
222  return False
223 
224 
225 def is_place_location(location):
226  for loc in locations:
227  if loc["name"] == location and (loc["manipulation"] == "yes" or loc["manipulation"] == "only_putting"):
228  return True
229  return False
230 
231 
232 def get_locations(room=None, pick_location=None, place_location=None):
233  return [loc["name"] for loc in locations
234  if (room == None or loc["room"] == room) and \
235  (pick_location == None or pick_location == is_pick_location(loc["name"])) and \
236  (place_location == None or place_location == is_place_location(loc["name"]))]
237 
238 
239 def get_objects(category=None):
240  return [obj["name"] for obj in objects
241  if category == None or category == obj["category"]]
242 
243 
244 def get_object_category(obj):
245  for o in objects:
246  if o["name"] == obj:
247  return o["category"]
248  return None
249 
250 def get_object_color(obj):
251  for o in objects:
252  if o["name"] == obj:
253  return o["color"]
254  return None
255 
256 def get_object_size(obj):
257  for o in objects:
258  if o["name"] == obj:
259  return o["volume"]
260  return None
261 
262 def get_object_weight(obj):
263  for o in objects:
264  if o["name"] == obj:
265  return o["weight"]
266  return None
267 
268 # Returns (location, area_name)
269 def get_object_category_location(obj_cat):
270  location, area_name = next(iter(category_locations[obj_cat].items()))
271  return location, area_name
272 
273 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
274 
275 
276 if __name__ == "__main__":
277  print("\n-----------------------------------------------------------------------------")
278  for obj in get_objects():
279  cat = get_object_category(obj)
280  (location, area_name) = get_object_category_location(cat)
281  print("object '{}'".format(obj))
282  print(" category: '{}'".format(cat))
283  print(" found '{} {}'".format(area_name, location))
284 
285  print("\n-----------------------------------------------------------------------------")
286  for loc in get_locations():
287  print("location '{}', room: '{}'".format(loc, get_room(loc)))
288 
289  print("\n-----------------------------------------------------------------------------")
290  print("Pick locations:")
291  for loc in get_locations(pick_location=True):
292  print(" {}".format(loc))
293 
294  print("\n-----------------------------------------------------------------------------")
295  print("Place locations:")
296  for loc in get_locations(place_location=True):
297  print(" {}".format(loc))
298 
299  print("\n-----------------------------------------------------------------------------")
300  print("None-manipulation locations:")
301  for loc in get_locations(pick_location=False, place_location=False):
302  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
challenge_person_recognition.printWarning
def printWarning(sentence)
Definition: reo2016/challenge_person_recognition.py:32