-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.py
More file actions
51 lines (39 loc) · 1.21 KB
/
controller.py
File metadata and controls
51 lines (39 loc) · 1.21 KB
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
import sys
import communication
import time
import json
import internal_logic
from controller_config import config
import client as cl
# Arguably dangerous to assume these exist, but OK to crash if they don't
# since these values are necessary
version = config['controller']['version']
controller_id = config['controller']['id']
if len(sys.argv)>1:
controller_id = sys.argv[1]
req = communication.Requester(controller_id, version)
def control_loop():
ply_count = 0
while True:
t0 = time.time()
r = req.sendResponse(ply_count)
if r.status_code == 200:
t1 = time.time()
print("Got response: {}s".format(t1 - t0))
jsonfile = r.json()
print(jsonfile)
for actions, i in enumerate(jsonfile["history"]):
ply_count = internal_logic.parseJson(jsonfile["history"][actions],ply_count)
r = req.sendResponse(ply_count)
print(r)
time.sleep(10)
t2 = time.time()
print("Took: {}s".format(t2 - t0))
print("\n")
try:
control_loop()
except KeyboardInterrupt:
internal_logic.close()
sys.exit(0)
# Close robot connection
internal_logic.close()