robocup_knowledge
reo2016/common.py
Go to the documentation of this file.
1 # COMMON KNOWLEDGE FILE REO2016
2 
3 from __future__ import print_function
4 
5 female_names = ["Emma", "Olivia", "Sophia", "Isabella", "Ava", "Mia", "Emily", "Abigail", "Madison", "Charlotte"]
6 male_names = ["Noah", "Liam", "Mason", "Jacob", "William", "Ethan", "Michael", "Alexander", "James", "Daniel"]
7 
8 names = female_names + male_names
9 
10 objects = [
11  {"name": "apple", "category": "food"},
12  {"name": "avocado", "category": "food"},
13  {"name": "bowl", "category": "container"},
14  {"name": "chocolate_sprinkles", "category": "food"},
15  {"name": "cloth", "category": "cleaning_stuff"},
16  {"name": "dishwashing_soap", "category": "cleaning_stuff"},
17  {"name": "kinder_coke", "category": "drink"},
18  {"name": "lemon", "category": "food"},
19  {"name": "licorice", "category": "candy"},
20  {"name": "little_bananas", "category": "candy"},
21  {"name": "macaroni", "category": "food"},
22  {"name": "milk", "category": "drink"},
23  {"name": "paprika", "category": "food"},
24  {"name": "pineapple_cookies", "category": "candy"},
25  {"name": "plate", "category": "container"},
26  {"name": "rice", "category": "food"},
27  {"name": "smoothie", "category": "drink"},
28  {"name": "soap", "category": "cleaning_stuff"},
29  {"name": "sponge", "category": "cleaning_stuff"},
30  {"name": "storage_box", "category": "container"},
31  {"name": "strawberry_cookies", "category": "candy"},
32  {"name": "tea", "category": "drink"},
33  {"name": "toilet_paper", "category": "cleaning_stuff"},
34  {"name": "tuc", "category": "candy"},
35  {"name": "wafer", "category": "candy"},
36  {"name": "water", "category": "drink"}
37 ]
38 
39 object_names = list(set([o["name"] for o in objects]))
40 object_categories = list(set([o["category"] for o in objects]))
41 
42 def get_object_names(category=None):
43  if category:
44  return list(set([o["name"] for o in objects if o["category"] == category]))
45  else:
46  return []
47 
48 locations = [
49  {"name": "closet", "room": "bedroom", "location_category": "shelf", "manipulation": "yes"},
50  {"name": "nightstand", "room": "bedroom", "location_category": "table", "manipulation": "yes"},
51  {"name": "bed", "room": "bedroom", "location_category": "seat", "manipulation": "yes"},
52  {"name": "fridge", "room": "kitchen", "location_category": "appliance", "manipulation": "no"},
53  {"name": "kitchen_trashbin", "room": "kitchen", "location_category": "bin", "manipulation": "only_putting"},
54  {"name": "kitchencounter", "room": "kitchen", "location_category": "table", "manipulation": "yes"},
55  {"name": "sink", "room": "kitchen", "location_category": "appliance", "manipulation": "only_putting"},
56  {"name": "hallway_trashbin", "room": "kitchen", "location_category": "bin", "manipulation": "only_putting"},
57  {"name": "sideboard", "room": "livingroom", "location_category": "shelf", "manipulation": "yes"},
58  {"name": "dinnerchairs", "room": "livingroom", "location_category": "seat", "manipulation": "no"},
59  {"name": "dinnertable", "room": "livingroom", "location_category": "table", "manipulation": "yes"},
60  {"name": "bookcase", "room": "livingroom", "location_category": "shelf", "manipulation": "yes"},
61  {"name": "couch", "room": "livingroom", "location_category": "seat", "manipulation": "yes"},
62  {"name": "tv_stand", "room": "livingroom", "location_category": "shelf", "manipulation": "yes"}
63 ]
64 
65 rooms = list(set([o["room"] for o in locations]))
66 grab_locations = list(set([o["name"] for o in locations if o["manipulation"] == "yes"]))
67 put_locations = list(set([o["name"] for o in locations if o["manipulation"] != "no"]))
68 
69 category_locations = {
70  "cleaning_stuff": {"closet": "on_top_of"},
71  "food": {"kitchencounter": "left_of_sink"},
72  "drink": {"kitchencounter": "right_of_sink"},
73  "candy": {"sideboard": "on_top_of"},
74  "container": {"dinnertable": "on_top_of"}
75 }
76 
77 inspect_areas = {
78  "closet" : ["on_top_of"],
79  "bookcase" : ["shelf1", "shelf2", "shelf3", "shelf4"],
80  "dinnertable" : ["on_top_of"],
81  "kitchencounter" : ["right_of_sink", "left_of_sink"],
82  "sideboard" : ["on_top_of_left", "on_top_of_right"],
83  "tv_stand" : ["on_top_of_left", "on_top_of_right"]
84 }
85 
86 inspect_positions = {
87  "kitchencounter" :
88  {
89  "right_of_sink" : "in_front_of_right_sink",
90  "left_of_sink" : "in_front_of_left_sink"
91  }
92 }
93 
94 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95 
96 def is_location(location):
97  for loc in locations:
98  if loc["name"] == location:
99  return True
100  return False
101 
102 def get_room(location):
103  for loc in locations:
104  if loc["name"] == location:
105  return loc["room"]
106  return None
107 
108 def get_inspect_areas(location):
109  if location in inspect_areas:
110  return inspect_areas[location]
111  else:
112  return ["on_top_of"]
113 
114 def get_inspect_position(location, area=""):
115  if location in inspect_positions and area in inspect_positions[location]:
116  return inspect_positions[location][area]
117  else:
118  return "in_front_of"
119 
120 def is_pick_location(location):
121  for loc in locations:
122  if loc["name"] == location and loc["manipulation"] == "yes":
123  return True
124  return False
125 
126 def is_place_location(location):
127  for loc in locations:
128  if loc["name"] == location and (loc["manipulation"] == "yes" or loc["manipulation"] == "only_putting"):
129  return True
130  return False
131 
132 def get_locations(room=None, pick_location=None, place_location=None):
133  return [loc["name"] for loc in locations
134  if (room == None or loc["room"] == room) and \
135  (pick_location == None or is_pick_location(loc["name"])) and \
136  (place_location == None or is_place_location(loc["name"]))]
137 
138 def get_objects(category=None):
139  return [obj["name"] for obj in objects
140  if category == None or category == obj["category"]]
141 
142 def get_object_category(obj):
143  for o in objects:
144  if o["name"] == obj:
145  return o["category"]
146  return None
147 
148 # Returns (location, area_name)
149 def get_object_category_location( obj_cat):
150  location, area_name = next(iter(category_locations[obj_cat].items()))
151  return location, area_name
152 
153 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
154 
155 
156 if __name__ == "__main__":
157  print("\n-----------------------------------------------------------------------------")
158  for obj in get_objects():
159  cat = get_object_category(obj)
160  (location, area_name) = get_object_category_location(cat)
161  print("object '{}'".format(obj))
162  print(" category: '{}'".format(cat))
163  print(" found '{} {}'".format(area_name, location))
164 
165  print("\n-----------------------------------------------------------------------------")
166  for loc in get_locations():
167  print("location '{}', room: '{}'".format(loc, get_room(loc)))
168 
169  print("\n-----------------------------------------------------------------------------")
170  print("Pick locations:")
171  for loc in get_locations(pick_location=True):
172  print(" {}".format(loc))
173 
174  print("\n-----------------------------------------------------------------------------")
175  print("Place locations:")
176  for loc in get_locations(place_location=True):
177  print(" {}".format(loc))
178 
179  print("\n-----------------------------------------------------------------------------")
180  print("None-manipulation locations:")
181  for loc in get_locations(pick_location=False, place_location=False):
182  print(" {}".format(loc))
common.get_inspect_position
def get_inspect_position(location, area="")
Definition: demo/common.py:103
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.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.get_object_names
def get_object_names(category=None)
Definition: reo2016/common.py:42