-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
59 lines (47 loc) · 1.86 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
from networktables import NetworkTables, NetworkTablesInstance
import json
import threading
teamNumber = 540
version = "1.0.0"
def main():
connection_condition = threading.Condition()
# define notified as a list variable b/c python cannot access
# primitive types from methods and lists are considered objects. Python sucks balls.
connection_notified = [False]
def connectionListener(isConnected: bool, info):
print(info, '; Connected=%s' % isConnected)
with connection_condition:
connection_notified[0] = True
connection_condition.notify()
NetworkTables.startClientTeam(team=teamNumber)
NetworkTables.addConnectionListener(
connectionListener, immediateNotify=True)
with connection_condition:
print("Waiting for connection to NetworkTables")
if not connection_notified[0]:
connection_condition.wait()
# Get the Default Table
talon_table = NetworkTablesInstance.getDefault().getTable(key='Talon')
# put the current version of the system, useful for debugging
talon_table.putString("version", version)
# put object specific data in a specific table, useful for multi-state changes
object_data_table = talon_table.getSubTable('detection')
# whatever bs ayush pal code
example_raw_data = {
"predictions": [
{
"x": 191,
"y": 285,
"width": 204,
"height": 212,
"confidence": 0.878,
"class": "cones"
}
]
}
example_latency_ms = 23
object_data_table.putNumber("latency", example_latency_ms)
# I can reconvert this in client code, this allows me to have acess to all of the raw data I could need
object_data_table.putString("rawData", json.dumps(example_raw_data))
if __name__ == "__main__":
main()