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