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