robocup_knowledge
rgo2017/common.py
Go to the documentation of this file.
1 # COMMON KNOWLEDGE FILE RGO2017
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 locations = [
11  { 'name':'bookshelf', 'room':'living_room', 'category': 'shelf', 'manipulation':'yes' },
12  { 'name':'sofa', 'room':'living_room', 'category': 'seat', 'manipulation':'no' },
13  { 'name':'couch_table', 'room':'living_room', 'category': 'table', 'manipulation':'yes' },
14  { 'name':'side_table', 'room':'living_room', 'category': 'table', 'manipulation':'yes' },
15  { 'name':'tv_stand', 'room':'living_room', 'category': 'beacon', 'manipulation':'no' },
16 
17  { 'name':'kitchencounter', 'room':'kitchen', 'category': 'table', 'manipulation':'yes' },
18  { 'name':'stove', 'room':'kitchen', 'category': 'table', 'manipulation':'yes' },
19  { 'name':'desk', 'room':'kitchen', 'category': 'table', 'manipulation':'yes' },
20  { 'name':'bar', 'room':'kitchen', 'category': 'table', 'manipulation':'yes' },
21 
22  { 'name':'bed', 'room':'bedroom', 'category': 'seat', 'manipulation':'no' },
23  { 'name':'closet', 'room':'bedroom', 'category': 'shelf', 'manipulation':'yes' },
24 
25  { 'name':'dinner_table', 'room':'dining_room', 'category': 'table', 'manipulation':'yes' },
26  { 'name':'cabinet', 'room':'dining_room', 'category': 'shelf', 'manipulation':'yes' }
27 
28 ]
29 
30 location_rooms = list(set([ o["room"] for o in locations ]))
31 location_categories = list(set([ o["category"] for o in locations ]))
32 location_names = list(set([ o["name"] for o in locations ]))
33 manipulation_locations = list(set([ o["name"] for o in locations if o["manipulation"] == "yes" ]))
34 
35 # hack
36 most_probable_location_in_room_map = {
37  'dining_room': 'dinner_table',
38  'bedroom': 'closet',
39  'living_room': 'couch_table',
40  'kitchen': 'desk'
41 }
42 
43 
44 def get_location_from_room(room_id):
45  if room_id in most_probable_location_in_room_map:
46  return most_probable_location_in_room_map[room_id]
47  return None
48 
49 # rooms = location_rooms + ["workshop"]
50 
51 objects = [
52  {'category': 'food', 'name': 'apple' },
53  {'category': 'food', 'name': 'bread' },
54  {'category': 'food', 'name': 'cereals' },
55  {'category': 'food', 'name': 'cornflakes' },
56  {'category': 'food', 'name': 'crackers' },
57  {'category': 'food', 'name': 'lemon' },
58  {'category': 'food', 'name': 'noodles' },
59  {'category': 'food', 'name': 'paprika' },
60  {'category': 'food', 'name': 'peas' },
61  {'category': 'food', 'name': 'pepper' },
62  {'category': 'food', 'name': 'potato' },
63  {'category': 'food', 'name': 'potato_soup' },
64  {'category': 'food', 'name': 'salt' },
65  {'category': 'food', 'name': 'tomato_pasta' },
66  {'category': 'container', 'name': 'bag' },
67  {'category': 'container', 'name': 'basket' },
68  {'category': 'container', 'name': 'coffecup' },
69  {'category': 'container', 'name': 'plate' },
70  {'category': 'container', 'name': 'red_bowl' },
71  {'category': 'container', 'name': 'white_bowl' },
72  {'category': 'drink', 'name': 'banana_milk' },
73  {'category': 'drink', 'name': 'cappucino' },
74  {'category': 'drink', 'name': 'coke' },
75  {'category': 'drink', 'name': 'orange_drink' },
76  {'category': 'drink', 'name': 'water' },
77  {'category': 'snack', 'name': 'chocolate_cookies' },
78  {'category': 'snack', 'name': 'egg' },
79  {'category': 'snack', 'name': 'party_cracker' },
80  {'category': 'snack', 'name': 'pringles' },
81  {'category': 'cleaning_stuff', 'name': 'cloth' },
82  {'category': 'cleaning_stuff', 'name': 'paper' },
83  {'category': 'cleaning_stuff', 'name': 'sponge' },
84  {'category': 'cleaning_stuff', 'name': 'towel' },
85  {'category': 'cutlery', 'name': 'fork' },
86  {'category': 'cutlery', 'name': 'spoon' },
87  {'category': 'cutlery', 'name': 'knife' }
88 
89 ]
90 
91 object_names = list(set([ o["name"] for o in objects ]))
92 object_categories = list(set([ o["category"] for o in objects ]))
93 # object_groups = list(set([ o["group"] for o in objects ]))
94 # object_known_objects = list(set([ o["name"] for o in objects ]))
95 
96 category_locations = {
97 
98  "cutlery": {"cabinet": "shelf2"},
99  "container": {"bookshelf": "shelf1"},
100  "drink": {"kitchencounter": "on_top_of"},
101  "snack": {"couch_table": "on_top_of"},
102  "food": {"stove": "on_top_of"},
103  "cleaning_stuff": {"closet": "on_top_of"},
104  "fruit": {"desk": "on_top_of"}
105 }
106 
107 inspect_areas = {
108  "cabinet": ["shelf1", "shelf2", "shelf3", "shelf4"],
109  "bookshelf": ["shelf1", "shelf2", "shelf3", "shelf4"]
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