-
Notifications
You must be signed in to change notification settings - Fork 0
/
Robot_with_Listener.py
49 lines (38 loc) · 1.25 KB
/
Robot_with_Listener.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
import time
from pynetworktables import *
SmartDashboard.init()
table = NetworkTable.GetTable("datatable")
class Listener(ITableListener):
def __init__(self):
ITableListener.__init__(self)
def ValueChanged(self, table, key, value, isNew):
print('Value changed: key %s, isNew: %s: %s' % (key, isNew, table.GetValue(key)))
listener = Listener()
table.AddTableListener(listener)
ready = False
connection = False
connectString = 'l'
redAlliance = True
while True:
if not ready:
try:
table.PutBoolean("connection", connection)
ready = True
except TableKeyNotDefinedException:
time.sleep(0.1)
connectString = raw_input("Connect or change alliance? Y/N; R/B: ")
if connectString == 'y' or connectString == 'Y':
connection = True
ready = False
elif connectString == 'n' or connectString == 'N':
connection = False
ready = False
elif connectString == 'r' or connectString == 'R':
redAlliance = True
elif connectString == 'b' or connectString == 'B':
redAlliance = False
try:
table.PutBoolean("allianceRed", redAlliance)
except TableKeyNotDefinedException:
time.sleep(0.1)
time.sleep(0.01)