This repository has been archived by the owner on Feb 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
week_zero.py
77 lines (67 loc) · 2.06 KB
/
week_zero.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from util.stopwatch import stopwatch as SW
import cv2
import sys
import time
from networktables import NetworkTables as NT
import socket
# random change
def main():
global timer
timer = SW('timer')
timer.start()
nt = init_nt()
cam = init_cv()
loop(cam, nt)
def init_nt():
robot = 'roborio-501-frc.local' # set robot name
robot_ip = socket.gethostbyname(robot) # determine robot IP
nt_init = False
while not nt_init:
try:
NT.initialize(server=robot_ip) # initialize client
except:
continue
try:
vision_table = NT.getTable('SmartDashboard')
except:
NT.stop()
NT.destroy()
continue
vision_table.putBoolean('Vision.pullback', True)
pullback = vision_table.getBoolean('Vision.pullback', None)
if pullback:
nt_init = True
else:
continue
else:
return vision_table
def init_cv():
try:
cam = cv2.VideoCapture('http://tinkerboard.local:1180/?action=stream?dummy=param.mjpg')
time.sleep(1)
# print('camera init.')
except:
print("Exception on VideoCapture init. Dying")
sys.exit()
return cam
def loop(camera, network_table):
while camera.isOpened():
pose = network_table.getBoolean('Robot.strikingAPose', None)
arm = network_table.getBoolean('Arm.inMotion', None)
wrist = network_table.getBoolean('Wrist.inMotion', None)
elbow = network_table.getBoolean('Elbow.inMotion', None)
if pose or arm or wrist or elbow:
ret, frame = camera.read()
if ret:
current_time = timer.get()
formatted_time = "%.3f" % (current_time)
filename = "/home/linaro/match_images/live_match"+formatted_time+".jpg"
cv2.imwrite(filename, frame)
time.sleep(0.133)
else:
time.sleep(0.133)
continue
else:
time.sleep(0.133)
if __name__ == "__main__":
main()