-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdance.py
More file actions
198 lines (138 loc) · 4.52 KB
/
Copy pathdance.py
File metadata and controls
198 lines (138 loc) · 4.52 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import socket
import time
# wlx503eaaaa884f
# wlx78d2946e0a54
# wlx8c3badea7325
# wlx8c3badea7433
# wlx503eaaac4bd6
wifiA = 'wlx503eaaaa884f' # TELLO-D1E7F9
wifiB = 'wlx78d2946e0a54' # TELLO-D1F086
wifiC = 'wlx8c3badea7325' # TELLO-D1EDA1
wifiD = 'wlp3s0' # TELLO-D1EE19
UDP_IP = "127.0.0.1"
UDP_PORT = 5005
MESSAGE = "Hello, World!"
#print "UDP target IP:", UDP_IP
#print "UDP target port:", UDP_PORT
#print "message:", MESSAGE
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.sendto(MESSAGE, (UDP_IP, UDP_PORT))
time.sleep(1.5)
_delay = 3
_delayB = 4
_shortDistance = 18
_middleDistance = 30
_longDistance = 100
shortDelay = 0.02
_leftShortMove = 'left ' + str(_shortDistance)
_rightShortMove = 'right ' + str(_shortDistance)
_forwardShortMove = 'forward ' + str(_shortDistance)
_backwardShortMove = 'back ' + str(_shortDistance)
_upShortMove = 'up ' + str(_shortDistance)
_downShortMove = 'down ' + str(_shortDistance)
_leftMiddleMove = 'left ' + str(_middleDistance)
_rightMiddleMove = 'right ' + str(_middleDistance)
_forwardMiddleMove = 'forward ' + str(_middleDistance)
_backwardMiddleMove = 'back ' + str(_middleDistance)
_upMiddleMove = 'up ' + str(_middleDistance)
_downMiddleMove = 'down ' + str(_middleDistance)
_leftLongMove = 'left ' + str(_longDistance)
_rightLongMove = 'right ' + str(_longDistance)
_forwardLongMove = 'forward ' + str(_longDistance)
_backwardLongMove = 'back ' + str(_longDistance)
_upLongMove = 'up ' + str(_longDistance)
_downLongMove = 'down ' + str(_longDistance)
sock1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock1.setsockopt(socket.SOL_SOCKET, 25, wifiA.encode())
sock2 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock2.setsockopt(socket.SOL_SOCKET, 25, wifiB.encode())
sock3 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock3.setsockopt(socket.SOL_SOCKET, 25, wifiC.encode())
sock4 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock4.setsockopt(socket.SOL_SOCKET, 25, wifiD.encode())
def sendSwarmCommand(command):
sendCommand(sock1,command.encode())
time.sleep(0.02)
sendCommand(sock2,command.encode())
time.sleep(0.02)
sendCommand(sock3,command.encode())
time.sleep(0.02)
sendCommand(sock4,command.encode())
time.sleep(0.02)
def sendCommand(telloSock,command):
telloSock.sendto(command.encode(),0, ('192.168.10.1', 8889))
def turnSwarm(sockA,sockB,sockC,sockD,shortDelay):
sendCommand(sockA,_leftLongMove)
time.sleep(shortDelay)
sendCommand(sockB,_forwardLongMove)
time.sleep(shortDelay)
sendCommand(sockC,_rightLongMove) #sock3 -> drone #2 () # sock1 -> drone3
time.sleep(shortDelay)
sendCommand(sockD,_backwardLongMove) # sock4 -> drone #3 () # sock2 -> drone 4
time.sleep(shortDelay)
def upAndDown(sockA,sockB,sockC,sockD,shortDelay):
sendCommand(sockA,_upMiddleMove)
time.sleep(shortDelay)
sendCommand(sockB,_downMiddleMove)
time.sleep(shortDelay)
sendCommand(sockC,_upMiddleMove)
time.sleep(shortDelay)
sendCommand(sockD,_downMiddleMove)
time.sleep(shortDelay)
print("takeoff")
sendSwarmCommand("command")
sendSwarmCommand("takeoff")
##########
time.sleep(_delay)
sendSwarmCommand(_upMiddleMove)
time.sleep(_delay)
turnSwarm(sock1,sock2,sock3,sock4,shortDelay)
time.sleep(1)
sendSwarmCommand("cw 180")
time.sleep(3)
sendSwarmCommand("ccw 180")
time.sleep(3)
upAndDown(sock1,sock2,sock3,sock4,2)
upAndDown(sock2,sock1,sock4,sock3,2)
time.sleep(2)
sendSwarmCommand("flip b")
time.sleep(3)
#turnSwarm(sock4,sock1,sock2,sock3,shortDelay)
# time.sleep(3)
print("differing part...")
print("a")
sendCommand(sock1,_leftLongMove)
time.sleep(shortDelay)
sendCommand(sock2,_forwardLongMove)
time.sleep(shortDelay)
sendCommand(sock3,_rightLongMove) #sock3 -> drone #2 () # sock1 -> drone3
time.sleep(shortDelay)
sendCommand(sock4,_backwardLongMove) # sock4 -> drone #3 () # sock2 -> drone 4
time.sleep(_delay)
print("ending part...")
sendSwarmCommand('ccw 180')
time.sleep(_delay)
sendSwarmCommand('cw 360')
time.sleep(_delay)
sendCommand(sock1,_upMiddleMove)
time.sleep(0.01)
sendCommand(sock2,_downMiddleMove)
time.sleep(0.01)
sendCommand(sock3,_upMiddleMove)
time.sleep(0.01)
sendCommand(sock4,_downMiddleMove)
time.sleep(0.01)
sendCommand(sock1,_downMiddleMove)
time.sleep(0.01)
sendCommand(sock2,_upMiddleMove)
time.sleep(0.01)
sendCommand(sock3,_downMiddleMove)
time.sleep(0.01)
sendCommand(sock4,_upMiddleMove)
time.sleep(0.01)
sendSwarmCommand("cw 360")
time.sleep(5)
sendSwarmCommand("flip f")
time.sleep(3)
sendSwarmCommand('land')