-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetstureJoystick.py
57 lines (50 loc) · 1.13 KB
/
getstureJoystick.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
from easytello import tello
import telloCoordinateSystem
import socket
import ast
import time
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('localhost', 46289))
s.listen(5)
tello = tello.Tello()
T = telloCoordinateSystem.telloC(tello)
flag = 1
last_x = 0
last_y = 0
commandTime = time.time()
def transformCoordinates(temp):
data = temp.decode()
x = 0
y = 0
if data:
#print(data)
try:
data = ast.literal_eval(data)
except:
return 0,0
x = data[0] - 0.5
y = data[0] - 0.5
return x * 2, y * 2
def flyTello(x, y, z, flag, t):
tx = -999
# print("flag")
if flag:
tello.takeoff()
if (t > 2):
T.move(x, y, z)
tx = time.time()
print(t)
return tx
conn, addr = s.accept()
while True:
data = conn.recv(1024)
x, y = transformCoordinates(data)
# print(x, y)
gap = time.time() - commandTime
# print(gap)
tx = flyTello(x, y, 0, flag, gap)
if tx != -999:
commandTime = tx
last_x = x
last_y = y
flag = 0