-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtarck.py
114 lines (97 loc) · 3.59 KB
/
tarck.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import time, cv2
from threading import Thread
class track:
def rotate(me, qudrant):
# Primary
if qudrant == 6:
me.rotate_clockwise(20)
elif qudrant == 4:
me.rotate_counter_clockwise(20)
elif qudrant == 8:
me.send_rc_control(0,0,40,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
elif qudrant == 2:
me.send_rc_control(0,0,-40,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
# Seconday
if qudrant == 7:
me.send_rc_control(0,0,40,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
me.rotate_counter_clockwise(20)
elif qudrant == 9:
me.send_rc_control(0,0,40,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
me.rotate_clockwise(20)
elif qudrant == 1:
me.send_rc_control(0,0,-40,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
me.rotate_counter_clockwise(20)
elif qudrant == 3:
me.send_rc_control(0,0,-40,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
me.rotate_clockwise(20)
def follow(me, qudrant):
# Primary
if qudrant == 6:
me.send_rc_control(20,0,0,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
elif qudrant == 4:
me.send_rc_control(-20,0,0,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
elif qudrant == 8:
me.send_rc_control(0,0,20,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
elif qudrant == 2:
me.send_rc_control(0,0,-20,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
# Secondary
if qudrant == 7:
me.send_rc_control(-20,0,-20,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
elif qudrant == 9:
me.send_rc_control(20,0,-20,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
elif qudrant == 1:
me.send_rc_control(-20,0,20,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
elif qudrant == 3:
me.send_rc_control(20,0,20,0)
time.sleep(1)
me.send_rc_control(0,0,0,0)
def sling_shot(me, qudrant):
keepRecording = True
frame_read = me.get_frame_read()
def videoRecorder():
# create a VideoWrite object, recoring to ./video.avi
# 创建一个VideoWrite对象,存储画面至./video.avi
height, width, _ = frame_read.frame.shape
video = cv2.VideoWriter('video.avi', cv2.VideoWriter_fourcc(*'XVID'), 30, (width, height))
while keepRecording:
video.write(frame_read.frame)
time.sleep(1 / 30)
video.release()
# we need to run the recorder in a seperate thread, otherwise blocking options
# would prevent frames from getting added to the video
# 我们需要在另一个线程中记录画面视频文件,否则其他的阻塞操作会阻止画面记录
recorder = Thread(target=videoRecorder)
recorder.start()
while me.get_height() < 150:
me.send_rc_control(0,10,10,0)
me.send_rc_control(0,0,0,0)
while me.get_height() > 50:
me.send_rc_control(0,-10,-10,0)
keepRecording = False
recorder.join()