forked from Arena-Rosnav/arena-rosnav
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
132 lines (104 loc) · 4.76 KB
/
run.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
import os
import subprocess
import socketio
import json
import random
from fileCreator import FileCreator
base_path = "~/arena_ws"
taskId = os.getenv('taskId')
tasktype = os.getenv('type')
url = os.getenv('url')
files_recieved = False
def startTask(data):
dataObj = json.load(data)
msg_taskId = dataObj.get('taskId')
if taskId != msg_taskId:
return
print('Recieved files! Starting file creation')
f = FileCreator(base_path)
if(tasktype == 'training'):
f.createRobotFiles(data)
f.createWorldFile(data)
f.createHyperparamsFile(data)
elif(tasktype == 'evaluation'):
f.createRobotFiles(data)
f.createWorldFile(data)
f.createScenarioFile(data)
elif(tasktype == 'benchmark'):
f.createRobotFiles(data)
f.createWorldFile(data)
f.createScenarioFile(data)
else:
f.createPlotFile(data)
print('Files created. Starting Arena-Rosnav')
files_recieved = True
if not (taskId or tasktype or url):
print('Environment variables are not set. Exiting...')
exit
sio = socketio.Client()
sio.connect(url=url,transports="websocket")
sio.on('configTransmission', startTask)
sio.emit('configRequest', {'taskId', taskId})
print('Waiting for config files')
while True:
if files_recieved:
break
if(tasktype == 'training'):
model = os.getenv('model')
subprocess.Popen(f"roslaunch arena_bringup start_training.launch map_folder_name:=dynamic_map model:={model} num_envs:=1 entity_manager:=pedsim", shell=True)
training = subprocess.Popen(f'poetry shell && python3 training/scripts/train_agent.py', shell=True, cwd="{base_path}/src/arena/arena-rosnav")
training.wait()
modelstring = ''
f = FileCreator(base_path)
for x in os.listdir(f'{base_path}/planners/rosnav/agents'):
if x.startswith(f'{model}_RosnavResNet_5_norm'):
modelstring = x
zip64 = f.createBase64Zip(f"{base_path}/planners/rosnav/agents/{modelstring}")
response = {
"taskId": taskId,
"data": zip64,
}
elif(tasktype == 'evaluation'):
model = os.getenv('model')
planner = os.getenv('planner')
subprocess.run(f"roslaunch arena_bringup start_arena.launch visualization:=none tm_robots:=scenario tm_obstacles:=scenario model:={model} local_planner:={planner} map_file:=map_custom record_data:=true", shell=True)
f = FileCreator(base_path)
items = os.listdir(f'{base_path}/src/arena/evaluation/arena-evaluation/data')
parentFolder = items[0]
zip64 = f.createBase64Zip(f"{base_path}/src/arena/evaluation/arena-evaluation/data/{parentFolder}")
response = {
"taskId": taskId,
"data": zip64,
}
elif(tasktype == 'benchmark'):
model = os.getenv('model')
planner = os.getenv('planner')
subprocess.run(f"roslaunch arena_bringup start_arena.launch tm_robots:=scenario tm_obstacles:=scenario model:={model} local_planner:={planner} map_file:=map_custom record_data:=true", shell=True)
f = FileCreator(base_path)
items = os.listdir(f'{base_path}/src/arena/evaluation/arena-evaluation/data')
parentFolder = items[0]
items = os.listdir(f"{base_path}/src/arena/evaluation/arena-evaluation/data/{parentFolder}")
dataFolder = items[0]
# TODO: Arena-Rosnav currently works on get_metrics. Finish when released
#subprocess.run(f"source ./devel/setup.sh && python3 {base_path}/src/arena/evaluation/arena-evaluation/scripts/get_metrics.py {base_path}/src/arena/evaluation/arena-evaluation/data/{parentFolder}/{dataFolder}")
zip64 = f.createBase64Zip(f"{base_path}/src/arena/evaluation/arena-evaluation/data/{parentFolder}")
# avgCollisions = f.getAvgCollisions(f"{base_path}/src/arena/evaluation/arena-evaluation/data/{parentFolder}/{dataFolder}/metrics.py")
# bestTime = f.getBestTime(f"{base_path}/src/arena/evaluation/arena-evaluation/data/{parentFolder}/{dataFolder}/metrics.py")
response = {
"taskId": taskId,
"data": zip64,
"best_time": random.randint(20, 160), # TODO: PLACEHOLDER RANDOM NUMBER! Finish when Arena-Rosnav functionalities are back
"avg_collisions": random.randint(0, 5), # TODO: PLACEHOLDER RANDOM NUMBER! Finish when Arena-Rosnav functionalities are back
}
else:
# TODO: Arena-Rosnav currently works on create_plots. Finish when released
#subprocess.run(f"source ./devel/setup.sh && python3 {base_path}/src/arena/evaluation/arena-evaluation/scripts/create_plots.py plot.yaml", shell=True)
f = FileCreator(base_path)
zip64 = f.createBase64Zip(f"{base_path}/src/arena/evaluation/arena-evaluation/plots")
response = {
"taskId": taskId,
"data": zip64,
}
print('Arena-Rosnav finished. Sending back data')
json_response = json.dumps(response)
sio.emit("taskFinished", json_response)