robocup_knowledge
siza_demo/common.py
Go to the documentation of this file.
1 # COMMON KNOWLEDGE FILE SIZA DEMO
2 
3 from __future__ import print_function
4 
5 names = ['peter', 'josja']
6 # This dict holds all locations
7 locations = [
8  {'name': 'dinner_table', 'room': 'living_room', 'category': 'table', 'manipulation': 'yes'},
9 
10  {'name': 'cabinet', 'room': 'kitchen', 'category': 'shelf', 'manipulation': 'yes'},
11  {'name': 'trashbin', 'room': 'kitchen', 'category': 'utility', 'manipulation': 'yes'},
12  {'name': 'couch', 'room': 'hallway', 'category': 'table', 'manipulation': 'yes'},
13 
14  {'name': 'counter', 'room': 'kitchen', 'category': 'shelf', 'manipulation': 'yes'},
15  {'name': 'tray_table', 'room': 'living_room', 'category': 'shelf', 'manipulation': 'yes'}
16 ]
17 
18 location_rooms = list(set([ o["room"] for o in locations ]))
19 location_categories = list(set([ o["category"] for o in locations ]))
20 location_names = list(set([ o["name"] for o in locations ]))
21 manipulation_locations = list(set([ o["name"] for o in locations if o["manipulation"] == "yes" ]))
22 
23 location_rooms += ["workshop"]
24 rooms = location_rooms
25 
26 objects = [
27  {'category': 'container', 'name': 'cup', 'color': 'green'},
28  {'category': 'drink', 'name': 'coke', 'color': 'red'},
29  {'category': 'drink', 'name': 'fanta_bottle', 'color': 'red'},
30  {'category': 'drink', 'name': 'coke_zero', 'color': 'black'},
31  {'category': 'drink', 'name': 'fanta', 'color': 'orange'},
32  {'category': 'snack', 'name': 'pringles', 'color': 'orange'},
33  {'category': 'snack', 'name': 'apple', 'color': 'green'},
34 ]
35 
36 object_names = list(set([ o["name"] for o in objects ]))
37 object_categories = list(set([ o["category"] for o in objects ]))
38 object_color = list(set([ o["color"] for o in objects ]))
39 
40 category_locations = {
41  "container": {"cabinet": "on_top_of"},
42  "drink": {"dinner_table": "on_top_of"},
43  "snack": {"cabinet": "on_top_of"},
44  "cleaning_stuff": {"cabinet": "on_top_of"},
45 }
46 
47 inspect_positions = {
48 }
49 inspect_areas = {
50 }
51 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52 
53 most_probable_location_in_room_map = {
54  'living_room': 'dinner_table',
55  'kitchen': 'cabinet',
56 }
57 
58 
59 def get_location_from_room(room_id):
60  if room_id in most_probable_location_in_room_map:
61  return most_probable_location_in_room_map[room_id]
62  return None
63 
64 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
65 
66 ''' colors from printing on screen '''
67 class bcolors:
68  HEADER = '\033[95m'
69  OKBLUE = '\033[94m'
70  OKGREEN = '\033[92m'
71  WARNING = '\033[93m'
72  FAIL = '\033[91m'
73  ENDC = '\033[0m'
74  BOLD = '\033[1m'
75  UNDERLINE = '\033[4m'
76 
77 
78 '''
79 General function for printing shortcuts
80 name: name of the program that instantiates make_prints
81 sentence: sentence to be displayed
82 
83 Ex: "[<EXECUTIVE NAME>] <SENTENCE TO BE DISPLAYED>"
84 '''
85 
86 
87 def make_prints(name):
88 
89  prefix = bcolors.HEADER + name + bcolors.ENDC
90  def printOk(sentence):
91  print(prefix + bcolors.OKBLUE + sentence + bcolors.ENDC)
92 
93  def printError(sentence):
94  print(prefix + bcolors.FAIL + sentence + bcolors.ENDC)
95 
96  def printWarning(sentence):
97  print(prefix + bcolors.WARNING + sentence + bcolors.ENDC)
98 
99  return printOk, printError, printWarning
100 
101 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
102 
103 def is_location(location):
104  for loc in locations:
105  if loc["name"] == location:
106  return True
107  return False
108 
109 
110 def get_room(location):
111  for loc in locations:
112  if loc["name"] == location:
113  return loc["room"]
114  return None
115 
116 
117 def is_room(entity_id):
118  return (entity_id in rooms)
119 
120 def get_inspect_position(location, area=""):
121  if location in inspect_positions and area in inspect_positions[location]:
122  return inspect_positions[location][area]
123  else:
124  return "in_front_of"
125 
126 
127 def is_pick_location(location):
128  for loc in locations:
129  if loc["name"] == location and loc["manipulation"] == "yes":
130  return True
131  return False
132 
133 def get_inspect_areas(location):
134  if location in inspect_areas:
135  return inspect_areas[location]
136  else:
137  return ["on_top_of"]
138 
139 def get_inspect_position(location, area=""):
140  if location in inspect_positions and area in inspect_positions[location]:
141  return inspect_positions[location][area]
142  else:
143  return "in_front_of"
144 
145 def is_place_location(location):
146  for loc in locations:
147  if loc["name"] == location and (loc["manipulation"] == "yes" or loc["manipulation"] == "only_putting"):
148  return True
149  return False
150 
151 
152 def get_locations(room=None, pick_location=None, place_location=None):
153  return [loc["name"] for loc in locations
154  if (room == None or loc["room"] == room) and \
155  (pick_location == None or pick_location == is_pick_location(loc["name"])) and \
156  (place_location == None or place_location == is_place_location(loc["name"]))]
157 
158 
159 def get_objects(category=None):
160  return [obj["name"] for obj in objects
161  if category == None or category == obj["category"]]
162 
163 
164 def get_object_category(obj):
165  for o in objects:
166  if o["name"] == obj:
167  return o["category"]
168  return None
169 
170 def get_object_color(obj):
171  for o in objects:
172  if o["name"] == obj:
173  return o["color"]
174  return None
175 
176 # Returns (location, area_name)
177 def get_object_category_location(obj_cat):
178  location, area_name = next(iter(category_locations[obj_cat].items()))
179  return location, area_name
180 
181 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
182 
183 
184 if __name__ == "__main__":
185  print("\n-----------------------------------------------------------------------------")
186  for obj in get_objects():
187  cat = get_object_category(obj)
188  (location, area_name) = get_object_category_location(cat)
189  print("object '{}'".format(obj))
190  print(" category: '{}'".format(cat))
191  print(" found '{} {}'".format(area_name, location))
192 
193  print("\n-----------------------------------------------------------------------------")
194  for loc in get_locations():
195  print("location '{}', room: '{}'".format(loc, get_room(loc)))
196 
197  print("\n-----------------------------------------------------------------------------")
198  print("Pick locations:")
199  for loc in get_locations(pick_location=True):
200  print(" {}".format(loc))
201 
202  print("\n-----------------------------------------------------------------------------")
203  print("Place locations:")
204  for loc in get_locations(place_location=True):
205  print(" {}".format(loc))
206 
207  print("\n-----------------------------------------------------------------------------")
208  print("None-manipulation locations:")
209  for loc in get_locations(pick_location=False, place_location=False):
210  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.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