-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
90 lines (75 loc) · 2.23 KB
/
server.js
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
const _ = require('lodash')
const chalk = require('chalk')
const assert = require('assert')
const comm = require('./lib/Comm.js')
require('draftlog').into(console)
const Match = require('./lib/Match')
const TAG = 'server'
const RUN_MODES = {
1: 'REAL_LIFE', 2: 'SIMPLE_SIMULATED',
3: 'SIMULATED', 4: 'PASSIVE'
}
const run_mode = parseInt(process.env.RUN_MODE)
console.log(run_mode)
assert.notEqual(run_mode, null, chalk.red('MISSING PARAMETER: RUN_MODE'))
assert.ok(run_mode in RUN_MODES, chalk.red('WRONG PARAMETER: RUN_MODE, must be 1, 2 or 3'))
async function startup(){
console.info(TAG, chalk.yellow('Startup'))
console.info(TAG, chalk.yellow('Run mode: '), chalk.green(RUN_MODES[run_mode]))
const config = require('./config.json')
let visionImpl = null
let driverImpl = null
let MatchClass = Match
let CoachClass = require('./lib/DumbCoach')
switch (run_mode) {
case 1:
visionImpl = 'ssl-vision'
driverImpl = 'serial-driver'
break
case 2:
visionImpl = 'simple-simulation-vision'
driverImpl = 'simple-simulation-driver'
break
case 3:
visionImpl = 'vss-vision'
driverImpl = 'vss-driver'
break
case 4:
visionImpl = 'ssl-vision'
driverImpl = 'mock-driver'
break
default:
visionImpl = config.vision
driverImpl = config.driver
}
let match = new MatchClass({
// Vision: Dados referentes ao input de dados da visão
// Coach: Dados de configuração do Coach que ira orquestrar a partida
// Driver: dados referentes ao output de dados de envio para os robos
vision: {impl: visionImpl, params: config[visionImpl]},
driver: {impl: driverImpl, params: config[driverImpl]},
coaches: [CoachClass],
matchParams: {
'startSide': config.startSide,
'startColor': config.startColor
},
robotsProperties:[
{
// TEAM 1
robot_2: {vision_id: 3, radio_id: 1},
robot_3: {vision_id: 9, radio_id: 3},
robot_1: {vision_id: 1, radio_id: 2}
},
{
}
]
})
await match.init()
await comm(match, {PORT:8080})
}
// process.on('unhandledRejection', (e) => {
// console.error('Unhandled Rejection')
// console.error(e)
// process.exit(1)
// })
startup()