robocup_knowledge
demo/common.py
Go to the documentation of this file.
1 # COMMON KNOWLEDGE FILE RWC2017
2 from __future__ import print_function
3 
4 female_names = ["emma", "olivia", "sophia", "ava", "isabella", "mia", "abigail", "emily", "charlotte", "harper"]
5 male_names = ["noah", "liam", "mason", "jacob", "william", "ethan", "james", "alexander", "michael", "benjamin"]
6 names = female_names + male_names
7 
8 # This dict holds all locations
9 # ToDo: check with Loy: category
10 locations = [
11  {"name": "amigo_case", "room": "ToDo", "category": "ToDo", "manipulation": "no"},
12  {"name": "laptop_case", "room": "ToDo", "category": "ToDo", "manipulation": "no"},
13  {"name": "amigo_case_lid", "room": "ToDo", "category": "ToDo", "manipulation": "yes"},
14  {"name": "laptop_case_lid", "room": "ToDo", "category": "ToDo", "manipulation": "yes"},
15 ]
16 
17 location_rooms = list(set([o["room"] for o in locations]))
18 location_categories = list(set([o["category"] for o in locations]))
19 location_names = list(set([o["name"] for o in locations]))
20 manipulation_locations = list(set([o["name"] for o in locations if o["manipulation"] == "yes"]))
21 
22 objects = [
23  {"name": "coke", "category": "drink"},
24  {"name": "fanta", "category": "drink"}
25 ]
26 
27 object_names = list(set([o["name"] for o in objects]))
28 object_categories = list(set([o["category"] for o in objects]))
29 
30 category_locations = {
31  "drink": {"amigo_case_lid": "on_top_of"}
32 }
33 
34 inspect_positions = {
35 }
36 
37 
38 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 
40 
41 class bcolors:
42  ''' colors from printing on screen '''
43  HEADER = '\033[95m'
44  OKBLUE = '\033[94m'
45  OKGREEN = '\033[92m'
46  WARNING = '\033[93m'
47  FAIL = '\033[91m'
48  ENDC = '\033[0m'
49  BOLD = '\033[1m'
50  UNDERLINE = '\033[4m'
51 
52 
53 '''
54  General function for printing shortcuts
55  name: name of the progam that instanciates make_prints
56  sentence: sentence to be displayed
57 
58  Ex: "[<EXECUTIVE NAME>] <SENTENCE TO BE DISPLAYED>"
59 '''
60 
61 
62 def make_prints(name):
63  prefix = bcolors.HEADER + name + bcolors.ENDC
64 
65  def printOk(sentence):
66  print(prefix + bcolors.OKBLUE + sentence + bcolors.ENDC)
67 
68  def printError(sentence):
69  print(prefix + bcolors.FAIL + sentence + bcolors.ENDC)
70 
71  def printWarning(sentence):
72  print(prefix + bcolors.WARNING + sentence + bcolors.ENDC)
73 
74  return printOk, printError, printWarning
75 
76 
77 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
78 
79 
80 def is_location(location):
81  for loc in locations:
82  if loc["name"] == location:
83  return True
84  return False
85 
86 
87 def get_room(location):
88  if location in location_rooms:
89  return location
90  for loc in locations:
91  if loc["name"] == location:
92  return loc["room"]
93  return None
94 
95 
96 def get_inspect_areas(location):
97  if location in inspect_areas:
98  return inspect_areas[location]
99  else:
100  return ["on_top_of"]
101 
102 
103 def get_inspect_position(location, area=""):
104  if location in inspect_positions and area in inspect_positions[location]:
105  return inspect_positions[location][area]
106  else:
107  return "in_front_of"
108 
109 
110 def is_pick_location(location):
111  for loc in locations:
112  if loc["name"] == location and loc["manipulation"] == "yes":
113  return True
114  return False
115 
116 
117 def is_place_location(location):
118  for loc in locations:
119  if loc["name"] == location and (loc["manipulation"] == "yes" or loc["manipulation"] == "only_putting"):
120  return True
121  return False
122 
123 
124 def get_locations(room=None, pick_location=None, place_location=None):
125  return [loc["name"] for loc in locations
126  if (room == None or loc["room"] == room) and \
127  (pick_location == None or pick_location == is_pick_location(loc["name"])) and \
128  (place_location == None or place_location == is_place_location(loc["name"]))]
129 
130 
131 def get_objects(category=None):
132  return [obj["name"] for obj in objects
133  if category == None or category == obj["category"]]
134 
135 
137  for o in objects:
138  if o["name"] == obj:
139  return o["category"]
140  return None
141 
142 
144  # Returns (location, area_name)
145  location, area_name = next(iter(category_locations[obj_cat].items()))
146  return location, area_name
147 
148 
149 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150 
151 
152 if __name__ == "__main__":
153  print("\n-----------------------------------------------------------------------------")
154  for obj in get_objects():
156  (location, area_name) = get_object_category_location(cat)
157  print("object '{}'".format(obj))
158  print(" category: '{}'".format(cat))
159  print(" found '{} {}'".format(area_name, location))
160 
161  print("\n-----------------------------------------------------------------------------")
162  for loc in get_locations():
163  print("location '{}', room: '{}'".format(loc, get_room(loc)))
164 
165  print("\n-----------------------------------------------------------------------------")
166  print("Pick locations:")
167  for loc in get_locations(pick_location=True):
168  print(" {}".format(loc))
169 
170  print("\n-----------------------------------------------------------------------------")
171  print("Place locations:")
172  for loc in get_locations(place_location=True):
173  print(" {}".format(loc))
174 
175  print("\n-----------------------------------------------------------------------------")
176  print("None-manipulation locations:")
177  for loc in get_locations(pick_location=False, place_location=False):
178  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.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
common.bcolors
Definition: demo/common.py:41
challenge_person_recognition.printWarning
def printWarning(sentence)
Definition: reo2016/challenge_person_recognition.py:32