robocup_knowledge
rwc2023/common.py
Go to the documentation of this file.
1 from __future__ import print_function
2 
3 female_names = ["adel", "angel", "axel", "charlie", "jane", "jules", "morgan", "paris", "robin", "simone"]
4 male_names = ["adel", "angel", "axel", "charlie", "john", "jules", "morgan", "paris", "robin", "simone"]
5 names = set(female_names)
6 names.update(set(male_names))
7 names = sorted(list(names))
8 
9 locations = [
10  {"name": "bed", "room": "bedroom", "manipulation": False},
11  {"name": "bedside_table", "room": "bedroom", "manipulation": True},
12  {"name": "shelf", "room": "bedroom", "manipulation": True},
13  {"name": "trashbin", "room": "kitchen", "manipulation": False},
14  {"name": "dishwasher", "room": "kitchen", "manipulation": True},
15  {"name": "potted_plant", "room": "kitchen", "manipulation": False},
16  {"name": "kitchen_table", "room": "kitchen", "manipulation": True},
17  {"name": "pantry", "room": "kitchen", "manipulation": True},
18  {"name": "refrigerator", "room": "kitchen", "manipulation": True},
19  {"name": "sink", "room": "kitchen", "manipulation": True},
20  {"name": "cabinet", "room": "study", "manipulation": True},
21  {"name": "coatrack", "room": "study", "manipulation": False},
22  {"name": "desk", "room": "study", "manipulation": True},
23  {"name": "armchair", "room": "study", "manipulation": False},
24  {"name": "waste_basket", "room": "study", "manipulation": False},
25  {"name": "tv_stand", "room": "living_room", "manipulation": True},
26  {"name": "storage_rack", "room": "living_room", "manipulation": True},
27  {"name": "lamp", "room": "living_room", "manipulation": False},
28  {"name": "side_tables", "room": "living_room", "manipulation": True},
29  {"name": "sofa", "room": "living_room", "manipulation": True},
30  {"name": "bookshelf", "room": "living_room", "manipulation": True},
31 ]
32 
33 location_rooms = list(set([o["room"] for o in locations]))
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": "sponge", "category": "cleaning_supplies"},
39  {"name": "cleanser", "category": "cleaning_supplies"},
40  {"name": "red_wine", "category": "drinks"},
41  {"name": "juice_pack", "category": "drinks"},
42  {"name": "cola", "category": "drinks"},
43  {"name": "tropical_juice", "category": "drinks"},
44  {"name": "milk", "category": "drinks"},
45  {"name": "iced_tea", "category": "drinks"},
46  {"name": "orange_juice", "category": "drinks"},
47  {"name": "tuna", "category": "food"},
48  {"name": "tomato_soup", "category": "food"},
49  {"name": "spam", "category": "food"},
50  {"name": "mustard", "category": "food"},
51  {"name": "strawberry_jello", "category": "food"},
52  {"name": "chocolate_jello", "category": "food"},
53  {"name": "coffee_grounds", "category": "food"},
54  {"name": "sugar", "category": "food"},
55  {"name": "pear", "category": "fruits"},
56  {"name": "plum", "category": "fruits"},
57  {"name": "peach", "category": "fruits"},
58  {"name": "lemon", "category": "fruits"},
59  {"name": "orange", "category": "fruits"},
60  {"name": "strawberry", "category": "fruits"},
61  {"name": "banana", "category": "fruits"},
62  {"name": "apple", "category": "fruits"},
63  {"name": "tennis_ball", "category": "toys"},
64  {"name": "soccer_ball", "category": "toys"},
65  {"name": "rubiks_cube", "category": "toys"},
66  {"name": "dice", "category": "toys"},
67  {"name": "baseball", "category": "toys"},
68  {"name": "pringles", "category": "snacks"},
69  {"name": "cornflakes", "category": "snacks"},
70  {"name": "cheezit", "category": "snacks"},
71  {"name": "spoon", "category": "dishes"},
72  {"name": "plate", "category": "dishes"},
73  {"name": "cup", "category": "dishes"},
74  {"name": "fork", "category": "dishes"},
75  {"name": "bowl", "category": "dishes"},
76  {"name": "knife", "category": "dishes"},
77 ]
78 
79 object_names = list(set([o["name"] for o in objects]))
80 object_categories = list(set([o["category"] for o in objects]))
81 
82 category_locations = {
83  "cleaning_supplies": {"shelf": "on_top_of"},
84  "drinks": {"cabinet": "on_top_of"},
85  "food": {"pantry": "on_top_of"},
86  "fruits": {"desk": "on_top_of"},
87  "toys": {"bookshelf": "on_top_of"},
88  "snacks": {"side_tables": "on_top_of"},
89  "dishes": {"kitchen_table": "on_top_of"},
90 }
91 
92 inspect_areas = {
93  "pantry": ["shelf2", "shelf3"],
94 }
95 
96 inspect_positions = {
97  'kitchen_shelf': {
98  # 'shelf1_l': 'in_front_of_l',
99  # 'shelf2_l': 'in_front_of_l',
100  # 'shelf3_l': 'in_front_of_l',
101  # 'shelf4_l': 'in_front_of_l',
102  # 'shelf5_l': 'in_front_of_l',
103  # 'shelf1_r': 'in_front_of_r',
104  # 'shelf2_r': 'in_front_of_r',
105  'shelf3_r': 'in_front_of_r',
106  'shelf4_r': 'in_front_of_r',
107  # 'shelf5_r': 'in_front_of_r',
108  # 'on_top_of': 'in_front_of',
109  }
110 }
111 
112 drink_spec = "T['drink': O] -> OPTIONS[O]\n\n"
113 for drink in [obj["name"] for obj in objects if obj["category"] == "drinks"]:
114  drink_spec += "OPTIONS['{drink}'] -> {drink}\n".format(drink=drink)
115 
116 
117 def is_location(location):
118  for loc in locations:
119  if loc["name"] == location:
120  return True
121  return False
122 
123 
124 def get_room(location):
125  for loc in locations:
126  if loc["name"] == location:
127  return loc["room"]
128  return None
129 
130 
131 def is_room(entity_id):
132  return entity_id in location_rooms
133 
134 
135 def get_inspect_areas(location):
136  if location in inspect_areas:
137  return inspect_areas[location]
138  else:
139  return ["on_top_of"]
140 
141 
142 def get_inspect_position(location, area=""):
143  if location in inspect_positions and area in inspect_positions[location]:
144  return inspect_positions[location][area]
145  else:
146  return "in_front_of"
147 
148 
150  for loc in locations:
151  if loc["name"] == location and loc["manipulation"] == True:
152  return True
153  return False
154 
155 
156 def get_locations(room=None, manipulation_location=None):
157  return [loc["name"] for loc in locations
158  if (room == None or loc["room"] == room) and \
159  (manipulation_location == None or manipulation_location == is_manipulation_location(loc["name"]))]
160 
161 
162 def is_known_object(obj):
163  for o in objects:
164  if o["name"] == obj:
165  return True
166  return False
167 
168 
169 def get_objects(category=None):
170  return [obj["name"] for obj in objects
171  if category == None or category == obj["category"]]
172 
173 
174 def get_object_category(obj):
175  for o in objects:
176  if o["name"] == obj:
177  return o["category"]
178  return None
179 
180 def get_object_color(obj):
181  for o in objects:
182  if o["name"] == obj:
183  return o["color"]
184  return None
185 
186 def get_object_size(obj):
187  for o in objects:
188  if o["name"] == obj:
189  return o["volume"]
190  return None
191 
192 def get_object_weight(obj):
193  for o in objects:
194  if o["name"] == obj:
195  return o["weight"]
196  return None
197 
198 # Returns (location, area_name)
199 def get_object_category_location(obj_cat):
200  location, area_name = next(iter(category_locations[obj_cat].items()))
201  return location, area_name
common.get_inspect_position
def get_inspect_position(location, area="")
Definition: demo/common.py:103
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.is_manipulation_location
def is_manipulation_location(location)
Definition: rwc2023/common.py:149
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_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