Created
January 26, 2016 17:53
-
-
Save virtuald/417f03b63edbe0449361 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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