-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
71 lines (57 loc) · 1.48 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
import cherrypy
from threading import Thread
from networktables import NetworkTable
from time import sleep
import logging
import configparser
robot = 'roborio-2067-frc.local'
print("initializing")
logging.basicConfig(level=logging.DEBUG)
config = configparser.ConfigParser()
NetworkTable.setIPAddress(robot)
NetworkTable.setClientMode()
NetworkTable.initialize()
sd = NetworkTable.getTable('SmartDashboard')
print("waiting for robot at: " + robot)
class ScoutServer(object):
@cherrypy.expose
def index(self, COG_X="", COG_Y="", COG_BOX_SIZE=""):
if sd.isConnected():
if COG_X == "" or COG_BOX_SIZE == "":
COG_X = 0
COG_Y = 0
COG_BOX_SIZE = 0
sd.putNumber("COG_X", COG_X)
sd.putNumber("COG_Y", COG_Y)
sd.putNumber("COG_BOX_SIZE", COG_BOX_SIZE)
return "."
conf = {
'global': {
'server.socket_port': 8000
}
}
def start():
cherrypy.quickstart(ScoutServer(), '/', conf)
Thread(target=start).start() #launch http server in separate thread
while not sd.isConnected():
sleep(0.1)
print("now connected")
n = 0
while True:
if not sd.isConnected():
print("Waiting for connection")
sleep(1)
continue
n += 1
print("Config iteration " + str(n))
config.read("robot2016.ini")
for section in config.sections():
for key in list(config[section].keys()):
val = config[section][key]
try:
val = float(val)
except:
print("something broke")
print("Loading: " + section + "/" + key + ": " + str(val))
sd.putNumber(section + '/' + key, val)
sleep(1.5)