robocup_knowledge
rwc2022/common.py
Go to the documentation of this file.
1 from __future__ import print_function
2 
3 female_names = ["amelia", "angel", "ava", "charlie", "charlotte", "hunter", "max", "mia", "olivia", "parker", "sam"]
4 male_names = ["angel", "charlie", "hunter", "jack", "max", "noah", "oliver", "parker", "sam", "thomas", "william"]
5 names = female_names + male_names
6 
7 locations = [
8  {"name": "house_plant", "room": "living_room", "manipulation": False},
9  {"name": "coat_rack", "room": "living_room", "manipulation": False},
10  {"name": "sofa", "room": "living_room", "manipulation": False},
11  {"name": "couch_table", "room": "living_room", "manipulation": True},
12  {"name": "tv", "room": "living_room", "manipulation": False},
13  {"name": "side_table", "room": "living_room", "manipulation": True},
14  {"name": "book_shelf", "room": "living_room", "manipulation": True},
15  {"name": "kitchen_shelf", "room": "kitchen", "manipulation": True},
16  {"name": "pantry", "room": "kitchen", "manipulation": True},
17  {"name": "dinner_table", "room": "kitchen", "manipulation": True},
18  {"name": "kitchen_bin", "room": "kitchen", "manipulation": True},
19  {"name": "fridge", "room": "kitchen", "manipulation": True},
20  {"name": "washing_machine", "room": "kitchen", "manipulation": True},
21  {"name": "sink", "room": "kitchen", "manipulation": False},
22  {"name": "small_shelf", "room": "bedroom", "manipulation": True},
23  {"name": "cupboard", "room": "bedroom", "manipulation": True},
24  {"name": "big_shelf", "room": "bedroom", "manipulation": True},
25  {"name": "bed", "room": "bedroom", "manipulation": False},
26  {"name": "desk", "room": "office", "manipulation": True},
27  {"name": "show_rack", "room": "office", "manipulation": False},
28  {"name": "bin", "room": "office", "manipulation": False},
29  {"name": "office_shelf", "room": "office", "manipulation": True},
30 ]
31 
32 location_rooms = list(set([o["room"] for o in locations]))
33 rooms = location_rooms
34 location_names = list(set([o["name"] for o in locations]))
35 manipulation_locations = list(set([o["name"] for o in locations if o["manipulation"]]))
36 
37 objects = [
38  {'name': 'water', 'category': 'drink'},
39  {'name': 'milk', 'category': 'drink'},
40  {'name': 'coke', 'category': 'drink'},
41  {'name': 'tonic', 'category': 'drink'},
42  {'name': 'bubble_tea', 'category': 'drink'},
43  {'name': 'ice_tea', 'category': 'drink'},
44  {'name': 'cloth', 'category': 'cleaning_supply'},
45  {'name': 'sponge', 'category': 'cleaning_supply'},
46  {'name': 'cleaner', 'category': 'cleaning_supply'},
47  {'name': 'corn_flakes', 'category': 'pantry_item'},
48  {'name': 'tuna_can', 'category': 'pantry_item'},
49  {'name': 'coffee_jar', 'category': 'pantry_item'},
50  {'name': 'sugar', 'category': 'pantry_item'},
51  {'name': 'mustard', 'category': 'pantry_item'},
52  {'name': 'apple', 'category': 'fruit'},
53  {'name': 'peach', 'category': 'fruit'},
54  {'name': 'orange', 'category': 'fruit'},
55  {'name': 'banana', 'category': 'fruit'},
56  {'name': 'strawberry', 'category': 'fruit'},
57  {'name': 'pockys', 'category': 'snack'},
58  {'name': 'pringles', 'category': 'snack'},
59  {'name': 'spoon', 'category': 'cutlery'},
60  {'name': 'fork', 'category': 'cutlery'},
61  {'name': 'plate', 'category': 'cutlery'},
62  {'name': 'bowl', 'category': 'cutlery'},
63  {'name': 'mug', 'category': 'cutlery'},
64  {'name': 'knife', 'category': 'cutlery'},
65 ]
66 
67 object_names = list(set([o["name"] for o in objects]))
68 object_categories = list(set([o["category"] for o in objects]))
69 
70 category_locations = {
71  "fruit": {"couch_table": "on_top_of"},
72  "drink": {"side_table": "on_top_of"},
73  "pantry_item": {"pantry": "on_top_of"},
74  "cutlery": {"dinner_table": "on_top_of"},
75  "cleaning_supply": {"small_shelf": "on_top_of"},
76  "snack": {"desk": "on_top_of"}
77 }
78 
79 inspect_areas = {
80  "kitchen_shelf": ["shelf2_r", "shelf3_r", "shelf4_r"],
81 }
82 
83 inspect_positions = {
84  'kitchen_shelf': {
85  # 'shelf1_l': 'in_front_of_l',
86  # 'shelf2_l': 'in_front_of_l',
87  # 'shelf3_l': 'in_front_of_l',
88  # 'shelf4_l': 'in_front_of_l',
89  # 'shelf5_l': 'in_front_of_l',
90  # 'shelf1_r': 'in_front_of_r',
91  # 'shelf2_r': 'in_front_of_r',
92  'shelf3_r': 'in_front_of_r',
93  'shelf4_r': 'in_front_of_r',
94  # 'shelf5_r': 'in_front_of_r',
95  # 'on_top_of': 'in_front_of',
96  }
97 }
98 
99 drink_spec = "T['drink': O] -> OPTIONS[O]\n\n"
100 for drink in [obj["name"] for obj in objects if obj["category"] == "drink"]:
101  drink_spec += "OPTIONS['{drink}'] -> {drink}\n".format(drink=drink)
102 
103 
104 def is_location(location):
105  for loc in locations:
106  if loc["name"] == location:
107  return True
108  return False
109 
110 
111 def get_room(location):
112  for loc in locations:
113  if loc["name"] == location:
114  return loc["room"]
115  return None
116 
117 
118 def is_room(entity_id):
119  return (entity_id in rooms)
120 
121 
122 def get_inspect_areas(location):
123  if location in inspect_areas:
124  return inspect_areas[location]
125  else:
126  return ["on_top_of"]
127 
128 
129 def get_inspect_position(location, area=""):
130  if location in inspect_positions and area in inspect_positions[location]:
131  return inspect_positions[location][area]
132  else:
133  return "in_front_of"
134 
135 
136 def is_pick_location(location):
137  for loc in locations:
138  if loc["name"] == location and loc["manipulation"] == "yes":
139  return True
140  return False
141 
142 
143 def is_place_location(location):
144  for loc in locations:
145  if loc["name"] == location and (loc["manipulation"] == "yes" or loc["manipulation"] == "only_putting"):
146  return True
147  return False
148 
149 
150 def get_locations(room=None, pick_location=None, place_location=None):
151  return [loc["name"] for loc in locations
152  if (room == None or loc["room"] == room) and \
153  (pick_location == None or pick_location == is_pick_location(loc["name"])) and \
154  (place_location == None or place_location == is_place_location(loc["name"]))]
155 
156 
157 def is_known_object(obj):
158  for o in objects:
159  if o["name"] == obj:
160  return True
161  return False
162 
163 
164 def get_objects(category=None):
165  return [obj["name"] for obj in objects
166  if category == None or category == obj["category"]]
167 
168 
169 def get_object_category(obj):
170  for o in objects:
171  if o["name"] == obj:
172  return o["category"]
173  return None
174 
175 def get_object_color(obj):
176  for o in objects:
177  if o["name"] == obj:
178  return o["color"]
179  return None
180 
181 def get_object_size(obj):
182  for o in objects:
183  if o["name"] == obj:
184  return o["volume"]
185  return None
186 
187 def get_object_weight(obj):
188  for o in objects:
189  if o["name"] == obj:
190  return o["weight"]
191  return None
192 
193 # Returns (location, area_name)
194 def get_object_category_location(obj_cat):
195  location, area_name = next(iter(category_locations[obj_cat].items()))
196  return location, area_name
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_object_weight
def get_object_weight(obj)
Definition: impuls/common.py:240
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.get_object_size
def get_object_size(obj)
Definition: impuls/common.py:234
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.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
common.is_known_object
def is_known_object(obj)
Definition: impuls/common.py:211