robocup_knowledge
rgo2018/common.py
Go to the documentation of this file.
1 # COMMON KNOWLEDGE FILE RGO2018
2 
3 from __future__ import print_function
4 
5 female_names = ["angie", "mary", "amy", "kimberley", "lisa", "melissa", "michelle", "jennifer", "elizabeth", "julie"]
6 male_names = ["brian", "michael", "christopher", "william", "john", "david", "james", "robert", "scott", "richard"]
7 names = female_names + male_names
8 
9 # This dict holds all locations
10 locations = [
11 
12  {'name': 'bed', 'room': 'bedroom', 'category': 'beacon', 'manipulation': 'no'},
13  {'name': 'desk', 'room': 'bedroom', 'category': 'shelf', 'manipulation': 'yes'},
14  {'name': 'bookcase', 'room': 'bedroom', 'category': 'shelf', 'manipulation': 'yes'},
15  {'name': 'side_table', 'room': 'bedroom', 'category': 'table', 'manipulation': 'yes'},
16 
17  {'name': 'bar', 'room': 'kitchen', 'category': 'bar', 'manipulation': 'yes'},
18  {'name': 'kitchen_table', 'room': 'kitchen', 'category': 'table', 'manipulation': 'yes'},
19  {'name': 'kitchen_cabinet', 'room': 'kitchen', 'category': 'table', 'manipulation': 'yes'},
20  {'name': 'sink', 'room': 'kitchen', 'category': 'table', 'manipulation': 'no'},
21 
22  {'name': 'tv_table', 'room': 'living_room', 'category': 'table', 'manipulation': 'yes'},
23  {'name': 'cupboard', 'room': 'living_room', 'category': 'shelf', 'manipulation': 'yes'},
24  {'name': 'couch', 'room': 'living_room', 'category': 'seat', 'manipulation': 'yes'},
25  {'name': 'couch_table', 'room': 'living_room', 'category': 'beacon', 'manipulation': 'yes'},
26 
27  {'name': 'dining_table', 'room': 'dining_room', 'category': 'beacon', 'manipulation': 'yes'},
28  {'name': 'cabinet', 'room': 'dining_room', 'category': 'shelf', 'manipulation': 'yes'},
29  {'name': 'display_case', 'room': 'dining_room', 'category': 'table', 'manipulation': 'no'},
30  {'name': 'storage_shelf', 'room': 'dining_room', 'category': 'shelf', 'manipulation': 'yes'}
31 
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 rooms = location_rooms + ["workshop"]
40 
41 objects = [
42  {'category': 'care', 'name': 'shower_gel', 'color': 'pink'},
43  {'category': 'care', 'name': 'soap', 'color': 'white'},
44  {'category': 'care', 'name': 'toothpaste', 'color': 'green'},
45  {'category': 'cleaning_stuff', 'name': 'sponge', 'color': 'yellow'},
46  {'category': 'cleaning_stuff', 'name': 'wiper', 'color': 'yellow'},
47  {'category': 'container', 'name': 'box', 'color': 'yellow'},
48  {'category': 'container', 'name': 'tray', 'color': 'white'},
49  {'category': 'drinks', 'name': 'beer', 'color': 'yellow'},
50  {'category': 'drinks', 'name': 'cacao', 'color': 'brown'},
51  {'category': 'drinks', 'name': 'coke', 'color': 'red'},
52  {'category': 'drinks', 'name': 'malz', 'color': 'brown'},
53  {'category': 'drinks', 'name': 'mixdrink', 'color': 'brown'},
54  {'category': 'drinks', 'name': 'orange_juice', 'color': 'orange'},
55  {'category': 'drinks', 'name': 'peppermint_tea', 'color': 'green'},
56  {'category': 'drinks', 'name': 'water', 'color': 'transparent'},
57  {'category': 'snacks', 'name': 'cookies', 'color': 'blue'},
58  {'category': 'snacks', 'name': 'fruit_bar', 'color': 'green'},
59  {'category': 'snacks', 'name': 'kinder', 'color': 'white'},
60  {'category': 'snacks', 'name': 'nuts', 'color': 'yellow'},
61  {'category': 'food', 'name': 'apple', 'color': 'green'},
62  {'category': 'food', 'name': 'green_paprika', 'color': 'green'},
63  {'category': 'food', 'name': 'kiwi', 'color': 'brown'},
64  {'category': 'food', 'name': 'lemon', 'color': 'yellow'},
65  {'category': 'food', 'name': 'noodles', 'color': 'yellow'},
66  {'category': 'food', 'name': 'pepper', 'color': 'brown'},
67  {'category': 'food', 'name': 'salt', 'color': 'salt'},
68  {'category': 'food', 'name': 'tomato', 'color': 'red'},
69  {'category': 'kitchen_stuff', 'name': 'fork', 'color': 'green'},
70  {'category': 'kitchen_stuff', 'name': 'spoon', 'color': 'green'},
71  {'category': 'kitchen_stuff', 'name': 'knife', 'color': 'green'},
72  {'category': 'kitchen_stuff', 'name': 'plate', 'color': 'green'},
73  {'category': 'kitchen_stuff', 'name': 'cup', 'color': 'green'}
74 
75 
76 ]
77 
78 # {'category': 'help_me_carry', 'name': 'bag', 'color': 'red'},
79 # {'category': 'dishwasher_test', 'name': 'dishwasher_tray', 'color': 'white'},
80 
81 object_names = list(set([ o["name"] for o in objects ]))
82 object_categories = list(set([ o["category"] for o in objects ]))
83 object_color = list(set([ o["color"] for o in objects ]))
84 # object_groups = list(set([ o["group"] for o in objects ]))
85 # object_known_objects = list(set([ o["name"] for o in objects ]))
86 
87 category_locations = {
88 #Test
89  "care": {"bookcase": "shelf2"},
90  "container": {"cupboard": "on_top_off"},
91  "drinks": {"kitchen_table": "on_top_of"},
92  "snacks": {"couch_table": "on_top_of"},
93  "food": {"cabinet": "shelf2"},
94  "cleaning_stuff": {"kitchen_cabinet": "on_top_of"},
95  "kitchen_stuff" : {"kitchen_table": "on_top_of"}
96 }
97 
98 inspect_areas = {
99 #Test
100  "cabinet": ["shelf2", "shelf3", "shelf4"],
101  "display_case": ["shelf2", "shelf3", "shelf4"],
102  "storage_shelf": ["shelf2", "shelf3", "shelf4"],
103  "bookcase": ["shelf2", "shelf3", "shelf4"]
104 }
105 
106 inspect_positions = {
107 }
108 
109 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
110 
111 ''' colors from printing on screen '''
112 class bcolors:
113  HEADER = '\033[95m'
114  OKBLUE = '\033[94m'
115  OKGREEN = '\033[92m'
116  WARNING = '\033[93m'
117  FAIL = '\033[91m'
118  ENDC = '\033[0m'
119  BOLD = '\033[1m'
120  UNDERLINE = '\033[4m'
121 
122 
123 '''
124 General function for printing shortcuts
125 name: name of the program that instantiates make_prints
126 sentence: sentence to be displayed
127 
128 Ex: "[<EXECUTIVE NAME>] <SENTENCE TO BE DISPLAYED>"
129 '''
130 
131 
132 def make_prints(name):
133 
134  prefix = bcolors.HEADER + name + bcolors.ENDC
135  def printOk(sentence):
136  print(prefix + bcolors.OKBLUE + sentence + bcolors.ENDC)
137 
138  def printError(sentence):
139  print(prefix + bcolors.FAIL + sentence + bcolors.ENDC)
140 
141  def printWarning(sentence):
142  print(prefix + bcolors.WARNING + sentence + bcolors.ENDC)
143 
144  return printOk, printError, printWarning
145 
146 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147 
148 def is_location(location):
149  for loc in locations:
150  if loc["name"] == location:
151  return True
152  return False
153 
154 
155 def get_room(location):
156  for loc in locations:
157  if loc["name"] == location:
158  return loc["room"]
159  return None
160 
161 
162 def is_room(entity_id):
163  return (entity_id in rooms)
164 
165 
166 def get_inspect_areas(location):
167  if location in inspect_areas:
168  return inspect_areas[location]
169  else:
170  return ["on_top_of"]
171 
172 
173 def get_inspect_position(location, area=""):
174  if location in inspect_positions and area in inspect_positions[location]:
175  return inspect_positions[location][area]
176  else:
177  return "in_front_of"
178 
179 
180 def is_pick_location(location):
181  for loc in locations:
182  if loc["name"] == location and loc["manipulation"] == "yes":
183  return True
184  return False
185 
186 
187 def is_place_location(location):
188  for loc in locations:
189  if loc["name"] == location and (loc["manipulation"] == "yes" or loc["manipulation"] == "only_putting"):
190  return True
191  return False
192 
193 
194 def get_locations(room=None, pick_location=None, place_location=None):
195  return [loc["name"] for loc in locations
196  if (room == None or loc["room"] == room) and \
197  (pick_location == None or pick_location == is_pick_location(loc["name"])) and \
198  (place_location == None or place_location == is_place_location(loc["name"]))]
199 
200 
201 def get_objects(category=None):
202  return [obj["name"] for obj in objects
203  if category == None or category == obj["category"]]
204 
205 
206 def get_object_category(obj):
207  for o in objects:
208  if o["name"] == obj:
209  return o["category"]
210  return None
211 
212 def get_object_color(obj):
213  for o in objects:
214  if o["name"] == obj:
215  return o["color"]
216  return None
217 
218 # Returns (location, area_name)
219 def get_object_category_location(obj_cat):
220  location, area_name = next(iter(category_locations[obj_cat].items()))
221  return location, area_name
222 
223 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
224 
225 
226 if __name__ == "__main__":
227  print("\n-----------------------------------------------------------------------------")
228  for obj in get_objects():
229  cat = get_object_category(obj)
230  (location, area_name) = get_object_category_location(cat)
231  print("object '{}'".format(obj))
232  print(" category: '{}'".format(cat))
233  print(" found '{} {}'".format(area_name, location))
234 
235  print("\n-----------------------------------------------------------------------------")
236  for loc in get_locations():
237  print("location '{}', room: '{}'".format(loc, get_room(loc)))
238 
239  print("\n-----------------------------------------------------------------------------")
240  print("Pick locations:")
241  for loc in get_locations(pick_location=True):
242  print(" {}".format(loc))
243 
244  print("\n-----------------------------------------------------------------------------")
245  print("Place locations:")
246  for loc in get_locations(place_location=True):
247  print(" {}".format(loc))
248 
249  print("\n-----------------------------------------------------------------------------")
250  print("None-manipulation locations:")
251  for loc in get_locations(pick_location=False, place_location=False):
252  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_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.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