-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyboard_input.py
More file actions
60 lines (56 loc) · 1.27 KB
/
Copy pathkeyboard_input.py
File metadata and controls
60 lines (56 loc) · 1.27 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
import time
from codrone_edu.drone import *
drone = Drone()
drone.pair()
#ユーザ入力
print("操作コマンド一覧")
print("w:up")
print("s:down")
print("a:turn left")
print("d:turn right")
print("i:front")
print("l:right")
print("j:left")
print("k:back")
print("q:quit")
drone.takeoff() #必要ならトリムを微調整する
power = 40
while True:
drone.set_throttle(0)
drone.set_roll(0)
drone.set_yaw(0)
drone.set_pitch(0)
direction = input("")
if direction == "w":
drone.set_throttle(power)
drone.move(1)
elif direction == "s":
drone.set_throttle(-power)
drone.move(1)
elif direction == "a":
drone.set_yaw(-power)
drone.move(1)
elif direction == "d":
drone.set_yaw(power)
drone.move(1)
elif direction == "i":
drone.set_pitch(power)
drone.move(1)
elif direction == "k":
drone.set_pitch(-power)
drone.move(1)
elif direction == "j":
drone.set_roll(-power)
drone.move(1)
elif direction == "l":
drone.set_roll(power)
drone.move(1)
elif direction == "q":
time.sleep(1)
drone.land()
break
else:
print("無効なコマンド")
print("終了")
drone.land()
drone.close()