-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot_sim.py
More file actions
43 lines (35 loc) · 1.21 KB
/
robot_sim.py
File metadata and controls
43 lines (35 loc) · 1.21 KB
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
#!/usr/bin/env python3
# modified from: https://github.com/robotpy/pynetworktables/blob/master/samples/nt_robot.py
#
# This is a NetworkTables server (eg, the robot or simulator side).
#
# On a real robot, you probably would create an instance of the
# wpilib.SmartDashboard object and use that instead -- but it's really
# just a passthru to the underlying NetworkTable object.
#
# When running, this will continue incrementing the value 'robotTime',
# and the value should be visible to networktables clients such as
# SmartDashboard. To view using the SmartDashboard, you can launch it
# like so:
#
# SmartDashboard.jar ip 127.0.0.1
#
import time
from networktables import NetworkTable
# To see messages from networktables, you must setup logging
import logging
logging.basicConfig(level=logging.DEBUG)
sd = NetworkTable.getTable("SmartDashboard")
sd.putString("omg", "")
def valueChanged(table, key, value, isNew):
print("valueChanged: key: '%s'; value: %s; isNew: %s" % (key, value, isNew))
sd.addTableListener(valueChanged)
i = 0
while True:
try:
print('dsTime:', sd.getNumber('dsTime'))
except KeyError:
print('dsTime: N/A')
sd.putNumber('robotTime', i)
time.sleep(1)
i += 1