robocup_knowledge
rwc2018/common.py
Go to the documentation of this file.
1 # COMMON KNOWLEDGE FILE RWC2018
2 
3 from __future__ import print_function
4 
5 female_names = ["alex", "charlie", "elizabeth", "francis", "jennifer", "linda", "mary", "patricia", "robin", "skyler"]
6 male_names = ["alex", "charlie", "francis", "james", "john", "michael", "robert", "robin", "skyler", "william"]
7 
8 names = female_names + male_names
9 
10 # This dict holds all locations
11 locations = [
12  {'name': 'side_table', 'room': 'bedroom', 'category': 'table', 'manipulation': 'yes'},
13  {'name': 'bed', 'room': 'bedroom', 'category': 'utility', 'manipulation': 'no'},
14  {'name': 'desk', 'room': 'bedroom', 'category': 'table', 'manipulation': 'yes'},
15 
16  {'name': 'cupboard', 'room': 'kitchen', 'category': 'shelf', 'manipulation': 'yes'},
17  {'name': 'storage_table', 'room': 'kitchen', 'category': 'table', 'manipulation': 'yes'},
18  {'name': 'sink', 'room': 'kitchen', 'category': 'utility', 'manipulation': 'no'},
19  {'name': 'dishwasher', 'room': 'kitchen', 'category': 'utility', 'manipulation': 'no'},
20  {'name': 'counter', 'room': 'kitchen', 'category': 'shelf', 'manipulation': 'yes'},
21 
22  {'name': 'dining_table', 'room': 'dining_room', 'category': 'table', 'manipulation': 'yes'},
23 
24  {'name': 'end_table', 'room': 'living_room', 'category': 'table', 'manipulation': 'yes'},
25  {'name': 'couch', 'room': 'living_room', 'category': 'utility', 'manipulation': 'no'},
26  {'name': 'bookcase', 'room': 'living_room', 'category': 'shelf', 'manipulation': 'yes'},
27  {'name': 'door', 'room': 'corridor', 'category': 'utility', 'manipulation': 'no'},
28  {'name': 'gpsr_entrance', 'room': 'corridor', 'category': 'utility', 'manipulation': 'no'}
29 ]
30 
31 location_rooms = list(set([ o["room"] for o in locations ]))
32 location_categories = list(set([ o["category"] for o in locations ]))
33 location_names = list(set([ o["name"] for o in locations ]))
34 manipulation_locations = list(set([ o["name"] for o in locations if o["manipulation"] == "yes" ]))
35 
36 rooms = location_rooms + ['corridor']
37 
38 objects = [
39  {'category': 'cleaning_stuff', 'name': 'cloth', 'color': 'purple', 'volume': 315, 'weight': 37},
40  {'category': 'cleaning_stuff', 'name': 'scrubby', 'color': 'yellowish', 'volume': 100, 'weight': 22},
41  {'category': 'cleaning_stuff', 'name': 'sponge', 'color': 'blue', 'volume': 247, 'weight': 15},
42 
43  {'category': 'container', 'name': 'basket', 'color': 'beige', 'volume': 3487, 'weight': 43},
44  {'category': 'container', 'name': 'tray', 'color': 'white', 'volume': 4508, 'weight': 120},
45 
46  {'category': 'cutlery', 'name': 'fork', 'color': 'green', 'volume': 22, 'weight': 10},
47  {'category': 'cutlery', 'name': 'knife', 'color': 'green', 'volume': 22, 'weight': 10},
48  {'category': 'cutlery', 'name': 'spoon', 'color': 'green', 'volume': 23, 'weight': 10},
49 
50  {'category': 'drink', 'name': 'chocolate_drink', 'color': 'brownish', 'volume': 404, 'weight': 325},
51  {'category': 'drink', 'name': 'coke', 'color': 'red', 'volume': 270, 'weight': 222},
52  {'category': 'drink', 'name': 'grape_juice', 'color': 'purplish', 'volume': 216, 'weight': 200},
53  {'category': 'drink', 'name': 'orange_juice', 'color': 'orange', 'volume': 216, 'weight': 200},
54  {'category': 'drink', 'name': 'sprite', 'color': 'bluegreen', 'volume': 270, 'weight': 222},
55 
56  {'category': 'food', 'name': 'cereal', 'color': 'blue', 'volume': 336, 'weight': 21},
57  {'category': 'food', 'name': 'noodles', 'color': 'yellowish', 'volume': 297, 'weight': 85},
58  {'category': 'food', 'name': 'sausages', 'color': 'blue', 'volume': 223, 'weight': 113},
59 
60  {'category': 'fruit', 'name': 'apple', 'color': 'greenred', 'volume': 360, 'weight': 85},
61  {'category': 'fruit', 'name': 'orange', 'color': 'orange', 'volume': 380, 'weight': 140},
62  {'category': 'fruit', 'name': 'paprika', 'color': 'red', 'volume': 402, 'weight': 90},
63 
64  {'category': 'snack', 'name': 'crackers', 'color': 'orange', 'volume': 243, 'weight': 28},
65  {'category': 'snack', 'name': 'potato_chips', 'color': 'black', 'volume': 4080, 'weight': 200},
66  {'category': 'snack', 'name': 'pringles', 'color': 'green', 'volume': 1125, 'weight': 156},
67 
68  {'category': 'tableware', 'name': 'bowl', 'color': 'green', 'volume': 458, 'weight': 65},
69  {'category': 'tableware', 'name': 'cup', 'color': 'green', 'volume': 300, 'weight': 50},
70  {'category': 'tableware', 'name': 'dish', 'color': 'green', 'volume': 672, 'weight': 70}
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  "drink": {"counter": "on_top_of"},
83  "cleaning_stuff": {"side_table": "on_top_of"},
84  "cutlery": {"storage_table": "on_top_of"},
85  "snack": {"bookcase": "shelf3"}, # educated guess
86  "fruit": {"bookcase": "shelf2"}, # educated guess
87  "container": {"end_table": "on_top_of"},
88  "food": {"cupboard": "shelf2"}, # educated guess
89  "tableware": {"storage_table": "on_top_of"}
90 }
91 
92 inspect_areas = {
93  "bookcase": ["shelf2", "shelf3", "shelf4"],
94  "cupboard": ["shelf3", "shelf4"]
95 }
96 
97 inspect_positions = {
98 }
99 
100 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101 
102 most_probable_location_in_room_map = {
103  'bedroom': 'side_table', # educated guess
104  'kitchen': 'cupboard', # educated guess
105  'dining_room': 'dining_table', # educated guess
106  'living_room': 'end_table' # educated guess
107 }
108 
109 def get_location_from_room(room_id):
110  if room_id in most_probable_location_in_room_map:
111  return most_probable_location_in_room_map[room_id]
112  return None
113 
114 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
115 
116 ''' colors from printing on screen '''
117 class bcolors:
118  HEADER = '\033[95m'
119  OKBLUE = '\033[94m'
120  OKGREEN = '\033[92m'
121  WARNING = '\033[93m'
122  FAIL = '\033[91m'
123  ENDC = '\033[0m'
124  BOLD = '\033[1m'
125  UNDERLINE = '\033[4m'
126 
127 
128 '''
129 General function for printing shortcuts
130 name: name of the program that instantiates make_prints
131 sentence: sentence to be displayed
132 
133 Ex: "[<EXECUTIVE NAME>] <SENTENCE TO BE DISPLAYED>"
134 '''
135 
136 
137 def make_prints(name):
138  prefix = bcolors.HEADER + name + bcolors.ENDC
139 
140  def printOk(sentence):
141  print(prefix + bcolors.OKBLUE + sentence + bcolors.ENDC)
142 
143  def printError(sentence):
144  print(prefix + bcolors.FAIL + sentence + bcolors.ENDC)
145 
146  def printWarning(sentence):
147  print(prefix + bcolors.WARNING + sentence + bcolors.ENDC)
148 
149  return printOk, printError, printWarning
150 
151 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
152 
153 def is_location(location):
154  for loc in locations:
155  if loc["name"] == location:
156  return True
157  return False
158 
159 
160 def get_room(location):
161  for loc in locations:
162  if loc["name"] == location:
163  return loc["room"]
164  return None
165 
166 
167 def is_room(entity_id):
168  return (entity_id in rooms)
169 
170 
171 def get_inspect_areas(location):
172  if location in inspect_areas:
173  return inspect_areas[location]
174  else:
175  return ["on_top_of"]
176 
177 
178 def get_inspect_position(location, area=""):
179  if location in inspect_positions and area in inspect_positions[location]:
180  return inspect_positions[location][area]
181  else:
182  return "in_front_of"
183 
184 
185 def is_pick_location(location):
186  for loc in locations:
187  if loc["name"] == location and loc["manipulation"] == "yes":
188  return True
189  return False
190 
191 
192 def is_place_location(location):
193  for loc in locations:
194  if loc["name"] == location and (loc["manipulation"] == "yes" or loc["manipulation"] == "only_putting"):
195  return True
196  return False
197 
198 
199 def get_locations(room=None, pick_location=None, place_location=None):
200  return [loc["name"] for loc in locations
201  if (room == None or loc["room"] == room) and \
202  (pick_location == None or pick_location == is_pick_location(loc["name"])) and \
203  (place_location == None or place_location == is_place_location(loc["name"]))]
204 
205 
206 def get_objects(category=None):
207  return [obj["name"] for obj in objects
208  if category == None or category == obj["category"]]
209 
210 
211 def get_object_category(obj):
212  for o in objects:
213  if o["name"] == obj:
214  return o["category"]
215  return None
216 
217 def get_object_color(obj):
218  for o in objects:
219  if o["name"] == obj:
220  return o["color"]
221  return None
222 
223 def get_object_size(obj):
224  for o in objects:
225  if o["name"] == obj:
226  return o["volume"]
227  return None
228 
229 def get_object_weight(obj):
230  for o in objects:
231  if o["name"] == obj:
232  return o["weight"]
233  return None
234 
235 # Returns (location, area_name)
236 def get_object_category_location(obj_cat):
237  location, area_name = next(iter(category_locations[obj_cat].items()))
238  return location, area_name
239 
240 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
241 
242 
243 if __name__ == "__main__":
244  print("\n-----------------------------------------------------------------------------")
245  for obj in get_objects():
246  cat = get_object_category(obj)
247  (location, area_name) = get_object_category_location(cat)
248  print("object '{}'".format(obj))
249  print(" category: '{}'".format(cat))
250  print(" found '{} {}'".format(area_name, location))
251 
252  print("\n-----------------------------------------------------------------------------")
253  for loc in get_locations():
254  print("location '{}', room: '{}'".format(loc, get_room(loc)))
255 
256  print("\n-----------------------------------------------------------------------------")
257  print("Pick locations:")
258  for loc in get_locations(pick_location=True):
259  print(" {}".format(loc))
260 
261  print("\n-----------------------------------------------------------------------------")
262  print("Place locations:")
263  for loc in get_locations(place_location=True):
264  print(" {}".format(loc))
265 
266  print("\n-----------------------------------------------------------------------------")
267  print("None-manipulation locations:")
268  for loc in get_locations(pick_location=False, place_location=False):
269  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