-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcf_interactive_traqr.py
78 lines (57 loc) · 1.87 KB
/
cf_interactive_traqr.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
"""
qfly | Qualisys Drone SDK Example Script: Interactive Crazyflie with Traqr
The drone flies along the YZ plane while centered at 0 along the X plane.
The Y and Z coordinates track a Traqr or other appropriately configured
rigid body.
ESC to land at any time.
"""
import pynput
from time import sleep
from qfly import ParallelContexts, Pose, QualisysCrazyflie, QualisysTraqr, 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]
traqr_body_name = 'traqr'
# 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)
traqr = QualisysTraqr(traqr_body_name)
with ParallelContexts(*[qcf, traqr]):
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 traqr.pose is not None:
y = traqr.pose.y
z = traqr.pose.z
target = Pose(x, y, z)
# Engage
qcf.safe_position_setpoint(target)
sleep(0.02)
continue
# Land calmly
qcf.land_in_place()