-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoves.py
107 lines (67 loc) · 2.22 KB
/
moves.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
import asyncio
import math
from enum import Enum
from tello import tello
from djitellopy import Tello
Distance = int
Milliseconds = float
Speed = int
""" 10 - 100 """
BPM = 103
class FlipDirection(Enum):
LEFT = 'l'
RIGHT = 'r'
FORWARD = 'f'
BACKWARD = 'b'
async def takeoff():
tello.takeoff()
async def land():
tello.land()
async def flip(direction: FlipDirection):
tello.flip(direction.value)
async def wait(ms: Milliseconds):
await asyncio.sleep(ms / 1000.0)
async def up(dist: Distance):
assert dist >= 20 and dist <= 500
tello.move_up(dist)
async def down(dist: Distance):
assert dist >= 20 and dist <= 500
tello.move_down(dist)
async def left(dist: Distance):
assert dist >= 20 and dist <= 500
tello.move_left(dist)
async def right(dist: Distance):
assert dist >= 20 and dist <= 500
tello.move_right(dist)
async def forward(dist: Distance):
assert dist >= 20 and dist <= 500
tello.move_forward(dist)
async def back(dist: Distance):
assert dist >= 20 and dist <= 500
tello.move_back(dist)
async def curve(x1: Distance, y1: Distance, z1: Distance, x2: Distance, y2: Distance, z2: Distance, speed: int):
assert x1 >= 20 and x1 <= 500
assert x2 >= 20 and x2 <= 500
assert y1 >= 20 and y1 <= 500
assert y2 >= 20 and y2 <= 500
assert z1 >= 20 and z1 <= 500
assert z2 >= 20 and z2 <= 500
assert speed >= 10 and speed <= 60
tello.send_command_without_return('curve %s %s %s %s %s %s %s' % (x1, y1, z1, x2, y2, z2, speed))
await wait(10)
async def go(x: int, y: int, z: int, speed: int):
tello.send_command_without_return('go %s %s %s %s' % (x, y, z, speed))
async def rotate(degrees: float):
if degrees >= 0:
tello.rotate_clockwise(degrees)
else:
tello.rotate_counter_clockwise(-degrees)
async def set_speed(speed: int):
assert speed >= 10 and speed <= 100, f'invalid speed - {speed}'
tello.set_speed(speed)
def required_speed(time_ms: float, distance: Distance) -> int:
return int((distance / (time_ms / 1000.0)))
def beats2ms(beats: int) -> Milliseconds:
return (beats / BPM) * 60 * 1000
def seconds2beats(seconds: float) -> int:
return math.ceil(BPM * (seconds / 60.0))