-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo_single1.0.0.py
195 lines (146 loc) · 6.12 KB
/
demo_single1.0.0.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
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
import string
import sys, os, json, time
from fly_tello import FlyTello
my_tellos = list()
#################################################################################################
####### CONNECTION SETUP OF TCP WITH BEYOND
import socket
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Bind the socket to the port
server_address = ('192.168.1.132', 50524)
#control_p=8889
print (sys.stderr, 'starting up on %s port %s' % server_address)
sock.bind(server_address)
# Listen for incoming connections
sock.listen(1)
####################################################################################################
###### DIFFERENT MOTION FUNCTIONS
def Motion(mot:int):
if mot==2:
fly.straight(x=0,y=-20,z=60, speed=100)
fly.straight(x=0,y=20,z=-60, speed=100)
elif mot==1:
fly.straight(x=0,y=0,z=50, speed=100)
fly.straight(x=0,y=0,z=-50, speed=100)
fly.straight(x=0,y=0,z=50, speed=100)
else:
print("Unsupported command")
def semicircle(dir:str):
# fly.rotate_cw(angle=90, tello=1)
if dir =='r':
fly.curve(x1=70, y1=-70, z1=0, x2=140, y2=0, z2=0, speed=60)
elif dir =='l':
fly.curve(x1=70, y1=70, z1=0, x2=140, y2=0, z2=0, speed=60)
else:
print("Unsupported values entered")
#fly.rotate_ccw(angle=45, tello=1)
def circle(type:str):
if type =='ccw':
# ledblink()
fly.curve(x1=70, y1=-70, z1=0, x2=140, y2=0, z2=0, speed=60)
fly.curve(x1=-70, y1=70, z1=0, x2=-140, y2=0, z2=0, speed=60)
# ledstop()
elif type=='cw':
fly.curve(x1=70, y1=70, z1=0, x2=140, y2=0, z2=0, speed=60)
fly.curve(x1=-70, y1=-70, z1=0, x2=-140, y2=0, z2=0,speed=60)
elif type =='du':
fly.curve(x1=70, y1=0, z1=-70, x2=140, y2=0, z2=0, speed=60)
fly.curve(x1=-70, y1=0, z1=70, x2=-140, y2=0, z2=0, speed=60)
elif type =='ud':
fly.curve(x1=70, y1=0, z1=70, x2=140, y2=0, z2=0, speed=60)
fly.curve(x1=-70, y1=0, z1=-70, x2=-140, y2=0, z2=0, speed=60)
else:
print("Unsupported values entered")
def eight(direction:str):
#vertical up to down
if direction =='vu':
#ledblink()
fly.curve(x1=0, y1=-70, z1=70, x2=0, y2=0, z2=140, speed=60)
fly.curve(x1=0, y1=70, z1=-70, x2=0, y2=0, z2=-140, speed=60)
fly.curve(x1=0, y1=-70, z1=-70, x2=0, y2=0, z2=-140, speed=60)
fly.curve(x1=0, y1=70, z1=70, x2=0, y2=0, z2=140, speed=60)
elif direction=='vd':
fly.curve(x1=0, y1=-70, z1=-70, x2=0, y2=0, z2=-140, speed=60)
fly.curve(x1=0, y1=70, z1=70, x2=0, y2=0, z2=140, speed=60)
fly.curve(x1=0, y1=-70, z1=70, x2=0, y2=0, z2=140, speed=60)
fly.curve(x1=0, y1=70, z1=-70, x2=0, y2=0, z2=-140, speed=60)
#horizontal right to left
elif direction=='hr':
fly.curve(x1=0, y1=-70, z1=-70, x2=0, y2=-140, z2=0, speed=60)
fly.curve(x1=0, y1=70, z1=70, x2=0, y2=140, z2=0, speed=60)
fly.curve(x1=0, y1=70, z1=-70, x2=0, y2=140, z2=0, speed=60)
fly.curve(x1=0, y1=-70, z1=70, x2=0, y2=-140, z2=0, speed=60)
#horizontal left to right
elif direction=='hl':
fly.curve(x1=0, y1=70, z1=-70, x2=0, y2=140, z2=0, speed=60)
fly.curve(x1=0, y1=-70, z1=70, x2=0, y2=-140, z2=0, speed=60)
fly.curve(x1=0, y1=-70, z1=-70, x2=0, y2=-140, z2=0, speed=60)
fly.curve(x1=0, y1=70, z1=70, x2=0, y2=140, z2=0, speed=60)
elif direction=='criscross':
fly.curve(x1=70, y1=-70, z1=-70, x2=140, y2=-140, z2=0, speed=60)
fly.curve(x1=-70, y1=70, z1=70, x2=-140, y2=140, z2=-0, speed=60)
fly.curve(x1=-70, y1=70, z1=-70, x2=-140, y2=140, z2=0, speed=60)
fly.curve(x1=70, y1=-70, z1=70, x2=140, y2=-140, z2=0, speed=60)
# MAIN FLIGHT CONTROL LOGIC
# Define the Tello's we're using, in the order we want them numbered
#my_tellos.append('0TQDG2KEDB4D6B') # 1-Yellow
my_tellos.append('0TQDG3REDB6D33') # 2-Blue
# my_tellos.append('0TQDFC6EDBH8M8') # 3-Green
# my_tellos.append('0TQDFC7EDB4874') # 4-Red
# Control the flight
#fly.takeoff()
#fly.land()
with FlyTello(my_tellos) as fly:
# while True:
# Wait for a connection
while True:
# Wait for a connection
print ('waiting for a connection')
connection, client_address = sock.accept()
try:
print ('connection from', client_address)
# Receive the data in small chunks and retransmit it
if True:
data = connection.recv(15).decode().strip()
print ('received "%s"' % data)
#data.strip('')
if data=='circle':
circle('ccw')
data=''
print("wohho ")
elif data=='takeoff':
fly.takeoff()
print("wohho")
data=''
elif data== 'up':
print('up comm')
fly.up(dist=100)
data=''
elif data=='flipr':
fly.flip(direction='right',tello=1)
data=''
elif data=='flipl':
fly.flip(direction='left',tello=1)
data=''
elif data=='down':
fly.down(dist=100)
data=''
elif data=='land':
fly.land()
x=1
elif data=='':
print ('Data cleared')
elif data=='close':
fly.land()
data=''
print("Closing connection")
break
# print ('sending data back to the client')
# connection.sendall(data.encode())
#else:
# print ('no more data from', client_address)
# break
finally:
# Clean up the connection
connection.close()