Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save primetoxinz/5584f4dbe0b8d30f0287bf2273bd23fb to your computer and use it in GitHub Desktop.
Save primetoxinz/5584f4dbe0b8d30f0287bf2273bd23fb to your computer and use it in GitHub Desktop.
import time
import random
#pip install pynetworktables
from networktables import NetworkTables
# To see messages from networktables, you must setup logging
import logging
logging.basicConfig(level=logging.DEBUG)
sd = NetworkTables.getTable("SmartDashboard")
i = 135
while True:
try:
print('robotTime:', sd.getNumber('robotTime'))
except KeyError:
print('dsTime: N/A')
for key in sd.getKeys():
print(str(sd.getValue(key)))
if i <= 0:
phase = 'Disabled'
elif i >= 30:
phase = 'Teleop'
else:
phase = 'Autonomous'
sd.putString('robotPhase', phase)
sd.putNumber('robotTime', i)
sd.putNumber('voltage', 12 + random.randint(-100, 100) * 0.05)
sd.putNumber('current', 7 + random.randint(-10, 10) * 0.05)
time.sleep(1)
if i > 0:
i -= 1
else:
i = 135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment