-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcf_interactive_deck.py
82 lines (61 loc) · 2 KB
/
cf_interactive_deck.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
"""
qfly | Qualisys Drone SDK Example Script: Interactive Crazyflie with Deck
The drone flies along the YZ plane while centered at 0 along the X plane.
The Y and Z coordinates track another Crazyflie body equipped with an
Active Marker Deck.
ESC to land at any time.
"""
import pynput
from time import sleep
from qfly import ParallelContexts, Pose, QualisysCrazyflie, QualisysDeck, World
# SETTINGS
cf_body_name = 'E7E7E7E701' # QTM rigid body name
cf_uri = 'radio://0/80/2M/E7E7E7E701' # Crazyflie address
cf_marker_ids = [11, 12, 13, 14]
deck_body_name = 'E7E7E7E7E7'
deck_uri = 'radio://0/80/2M/E7E7E7E7E7'
deck_marker_ids = [1, 2, 3, 4]
# Watch key presses with a global variable
last_key_pressed = None
# Set up keyboard callback
def on_press(key):
"""React to keyboard."""
global last_key_pressed
last_key_pressed = key
if key == pynput.keyboard.Key.esc:
fly = False
# Listen to the keyboard
listener = pynput.keyboard.Listener(on_press=on_press)
listener.start()
# Set up world - the World object comes with sane defaults
world = World()
# Stack up context managers
qcf = QualisysCrazyflie(cf_body_name,
cf_uri,
world,
marker_ids=cf_marker_ids)
deck = QualisysDeck(deck_body_name,
deck_uri,
deck_marker_ids)
with ParallelContexts(*[qcf, deck]):
print("Beginning maneuvers...")
# MAIN LOOP WITH SAFETY CHECK
while(qcf.is_safe()):
# Terminate upon Esc command
if last_key_pressed == pynput.keyboard.Key.esc:
break
# Take off and hover in the center of safe airspace for 5 seconds
# Set target
x = world.origin.x
y = world.origin.y
z = world.expanse
if deck.pose is not None:
y = deck.pose.y
z = deck.pose.z
target = Pose(x, y, z)
# Engage
qcf.safe_position_setpoint(target)
sleep(0.02)
continue
# Land calmly
qcf.land_in_place()