forked from project-neon/NeonFC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
73 lines (61 loc) · 2.08 KB
/
main.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
import os
import api
import comm
import vision
import match
import argparse
import fields as pitch
from commons.utils import get_config
parser = argparse.ArgumentParser(description='NeonFC')
parser.add_argument('--config_file', default='config.json')
args = parser.parse_args()
class Game():
def __init__(self, config_file=None):
self.config = get_config(config_file)
self.match = match.Match(self,
**self.config.get('match')
)
self.vision = vision.FiraVision()
self.comm = comm.FiraComm()
self.referee = comm.RefereeComm()
self.data_sender = api.DataSender()
self.field = pitch.Field(self.match.category)
if os.environ.get('USE_DATA_SENDER'):
self.use_data_sender = bool(int(os.environ.get('USE_DATA_SENDER')))
else:
self.use_data_sender = self.config.get('data_sender', False)
if os.environ.get('USE_REFEREE'):
self.use_referee = bool(int(os.environ.get('USE_REFEREE')))
else:
self.use_referee = self.config.get('referee')
self.start()
def start(self):
self.vision.assign_vision(self)
self.match.start()
self.vision.start()
self.comm.start()
self.referee.start()
self.data_sender.start()
def update(self):
frame = vision.assign_empty_values(
self.vision.frame,
color=self.match.team_color,
field_size=self.field.get_dimensions()
)
self.match.update(frame)
commands = self.match.decide()
if self.referee.can_play or (not self.use_referee):
self.comm.send(commands)
else:
commands = [
{
'robot_id': r['robot_id'],
'color': r['color'],
'wheel_left': 0,
'wheel_right': 0
} for r in commands
]
self.comm.send(commands)
if self.use_data_sender:
api.DataSender().send_data()
g = Game(config_file=args.config_file)