-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
244 lines (172 loc) · 7.36 KB
/
Copy pathmain.py
File metadata and controls
244 lines (172 loc) · 7.36 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
from Tkinter import *
import threading
import socket
import sys
import time
import platform
import cv2
import os
#------------------- END LAYOUT, START FUNCTIONS ----------------------------------
def on_closing():
root.destroy()
os._exit(1)
def recv():
count = 0
while True:
try:
data, server = sock.recvfrom(1518)
addLog(data.decode(encoding="utf-8"))
except Exception:
print ('\nExit . . .\n')
break
def camStream():
while True:
_, frame = cap.read()
cv2.imshow('cap', frame)
key = cv2.waitKey(1)
if key == 27:
break
def addLog(txt):
terminalList.insert(0, txt)
def startCam():
global cap
sock.sendto('streamon', tello_address)
cap = cv2.VideoCapture('udp://192.168.10.1:11111')
camThread = threading.Thread(target=camStream)
camThread.start()
def startCon():
addLog('Conectando')
sock.sendto('command', tello_address)
label_status_con.config(text='Conectado', fg='green')
label_status_aircraft.config(text='Pousado')
def takeoff():
addLog('Decolando')
sock.sendto('takeoff', tello_address)
label_status_aircraft.config(text='Voando', fg='green')
def land():
addLog('Pousando')
sock.sendto('land', tello_address)
label_status_aircraft.config(text='Pousado')
def emergency():
addLog('Parada de emergencia')
sock.sendto('emergency', tello_address)
label_status_aircraft.config(text='Pousado')
def move_up():
addLog('Subindo')
sock.sendto('up 20', tello_address)
def move_down():
addLog('Descendo')
sock.sendto('down 20', tello_address)
def move_cw():
addLog('Girando para direita')
sock.sendto('cw 20', tello_address)
def move_ccw():
addLog('Girando para esquerda')
sock.sendto('ccw 20', tello_address)
def move_forward():
addLog('Indo para frente')
sock.sendto('forward 40', tello_address)
def move_back():
addLog('Indo para tras')
sock.sendto('back 40', tello_address)
def move_left():
addLog('Indo para esquerda')
sock.sendto('left 40', tello_address)
def move_right():
addLog('Indo para direita')
sock.sendto('right 40', tello_address)
def flip_forward():
addLog('Flip para frente')
sock.sendto('flip f', tello_address)
def flip_back():
addLog('Flip para tras')
sock.sendto('flip b', tello_address)
def flip_left():
addLog('Flip para esquerda')
sock.sendto('flip l', tello_address)
def flip_right():
addLog('Flip para direita')
sock.sendto('flip r', tello_address)
def battery():
addLog('Nivel da bateria')
sock.sendto('battery?', tello_address)
#------------------- PRE CONFIG ----------------------
host = ''
port = 9000
locaddr = (host,port)
cap = None
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
tello_address = ('192.168.10.1', 8889)
sock.bind(locaddr)
recvThread = threading.Thread(target=recv)
recvThread.start()
#---------- MAIN FRAME ----------
root = Tk()
root.protocol("WM_DELETE_WINDOW", on_closing)
root.geometry('600x600+200+200')
root.wm_title("DJI Tello")
#---------- COMMANDS FRAME ----------
commandsFrame = LabelFrame(root, text="Comandos")
commandsFrame.place(rely=0, relx=0, relwidth=1, relheight=0.7)
label_ip = Label(commandsFrame, text="IP Tello", font=("Helvetica", 12))
label_ip.place(rely=0, relwidth=0.2, relheight=0.1, relx=0.05)
entry_ip = Entry(commandsFrame)
entry_ip.place(relx=0.05, relwidth=0.2, relheight=0.1, rely=0.1)
entry_ip.insert(0, '192.168.10.1')
label_port = Label(commandsFrame, text="Command Port", font=("Helvetica", 12))
label_port.place(rely=0, relwidth=0.2, relheight=0.1, relx=0.25)
entry_port = Entry(commandsFrame)
entry_port.place(relx=0.25, relwidth=0.2, relheight=0.1, rely=0.1)
entry_port.insert(0, '8889')
btn_connect = Button(commandsFrame, text="Conectar", command=startCon)
btn_connect.place(relx=0.45, relwidth=0.2, relheight=0.1, rely=0.1)
btn_connect_cam = Button(commandsFrame, text="Camera", command=startCam)
btn_connect_cam.place(relx=0.45, relwidth=0.2, relheight=0.1, rely=0.2)
btn_connect_cam = Button(commandsFrame, text="Bateria", command=battery)
btn_connect_cam.place(relx=0.25, relwidth=0.2, relheight=0.1, rely=0.2)
label_status_con = Label(commandsFrame, text="Desconectado", fg="red", font=("Helvetica", 12))
label_status_con.place(rely=0.1, relwidth=0.2, relheight=0.1, relx=0.7)
btn_takeoff = Button(commandsFrame, text="Decolar", command=takeoff)
btn_takeoff.place(relx=0.05, relwidth=0.2, relheight=0.1, rely=0.3)
btn_land = Button(commandsFrame, text="Pousar", command=land)
btn_land.place(relx=0.25, relwidth=0.2, relheight=0.1, rely=0.3)
btn_emergency = Button(commandsFrame, text="Emergencia", command=emergency)
btn_emergency.place(relx=0.45, relwidth=0.2, relheight=0.1, rely=0.3)
label_status_aircraft = Label(commandsFrame, text="Desconectado", fg="red", font=("Helvetica", 12))
label_status_aircraft.place(rely=0.3, relwidth=0.2, relheight=0.1, relx=0.7)
#------------------ ROTATION -----------------
btn_move_up = Button(commandsFrame, text="Subir", command=move_up)
btn_move_up.place(relx=0.15, relwidth=0.2, relheight=0.1, rely=0.5)
btn_move_cw = Button(commandsFrame, text="Girar", command=move_ccw)
btn_move_cw.place(relx=0.05, relwidth=0.2, relheight=0.1, rely=0.6)
btn_move_down = Button(commandsFrame, text="Descer", command=move_down)
btn_move_down.place(relx=0.15, relwidth=0.2, relheight=0.1, rely=0.7)
btn_move_ccw = Button(commandsFrame, text="Girar", command=move_cw)
btn_move_ccw.place(relx=0.25, relwidth=0.2, relheight=0.1, rely=0.6)
#----------------------- MOVEMENT -------------------
btn_move_up = Button(commandsFrame, text="Frente", command=move_forward)
btn_move_up.place(relx=0.65, relwidth=0.2, relheight=0.1, rely=0.5)
btn_move_cc = Button(commandsFrame, text="Esquerda", command=move_left)
btn_move_cc.place(relx=0.55, relwidth=0.2, relheight=0.1, rely=0.6)
btn_move_down = Button(commandsFrame, text="Tras", command=move_back)
btn_move_down.place(relx=0.65, relwidth=0.2, relheight=0.1, rely=0.7)
btn_move_cc = Button(commandsFrame, text="Direita", command=move_right)
btn_move_cc.place(relx=0.75, relwidth=0.2, relheight=0.1, rely=0.6)
# ------------------------- FLIPS
label_flips = Label(commandsFrame, text="Flips", font=("Helvetica", 12))
label_flips.place(rely=0.8, relwidth=0.2, relheight=0.1, relx=0.05)
btn_flip_front = Button(commandsFrame, text="Frente", command=flip_forward)
btn_flip_front.place(relx=0.05, relwidth=0.2, relheight=0.1, rely=0.9)
btn_flip_back = Button(commandsFrame, text="Tras", command=flip_left)
btn_flip_back.place(relx=0.25, relwidth=0.2, relheight=0.1, rely=0.9)
btn_flip_left = Button(commandsFrame, text="Esquerda", command=flip_back)
btn_flip_left.place(relx=0.45, relwidth=0.2, relheight=0.1, rely=0.9)
btn_flip_right = Button(commandsFrame, text="Direita", command=flip_right)
btn_flip_right.place(relx=0.65, relwidth=0.2, relheight=0.1, rely=0.9)
#---------- TERMINAL FRAME ----------
terminalFrame = LabelFrame(root, text="Terminal")
terminalFrame.place(rely=0.7, relx=0, relwidth=1, relheight=0.3)
terminalList = Listbox(terminalFrame)
terminalList.pack(fill="both", expand=1)
#---------- START APP ----------
root.mainloop()