Skip to content

Instantly share code, notes, and snippets.

@virtuald
Created January 26, 2016 17:53
Show Gist options
  • Save virtuald/417f03b63edbe0449361 to your computer and use it in GitHub Desktop.
Save virtuald/417f03b63edbe0449361 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import threading
import wpilib
class MyRobot(wpilib.SampleRobot):
def robotInit(self):
c = threading.Condition()
def _thread():
with c:
# get the fake time
now = wpilib.Timer.getFPGATimestamp()
# tell main thread to go
c.notify_all()
print("Now", now)
# Sleep for a second incrementing time as we go
for _ in range(100):
wpilib.Timer.delay(0.01)
# check time
later = wpilib.Timer.getFPGATimestamp()
print(later)
t = threading.Thread(target=_thread)
# wait for thread to start
with c:
t.start()
c.wait()
# sleep for a second
print("Delay")
wpilib.Timer.delay(1.0)
print("Delay done")
# check results
if __name__ == '__main__':
wpilib.run(MyRobot)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment