This repository has been archived by the owner on Oct 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
tello.py
93 lines (72 loc) · 2.43 KB
/
tello.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
import time
from socket import *
high = 0
# By Q.Z.Lin License:GPLV3
# If you have any advice, please send an email to [email protected]
class tello:
def take_off(self):
global high
self.send_data("takeoff")
high = 1
time.sleep(5)
def land(self):
global high
self.send_data("land")
high = 0
time.sleep(8)
def up(self, distance):
global high
self.send_data("up" + " " + str(distance))
high += distance / 100
time.sleep(int(distance * 0.05))
def down(self, distance):
global high
self.send_data("down" + " " + str(distance))
high -= distance / 100
time.sleep(int(distance * 0.05))
def left(self, distance):
self.send_data("left" + " " + str(distance))
time.sleep(int(distance * 0.05))
def right(self, distance):
self.send_data("right" + " " + str(distance))
time.sleep(int(distance * 0.05))
def forward(self, distance):
self.send_data("forward" + " " + str(distance))
time.sleep(int(distance * 0.05))
def back(self, distance):
self.send_data("back" + " " + str(distance))
time.sleep(int(distance * 0.05))
def cw(self, angle):
self.send_data("cw" + " " + str(angle))
time.sleep(int(angle * 0.02))
def ccw(self, angle):
self.send_data("ccw" + " " + str(angle))
time.sleep(int(angle * 0.02))
def flip(self, direction):
self.send_data("flip" + " " + direction)
time.sleep(3)
def set_speed(self, speed):
self.send_data("speed" + " " + str(speed))
def delay(self, s):
print("Delay: ", s, " s")
time.sleep(s)
def send_data(self, data):
try:
data = data.encode(encoding="utf-8")
self.udpClient.sendto(data, self.addr)
print("Send Command:" + " " + data.decode(encoding="utf-8"))
except:
print("Error")
def end(self):
self.udpClient.close()
print("Program Stop")
def __init__(self):
self.host = "192.168.10.1" # Host ip address
self.port = 8889 # port
self.bufsize = 1024
#
self.addr = (self.host, self.port)
self.udpClient = socket(AF_INET, SOCK_DGRAM)
self.send_data("command")
print("=" * 20, "SimpleTello", "=" * 20)
# print("If you have any advice, please send an email to [email protected]\n")