robocup_knowledge
rwc2017/common.py
Go to the documentation of this file.
1 # COMMON KNOWLEDGE FILE RWC2017
2 
3 from __future__ import print_function
4 
5 female_names = ["emma", "olivia", "sophia", "ava", "isabella", "mia", "abigail", "emily", "charlotte", "harper"]
6 male_names = ["noah", "liam", "mason", "jacob", "william", "ethan", "james", "alexander", "michael", "benjamin"]
7 names = female_names + male_names
8 
9 # This dict holds all locations
10 # ToDo: check with Loy: category
11 locations = [
12  {"name": "desk", "room": "living_room", "category": "ToDo", "manipulation": "yes"},
13  {"name": "left_rack", "room": "living_room", "category": "ToDo", "manipulation": "yes"},
14  {"name": "right_rack", "room": "living_room", "category": "ToDo", "manipulation": "yes"},
15  {"name": "sideboard", "room": "kitchen", "category": "ToDo", "manipulation": "yes"},
16  {"name": "kitchen_table", "room": "kitchen", "category": "ToDo", "manipulation": "yes"},
17  {"name": "little_desk", "room": "bedroom", "category": "ToDo", "manipulation": "yes"},
18  {"name": "teepee", "room": "bedroom", "category": "ToDo", "manipulation": "no"},
19  {"name": "bed", "room": "bedroom", "category": "ToDo", "manipulation": "yes"},
20  {"name": "entrance_shelf", "room": "entrance", "category": "ToDo", "manipulation": "yes"},
21  {"name": "kitchen_shelf", "room": "kitchen", "category": "ToDo", "manipulation": "yes"},
22  {"name": "bookcase", "room": "living_room", "category": "ToDo", "manipulation": "yes"},
23  {"name": "sofa", "room": "living_room", "category": "ToDo", "manipulation": "yes"},
24  {"name": "coffee_table", "room": "living_room", "category": "ToDo", "manipulation": "yes"},
25  {"name": "tv", "room": "living_room", "category": "ToDo", "manipulation": "no"},
26  {"name": "bistro_table", "room": "balcony", "category": "ToDo", "manipulation": "yes"},
27  {"name": "left_planks", "room": "balcony", "category": "ToDo", "manipulation": "yes"},
28  {"name": "right_planks", "room": "balcony", "category": "ToDo", "manipulation": "yes"},
29  {"name": "balcony_shelf", "room": "balcony", "category": "ToDo", "manipulation": "yes"},
30  {"name": "kitchen_counter", "room": "kitchen", "category": "ToDo", "manipulation": "yes"},
31  {"name": "fridge", "room": "kitchen", "category": "ToDo", "manipulation": "yes"},
32  {"name": "kitchen_rack", "room": "kitchen", "category": "ToDo", "manipulation": "yes"}
33 ]
34 
35 location_rooms = list(set([o["room"] for o in locations])) + ['corridor']
36 location_categories = list(set([o["category"] for o in locations]))
37 location_names = list(set([o["name"] for o in locations]))
38 manipulation_locations = list(set([o["name"] for o in locations if o["manipulation"] == "yes"]))
39 
40 # hack
41 # ToDo: Rokus
42 most_probable_location_in_room_map = {
43  "living_room" : "desk",
44  "kitchen" : "kitchen_table",
45  "bedroom" : "little_desk",
46  "entrance" : "entrance_shelf",
47  "balcony" : "bistro_table"
48 }
49 
50 
51 def get_location_from_room(room_id):
52  if room_id in most_probable_location_in_room_map:
53  return most_probable_location_in_room_map[room_id]
54  return None
55 
56 objects = [
57  {"name": "curry", "category": "snack"},
58  {"name": "plate", "category": "container"},
59  {"name": "shampoo", "category": "cleaning_stuff"},
60  {"name": "green_tea", "category": "drink"},
61  {"name": "chewing_gum", "category": "snack"},
62  {"name": "chopsticks", "category": "cutlery"},
63  {"name": "soup_container", "category": "container"},
64  {"name": "aquarius", "category": "drink"},
65  {"name": "fries", "category": "snack"},
66  {"name": "bowl", "category": "container"},
67  {"name": "candy", "category": "snack"},
68  {"name": "asience", "category": "cleaning_stuff"},
69  {"name": "fork", "category": "cutlery"},
70  {"name": "spoon", "category": "cutlery"},
71  {"name": "hair_spray", "category": "cleaning_stuff"},
72  {"name": "radish", "category": "food"},
73  {"name": "apple", "category": "fruit"},
74  {"name": "cold_brew", "category": "drink"},
75  {"name": "onion", "category": "food"},
76  {"name": "corn", "category": "food"},
77  {"name": "jelly", "category": "snack"},
78  {"name": "bread", "category": "food"},
79  {"name": "cup_star", "category": "snack"},
80  {"name": "orange", "category": "fruit"},
81  {"name": "moisturizer", "category": "cleaning_stuff"},
82  {"name": "coke", "category": "drink"}
83 ]
84 
85 object_names = list(set([o["name"] for o in objects]))
86 object_categories = list(set([o["category"] for o in objects]))
87 
88 category_locations = {
89  "container": {"left_rack": "on_top_of"},
90  "cleaning_stuff": {"right_rack": "on_top_of"},
91  "cutlery": {"sideboard": "on_top_of"},
92  "food": {"kitchen_shelf": "shelf3"},
93  "drink": {"kitchen_counter": "on_top_of"},
94  "snack": {"kitchen_rack": "shelf2"},
95  "fruit": {"bistro_table": "on_top_of"}
96 }
97 
98 # "left_planks": [],
99 # "right_planks": [],
100 inspect_areas = {
101  "kitchen_shelf": ["shelf2", "shelf3", "shelf4", "shelf5", "shelf6"],
102  "balcony_shelf": ["shelf2", "shelf3", "shelf4"],
103  "kitchen_rack": ["shelf2", "shelf3", "shelf4"],
104  "kitchen_table": ["on_top_of", "on_top_of_back"],
105  "sideboard": ["on_top_of", "shelf1"],
106  "left_rack": ["on_top_of", "shelf3", "shelf2"],
107  "right_rack": ["on_top_of", "shelf3", "shelf2"],
108  "left_planks": ["on_top_of"],
109  "right_planks": ["on_top_of"]
110 }
111 
112 inspect_positions = {
113 }
114 
115 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
116 
117 
118 class bcolors:
119  ''' colors from printing on screen '''
120  HEADER = '\033[95m'
121  OKBLUE = '\033[94m'
122  OKGREEN = '\033[92m'
123  WARNING = '\033[93m'
124  FAIL = '\033[91m'
125  ENDC = '\033[0m'
126  BOLD = '\033[1m'
127  UNDERLINE = '\033[4m'
128 
129 
130 '''
131  General function for printing shortcuts
132  name: name of the progam that instanciates make_prints
133  sentence: sentence to be displayed
134 
135  Ex: "[<EXECUTIVE NAME>] <SENTENCE TO BE DISPLAYED>"
136 '''
137 
138 
139 def make_prints(name):
140 
141  prefix = bcolors.HEADER + name + bcolors.ENDC
142  def printOk(sentence):
143  print(prefix + bcolors.OKBLUE + sentence + bcolors.ENDC)
144 
145  def printError(sentence):
146  print(prefix + bcolors.FAIL + sentence + bcolors.ENDC)
147 
148  def printWarning(sentence):
149  print(prefix + bcolors.WARNING + sentence + bcolors.ENDC)
150 
151  return printOk, printError, printWarning
152 
153 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
154 
155 
156 def is_location(location):
157  for loc in locations:
158  if loc["name"] == location:
159  return True
160  return False
161 
162 
163 def get_room(location):
164  if location in location_rooms:
165  return location
166  for loc in locations:
167  if loc["name"] == location:
168  return loc["room"]
169  return None
170 
171 
172 def get_inspect_areas(location):
173  if location in inspect_areas:
174  return inspect_areas[location]
175  else:
176  return ["on_top_of"]
177 
178 
179 def get_inspect_position(location, area=""):
180  if location in inspect_positions and area in inspect_positions[location]:
181  return inspect_positions[location][area]
182  else:
183  return "in_front_of"
184 
185 
186 def is_pick_location(location):
187  for loc in locations:
188  if loc["name"] == location and loc["manipulation"] == "yes":
189  return True
190  return False
191 
192 
193 def is_place_location(location):
194  for loc in locations:
195  if loc["name"] == location and (loc["manipulation"] == "yes" or loc["manipulation"] == "only_putting"):
196  return True
197  return False
198 
199 
200 def get_locations(room=None, pick_location=None, place_location=None):
201  return [loc["name"] for loc in locations
202  if (room == None or loc["room"] == room) and \
203  (pick_location == None or pick_location == is_pick_location(loc["name"])) and \
204  (place_location == None or place_location == is_place_location(loc["name"]))]
205 
206 
207 def get_objects(category=None):
208  return [obj["name"] for obj in objects
209  if category == None or category == obj["category"]]
210 
211 
212 def get_object_category(obj):
213  for o in objects:
214  if o["name"] == obj:
215  return o["category"]
216  return None
217 
218 
219 def get_object_category_location(obj_cat):
220  # Returns (location, area_name)
221  location, area_name = next(iter(category_locations[obj_cat].items()))
222  return location, area_name
223 
224 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
225 
226 
227 if __name__ == "__main__":
228  print("\n-----------------------------------------------------------------------------")
229  for obj in get_objects():
230  cat = get_object_category(obj)
231  (location, area_name) = get_object_category_location(cat)
232  print("object '{}'".format(obj))
233  print(" category: '{}'".format(cat))
234  print(" found '{} {}'".format(area_name, location))
235 
236  print("\n-----------------------------------------------------------------------------")
237  for loc in get_locations():
238  print("location '{}', room: '{}'".format(loc, get_room(loc)))
239 
240  print("\n-----------------------------------------------------------------------------")
241  print("Pick locations:")
242  for loc in get_locations(pick_location=True):
243  print(" {}".format(loc))
244 
245  print("\n-----------------------------------------------------------------------------")
246  print("Place locations:")
247  for loc in get_locations(place_location=True):
248  print(" {}".format(loc))
249 
250  print("\n-----------------------------------------------------------------------------")
251  print("None-manipulation locations:")
252  for loc in get_locations(pick_location=False, place_location=False):
253  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_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.is_place_location
def is_place_location(location)
Definition: demo/common.py:117
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_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