-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlama_test.py
370 lines (316 loc) · 19 KB
/
lama_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#!/usr/bin/env python3
import os
import unittest
import pymongo as pm
import yaml
from ropod.structs.task import TaskRequest
from task_planner.lama_interface import LAMAInterface
def get_planner_config(config_file_path):
planner_config_params = None
with open(config_file_path, 'r') as config_file:
planner_config_params = yaml.load(config_file)
return planner_config_params
class LamaPlannerTest(unittest.TestCase):
@classmethod
def setUpClass(self):
self.test_kb_name = 'test_robot_store'
host, port = self._get_db_host_and_port()
self.client = pm.MongoClient(host=host, port=port)
planner_config_params = get_planner_config('../config/planner_config.yaml')
domain_file = planner_config_params['domain_file']
planner_cmd = planner_config_params['planner_cmd']
plan_file_path = planner_config_params['plan_file_path']
self.planner_interface = LAMAInterface(self.test_kb_name, domain_file,
planner_cmd, plan_file_path,
debug=True)
@classmethod
def tearDownClass(self):
self._drop_test_db()
def test_robot_cart_same_location_delivery_same_floor(self):
state_facts = [('empty_gripper', [('bot', 'frank')])]
state_fluents = [('robot_at', [('bot', 'frank')], 'PICKUP_LOCATION'),
('load_at', [('load', 'mobidik')], 'PICKUP_LOCATION')]
floor_facts = [('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR0')]),
('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR1')]),
('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR2')])]
floor_fluents = [('robot_floor', [('bot', 'frank')], 'floor0'),
('load_floor', [('load', 'mobidik')], 'floor0'),
('elevator_floor', [('elevator', 'toma_elevator')], 'unknown'),
('destination_floor', [('elevator', 'toma_elevator')], 'unknown'),
('location_floor', [('loc', 'PICKUP_LOCATION')], 'floor0'),
('location_floor', [('loc', 'DELIVERY_LOCATION')], 'floor0'),
('location_floor', [('loc', 'ELEVATOR0')], 'floor0'),
('location_floor', [('loc', 'ELEVATOR2')], 'floor2')]
self.planner_interface.kb_interface.insert_facts(state_facts)
self.planner_interface.kb_interface.insert_facts(floor_facts)
self.planner_interface.kb_interface.insert_fluents(state_fluents)
self.planner_interface.kb_interface.insert_fluents(floor_fluents)
task_request = TaskRequest()
task_request.load_id = 'mobidik'
task_request.delivery_pose.id = 'DELIVERY_LOCATION'
task_goals = [('load_at', [('load', task_request.load_id),
('loc', task_request.delivery_pose.id)]),
('empty_gripper', [('bot', 'frank')])]
plan_found, plan = self.planner_interface.plan(task_request, 'frank', task_goals)
self.planner_interface.kb_interface.remove_facts(state_facts)
self.planner_interface.kb_interface.remove_facts(floor_facts)
self.planner_interface.kb_interface.remove_fluents(state_fluents)
self.planner_interface.kb_interface.remove_fluents(floor_fluents)
assert plan_found
# the expected plan is:
# 1. DOCK
# 2. GOTO DELIVERY_LOCATION
# 3. UNDOCK
assert len(plan) == 3
expected_action_sequence = ['DOCK', 'GOTO', 'UNDOCK']
obtained_action_sequence = [action.type for action in plan]
assert expected_action_sequence == obtained_action_sequence
def test_robot_cart_same_location_delivery_diff_floor(self):
state_facts = [('empty_gripper', [('bot', 'frank')])]
state_fluents = [('robot_at', [('bot', 'frank')], 'PICKUP_LOCATION'),
('load_at', [('load', 'mobidik')], 'PICKUP_LOCATION')]
floor_facts = [('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR0')]),
('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR1')]),
('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR2')])]
floor_fluents = [('robot_floor', [('bot', 'frank')], 'floor0'),
('load_floor', [('load', 'mobidik')], 'floor0'),
('elevator_floor', [('elevator', 'toma_elevator')], 'unknown'),
('destination_floor', [('elevator', 'toma_elevator')], 'unknown'),
('location_floor', [('loc', 'PICKUP_LOCATION')], 'floor0'),
('location_floor', [('loc', 'DELIVERY_LOCATION')], 'floor2'),
('location_floor', [('loc', 'ELEVATOR0')], 'floor0'),
('location_floor', [('loc', 'ELEVATOR2')], 'floor2')]
self.planner_interface.kb_interface.insert_facts(state_facts)
self.planner_interface.kb_interface.insert_facts(floor_facts)
self.planner_interface.kb_interface.insert_fluents(state_fluents)
self.planner_interface.kb_interface.insert_fluents(floor_fluents)
task_request = TaskRequest()
task_request.load_id = 'mobidik'
task_request.delivery_pose.id = 'DELIVERY_LOCATION'
task_goals = [('load_at', [('load', task_request.load_id),
('loc', task_request.delivery_pose.id)]),
('empty_gripper', [('bot', 'frank')])]
plan_found, plan = self.planner_interface.plan(task_request, 'frank', task_goals)
self.planner_interface.kb_interface.remove_facts(state_facts)
self.planner_interface.kb_interface.remove_facts(floor_facts)
self.planner_interface.kb_interface.remove_fluents(state_fluents)
self.planner_interface.kb_interface.remove_fluents(floor_fluents)
assert plan_found
# the expected plan is:
# 1. DOCK
# 2. GOTO ELEVATOR0
# 3. REQUEST_ELEVATOR
# 4. WAIT_FOR_ELEVATOR
# 5. ENTER_ELEVATOR
# 6. WAIT_FOR_ELEVATOR
# 7. RIDE_ELEVATOR
# 8. EXIT_ELEVATOR
# 9. GOTO DELIVERY_LOCATION
# 10. UNDOCK
# though RIDE_ELEVATOR can also be followed by WAIT_FOR_ELEVATOR
assert len(plan) == 10
allowed_action_sequence1 = ['DOCK', 'GOTO', 'REQUEST_ELEVATOR', 'WAIT_FOR_ELEVATOR',
'ENTER_ELEVATOR', 'WAIT_FOR_ELEVATOR', 'RIDE_ELEVATOR',
'EXIT_ELEVATOR', 'GOTO', 'UNDOCK']
allowed_action_sequence2 = ['DOCK', 'GOTO', 'REQUEST_ELEVATOR', 'WAIT_FOR_ELEVATOR',
'ENTER_ELEVATOR', 'RIDE_ELEVATOR', 'WAIT_FOR_ELEVATOR',
'EXIT_ELEVATOR', 'GOTO', 'UNDOCK']
obtained_action_sequence = [action.type for action in plan]
assert (allowed_action_sequence1 == obtained_action_sequence) or\
(allowed_action_sequence2 == obtained_action_sequence)
def test_robot_cart_same_floor(self):
state_facts = [('empty_gripper', [('bot', 'frank')])]
state_fluents = [('robot_at', [('bot', 'frank')], 'CHARGING_STATION'),
('load_at', [('load', 'mobidik')], 'PICKUP_LOCATION')]
floor_facts = [('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR0')]),
('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR1')]),
('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR2')])]
floor_fluents = [('robot_floor', [('bot', 'frank')], 'floor0'),
('load_floor', [('load', 'mobidik')], 'floor0'),
('elevator_floor', [('elevator', 'toma_elevator')], 'unknown'),
('destination_floor', [('elevator', 'toma_elevator')], 'unknown'),
('location_floor', [('loc', 'CHARGING_STATION')], 'floor0'),
('location_floor', [('loc', 'PICKUP_LOCATION')], 'floor0'),
('location_floor', [('loc', 'DELIVERY_LOCATION')], 'floor0'),
('location_floor', [('loc', 'ELEVATOR0')], 'floor0'),
('location_floor', [('loc', 'ELEVATOR2')], 'floor0')]
self.planner_interface.kb_interface.insert_facts(state_facts)
self.planner_interface.kb_interface.insert_facts(floor_facts)
self.planner_interface.kb_interface.insert_fluents(state_fluents)
self.planner_interface.kb_interface.insert_fluents(floor_fluents)
task_request = TaskRequest()
task_request.load_id = 'mobidik'
task_request.delivery_pose.id = 'DELIVERY_LOCATION'
task_goals = [('load_at', [('load', task_request.load_id),
('loc', task_request.delivery_pose.id)]),
('empty_gripper', [('bot', 'frank')])]
plan_found, plan = self.planner_interface.plan(task_request, 'frank', task_goals)
self.planner_interface.kb_interface.remove_facts(state_facts)
self.planner_interface.kb_interface.remove_facts(floor_facts)
self.planner_interface.kb_interface.remove_fluents(state_fluents)
self.planner_interface.kb_interface.remove_fluents(floor_fluents)
assert plan_found
# the expected plan is:
# 1. GOTO PICKUP_LOCATION
# 2. DOCK
# 3. GOTO DELIVERY_LOCATION
# 4. UNDOCK
assert len(plan) == 4
expected_action_sequence = ['GOTO', 'DOCK', 'GOTO', 'UNDOCK']
obtained_action_sequence = [action.type for action in plan]
assert expected_action_sequence == obtained_action_sequence
def test_delivery_location_diff_floor(self):
state_facts = [('empty_gripper', [('bot', 'frank')])]
state_fluents = [('robot_at', [('bot', 'frank')], 'CHARGING_STATION'),
('load_at', [('load', 'mobidik')], 'PICKUP_LOCATION')]
floor_facts = [('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR0')]),
('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR1')]),
('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR2')])]
floor_fluents = [('robot_floor', [('bot', 'frank')], 'floor0'),
('load_floor', [('load', 'mobidik')], 'floor0'),
('elevator_floor', [('elevator', 'toma_elevator')], 'unknown'),
('destination_floor', [('elevator', 'toma_elevator')], 'unknown'),
('location_floor', [('loc', 'CHARGING_STATION')], 'floor0'),
('location_floor', [('loc', 'PICKUP_LOCATION')], 'floor0'),
('location_floor', [('loc', 'DELIVERY_LOCATION')], 'floor2'),
('location_floor', [('loc', 'ELEVATOR0')], 'floor0'),
('location_floor', [('loc', 'ELEVATOR2')], 'floor2')]
self.planner_interface.kb_interface.insert_facts(state_facts)
self.planner_interface.kb_interface.insert_facts(floor_facts)
self.planner_interface.kb_interface.insert_fluents(state_fluents)
self.planner_interface.kb_interface.insert_fluents(floor_fluents)
task_request = TaskRequest()
task_request.load_id = 'mobidik'
task_request.delivery_pose.id = 'DELIVERY_LOCATION'
task_goals = [('load_at', [('load', task_request.load_id),
('loc', task_request.delivery_pose.id)]),
('empty_gripper', [('bot', 'frank')])]
plan_found, plan = self.planner_interface.plan(task_request, 'frank', task_goals)
self.planner_interface.kb_interface.remove_facts(state_facts)
self.planner_interface.kb_interface.remove_facts(floor_facts)
self.planner_interface.kb_interface.remove_fluents(state_fluents)
self.planner_interface.kb_interface.remove_fluents(floor_fluents)
assert plan_found
# the expected plan is:
# 1. GOTO PICKUP_LOCATION
# 2. DOCK
# 3. GOTO ELEVATOR0
# 4. REQUEST_ELEVATOR floor0 floor2
# 5. WAIT_FOR_ELEVATOR
# 6. ENTER_ELEVATOR
# 7. WAIT_FOR_ELEVATOR
# 8. RIDE_ELEVATOR
# 9. EXIT_ELEVATOR
# 10. GOTO DELIVERY_LOCATION
# 11. UNDOCK
# though RIDE_ELEVATOR can also be followed by WAIT_FOR_ELEVATOR
assert len(plan) == 11
allowed_action_sequence1 = ['GOTO', 'DOCK', 'GOTO', 'REQUEST_ELEVATOR',
'WAIT_FOR_ELEVATOR', 'ENTER_ELEVATOR',
'WAIT_FOR_ELEVATOR', 'RIDE_ELEVATOR',
'EXIT_ELEVATOR', 'GOTO', 'UNDOCK']
allowed_action_sequence2 = ['GOTO', 'DOCK', 'GOTO', 'REQUEST_ELEVATOR',
'WAIT_FOR_ELEVATOR', 'ENTER_ELEVATOR',
'RIDE_ELEVATOR', 'WAIT_FOR_ELEVATOR',
'EXIT_ELEVATOR', 'GOTO', 'UNDOCK']
obtained_action_sequence = [action.type for action in plan]
assert (allowed_action_sequence1 == obtained_action_sequence) or\
(allowed_action_sequence2 == obtained_action_sequence)
def test_robot_cart_diff_floors(self):
state_facts = [('empty_gripper', [('bot', 'frank')])]
state_fluents = [('robot_at', [('bot', 'frank')], 'CHARGING_STATION'),
('load_at', [('load', 'mobidik')], 'PICKUP_LOCATION')]
floor_facts = [('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR0')]),
('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR1')]),
('elevator_at', [('elevator', 'toma_elevator'), ('loc', 'ELEVATOR2')])]
floor_fluents = [('robot_floor', [('bot', 'frank')], 'floor0'),
('load_floor', [('load', 'mobidik')], 'floor2'),
('elevator_floor', [('elevator', 'toma_elevator')], 'unknown'),
('destination_floor', [('elevator', 'toma_elevator')], 'unknown'),
('location_floor', [('loc', 'CHARGING_STATION')], 'floor0'),
('location_floor', [('loc', 'PICKUP_LOCATION')], 'floor2'),
('location_floor', [('loc', 'DELIVERY_LOCATION')], 'floor1'),
('location_floor', [('loc', 'ELEVATOR0')], 'floor0'),
('location_floor', [('loc', 'ELEVATOR1')], 'floor1'),
('location_floor', [('loc', 'ELEVATOR2')], 'floor2')]
self.planner_interface.kb_interface.insert_facts(state_facts)
self.planner_interface.kb_interface.insert_facts(floor_facts)
self.planner_interface.kb_interface.insert_fluents(state_fluents)
self.planner_interface.kb_interface.insert_fluents(floor_fluents)
task_request = TaskRequest()
task_request.load_id = 'mobidik'
task_request.delivery_pose.id = 'DELIVERY_LOCATION'
task_goals = [('load_at', [('load', task_request.load_id),
('loc', task_request.delivery_pose.id)]),
('empty_gripper', [('bot', 'frank')])]
plan_found, plan = self.planner_interface.plan(task_request, 'frank', task_goals)
self.planner_interface.kb_interface.remove_facts(state_facts)
self.planner_interface.kb_interface.remove_facts(floor_facts)
self.planner_interface.kb_interface.remove_fluents(state_fluents)
self.planner_interface.kb_interface.remove_fluents(floor_fluents)
assert plan_found
# the expected plan is:
# 1. GOTO ELEVATOR0
# 2. REQUEST_ELEVATOR floor0 floor2
# 3. WAIT_FOR_ELEVATOR
# 4. ENTER_ELEVATOR
# 5. WAIT_FOR_ELEVATOR
# 6. RIDE_ELEVATOR
# 7. EXIT_ELEVATOR
# 8. GOTO PICKUP_LOCATION
# 9. DOCK
# 10. GOTO ELEVATOR2
# 11. REQUEST_ELEVATOR floor2 floor1
# 12. WAIT_FOR_ELEVATOR
# 13. ENTER_ELEVATOR
# 14. WAIT_FOR_ELEVATOR
# 15. RIDE_ELEVATOR
# 16. EXIT_ELEVATOR
# 17. GOTO DELIVERY_LOCATION
# 18. UNDOCK
# though RIDE_ELEVATOR can also be followed by WAIT_FOR_ELEVATOR
assert len(plan) == 18
allowed_action_sequence1 = ['GOTO', 'REQUEST_ELEVATOR', 'WAIT_FOR_ELEVATOR',
'ENTER_ELEVATOR', 'WAIT_FOR_ELEVATOR', 'RIDE_ELEVATOR',
'EXIT_ELEVATOR', 'GOTO', 'DOCK', 'GOTO',
'REQUEST_ELEVATOR', 'WAIT_FOR_ELEVATOR', 'ENTER_ELEVATOR',
'WAIT_FOR_ELEVATOR', 'RIDE_ELEVATOR', 'EXIT_ELEVATOR',
'GOTO', 'UNDOCK']
allowed_action_sequence2 = ['GOTO', 'REQUEST_ELEVATOR', 'WAIT_FOR_ELEVATOR',
'ENTER_ELEVATOR', 'RIDE_ELEVATOR', 'WAIT_FOR_ELEVATOR',
'EXIT_ELEVATOR', 'GOTO', 'DOCK', 'GOTO',
'REQUEST_ELEVATOR', 'WAIT_FOR_ELEVATOR', 'ENTER_ELEVATOR',
'WAIT_FOR_ELEVATOR', 'RIDE_ELEVATOR', 'EXIT_ELEVATOR',
'GOTO', 'UNDOCK']
allowed_action_sequence3 = ['GOTO', 'REQUEST_ELEVATOR', 'WAIT_FOR_ELEVATOR',
'ENTER_ELEVATOR', 'WAIT_FOR_ELEVATOR', 'RIDE_ELEVATOR',
'EXIT_ELEVATOR', 'GOTO', 'DOCK', 'GOTO',
'REQUEST_ELEVATOR', 'WAIT_FOR_ELEVATOR', 'ENTER_ELEVATOR',
'RIDE_ELEVATOR', 'WAIT_FOR_ELEVATOR', 'EXIT_ELEVATOR',
'GOTO', 'UNDOCK']
allowed_action_sequence4 = ['GOTO', 'REQUEST_ELEVATOR', 'WAIT_FOR_ELEVATOR',
'ENTER_ELEVATOR', 'RIDE_ELEVATOR', 'WAIT_FOR_ELEVATOR',
'EXIT_ELEVATOR', 'GOTO', 'DOCK', 'GOTO',
'REQUEST_ELEVATOR', 'WAIT_FOR_ELEVATOR', 'ENTER_ELEVATOR',
'RIDE_ELEVATOR', 'WAIT_FOR_ELEVATOR', 'EXIT_ELEVATOR',
'GOTO', 'UNDOCK']
obtained_action_sequence = [action.type for action in plan]
assert (allowed_action_sequence1 == obtained_action_sequence) or\
(allowed_action_sequence2 == obtained_action_sequence) or\
(allowed_action_sequence3 == obtained_action_sequence) or\
(allowed_action_sequence4 == obtained_action_sequence)
@classmethod
def _drop_test_db(self):
if self.test_kb_name in self.client.list_database_names():
self.client.drop_database(self.test_kb_name)
@classmethod
def _get_db_host_and_port(self):
host = 'localhost'
port = 27017
if 'DB_HOST' in os.environ:
host = os.environ['DB_HOST']
if 'DB_PORT' in os.environ:
port = int(os.environ['DB_PORT'])
return (host, port)
if __name__ == '__main__':
unittest.main()