-
Notifications
You must be signed in to change notification settings - Fork 1
/
crash.py
85 lines (76 loc) · 3.19 KB
/
crash.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
from transport_challenge import Transport
import pickle
import gym
import requests
import json
import random
def create_tdw(port):
url = "http://localhost:5000/get_tdw"
data = {
'ip_address': "localhost",
'port': port
}
response = requests.post(url, json=json.dumps(data))
print(response.status_code, response.reason)
docker_id = response.json()['docker_id']
return docker_id
def kill_tdw(docker_id):
url = "http://localhost:5000/kill_tdw"
data = {
"container_id": docker_id
}
response = requests.post(url, json=json.dumps(data))
print(response.status_code, response.reason)
if __name__ == '__main__':
port = 1090
docker_id = create_tdw(port = port)
try:
m = Transport(port=port, launch_build=False, \
screen_width=128, screen_height=128, fov = 90)
#path = './to_send/tdw_crash/submissions_4/actions_history.pickle'
path = 'action.pkl'
with open(path, 'rb') as f:
data = pickle.load(f)
n = len(data)
print('done')
scene_info, actions = data['scene_info'], data['actions']
m.init_scene(scene = scene_info['scene'], \
layout = scene_info['layout'], \
random_seed = scene_info['seed'])
m.communicate([{"$type": "set_floorplan_roof", "show": False}])
x, y, z = m.state.magnebot_transform.position
print('init:', m.state.magnebot_transform.position, m.state.magnebot_transform.forward)
m.turn_by(angle=-15, aligned_at=2)
print('second:', m.state.magnebot_transform.position, m.state.magnebot_transform.forward)
assert False
#m.add_camera({"x": x, "y": 5, "z": z}, look_at=True, follow=True)
i = 0
for action in actions:
i += 1
if action['type'] == 0:
status = m.move_by(0.5, arrived_at = 0.1)
elif action['type'] == 1:
status = m.turn_by(angle=-15, aligned_at=2)
elif action['type'] == 2:
status = m.turn_by(angle=15, aligned_at=2)
#elif action['type'] == 3:
# m.move_to(int(action['object']))
print(f'execute step: {i}, action: {action["type"]}, status: {status}')
'''for episode in data.keys():
scene_info, actions = data[episode]['seed'], data[episode]['actions']
m.init_scene(scene = scene_info['scene'], \
layout = scene_info['layout'], \
random_seed = scene_info['seed'])
i = 0
print('episode: {}, length: {}'.format(episode, len(actions)))
for action in actions:
i += 1
if action['type'] == 0:
status = m.move_by(0.5, arrived_at = 0.1)
elif action['type'] == 1:
status = m.turn_by(angle=-15, aligned_at=2)
else:
status = m.turn_by(angle=15, aligned_at=2)
'''
finally:
kill_tdw(docker_id)