robocup_knowledge
rwc2016_common/common.py
Go to the documentation of this file.
1 # COMMON KNOWLEDGE FILE RWC2016A
2 from __future__ import print_function
3 
4 female_names = ["Emma", "Taylor", "Sophia", "Isabella", "Ava", "Robin", "Emily", "Angel", "Madison", "Charlotte"]
5 male_names = ["Noah", "Liam", "Mason", "Jacob", "William", "Ethan", "Michael", "Alexander", "James", "Daniel"]
6 names = female_names + male_names
7 
8 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
9 
10 locations = []
11 category_locations = {}
12 inspect_areas = {}
13 inspect_positions = {}
14 rooms = []
15 grab_locations = []
16 put_locations = []
17 
18 objects = [
19  { 'name' : 'choco_syrup', 'category' : 'candies' },
20  { 'name' : 'biscuits', 'category' : 'candies' },
21  { 'name' : 'baby_sweets', 'category' : 'candies' },
22  { 'name' : 'egg', 'category' : 'candies' },
23  { 'name' : 'chips', 'category' : 'snacks' },
24  { 'name' : 'pretzels', 'category' : 'snacks' },
25  { 'name' : 'pringles', 'category' : 'snacks' },
26  { 'name' : 'beer', 'category' : 'drinks' },
27  { 'name' : 'coconut_milk', 'category' : 'drinks' },
28  { 'name' : 'coke', 'category' : 'drinks' },
29  { 'name' : 'tea', 'category' : 'drinks' },
30  { 'name' : 'apple', 'category' : 'food' },
31  { 'name' : 'paprika', 'category' : 'food' },
32  { 'name' : 'pumper_nickel', 'category' : 'food' },
33  { 'name' : 'shampoo', 'category' : 'toiletries' },
34  { 'name' : 'soap', 'category' : 'toiletries' },
35  { 'name' : 'sponge', 'category' : 'toiletries' },
36  { 'name' : 'cloth', 'category' : 'toiletries' },
37  { 'name' : 'bowl', 'category' : 'containers' },
38  { 'name' : 'tray', 'category' : 'containers' },
39  { 'name' : 'plate', 'category' : 'containers' }
40 ]
41 
42 object_names = list(set([ o["name"] for o in objects ]))
43 object_categories = list(set([ o["category"] for o in objects ]))
44 
45 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46 
47 def is_location(location):
48  for loc in locations:
49  if loc["name"] == location:
50  return True
51  return False
52 
53 
54 def get_room(location):
55  for loc in locations:
56  if loc["name"] == location:
57  return loc["room"]
58  return None
59 
60 
61 def get_inspect_areas(location):
62  if location in inspect_areas:
63  return inspect_areas[location]
64  else:
65  return ["on_top_of"]
66 
67 
68 def get_inspect_position(location, area=""):
69  if location in inspect_positions and area in inspect_positions[location]:
70  return inspect_positions[location][area]
71  else:
72  return "in_front_of"
73 
74 
75 def is_pick_location(location):
76  for loc in locations:
77  if loc["name"] == location and loc["manipulation"] == "yes":
78  return True
79  return False
80 
81 
82 def is_place_location(location):
83  for loc in locations:
84  if loc["name"] == location and (loc["manipulation"] == "yes" or loc["manipulation"] == "only_putting"):
85  return True
86  return False
87 
88 
89 def get_locations(room=None, pick_location=None, place_location=None):
90  return [loc["name"] for loc in locations if (room is None or loc["room"] == room) and
91  (pick_location is None or pick_location == is_pick_location(loc["name"])) and
92  (place_location is None or place_location == is_place_location(loc["name"]))]
93 
94 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
95 
96 def get_objects(category=None):
97  return [obj["name"] for obj in objects
98  if category == None or category == obj["category"]]
99 
100 
102  for o in objects:
103  if o["name"] == obj:
104  return o["category"]
105  return None
106 
107 # Returns (location, area_name)
109  location, area_name = next(iter(category_locations[obj_cat].items()))
110  return location, area_name
111 
112 
113 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114 
116  print("\n-----------------------------------------------------------------------------")
117  for obj in get_objects():
118  cat = get_object_category(obj)
119  print("object '{}'".format(obj))
120  print(" category: '{}'".format(cat))
121  (location, area_name) = get_object_category_location(cat)
122  print(" found '{} {}'".format(area_name, location))
123 
124  print("\n-----------------------------------------------------------------------------")
125  for loc in get_locations():
126  print("location '{}', room: '{}'".format(loc, get_room(loc)))
127 
128  print("\n-----------------------------------------------------------------------------")
129  print("Pick locations:")
130  for loc in get_locations(pick_location=True):
131  print(" {}".format(loc))
132 
133  print("\n-----------------------------------------------------------------------------")
134  print("Place locations:")
135  for loc in get_locations(place_location=True):
136  print(" {}".format(loc))
137 
138 
139  print("\n-----------------------------------------------------------------------------")
140  print("None-manipulation locations:")
141  for loc in get_locations(pick_location=False, place_location=False):
142  print(" {}".format(loc))
robocup_knowledge.environments.rwc2016_common.common.get_object_category_location
def get_object_category_location(obj_cat)
Definition: rwc2016_common/common.py:108
robocup_knowledge.environments.rwc2016_common.common.get_locations
def get_locations(room=None, pick_location=None, place_location=None)
Definition: rwc2016_common/common.py:89
robocup_knowledge.environments.rwc2016_common.common.get_inspect_position
def get_inspect_position(location, area="")
Definition: rwc2016_common/common.py:68
robocup_knowledge.environments.rwc2016_common.common.get_objects
def get_objects(category=None)
Definition: rwc2016_common/common.py:96
robocup_knowledge.environments.rwc2016_common.common.is_location
def is_location(location)
Definition: rwc2016_common/common.py:47
robocup_knowledge.environments.rwc2016_common.common.is_pick_location
def is_pick_location(location)
Definition: rwc2016_common/common.py:75
robocup_knowledge.environments.rwc2016_common.common.get_object_category
def get_object_category(obj)
Definition: rwc2016_common/common.py:101
robocup_knowledge.environments.rwc2016_common.common.is_place_location
def is_place_location(location)
Definition: rwc2016_common/common.py:82
robocup_knowledge.environments.rwc2016_common.common.get_inspect_areas
def get_inspect_areas(location)
Definition: rwc2016_common/common.py:61
robocup_knowledge.environments.rwc2016_common.common.get_room
def get_room(location)
Definition: rwc2016_common/common.py:54
robocup_knowledge.environments.rwc2016_common.common.test_knowledge
def test_knowledge()
Definition: rwc2016_common/common.py:115