forked from AliceGuntli/crazy-practical-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotion_commander_test.py
More file actions
84 lines (67 loc) · 2.26 KB
/
motion_commander_test.py
File metadata and controls
84 lines (67 loc) · 2.26 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
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
import logging
import sys
import time
from threading import Event
import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.log import LogConfig
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.positioning.motion_commander import MotionCommander
from cflib.utils import uri_helper
uri = 'radio://0/80/2M/E7E7E7E701'
deck_attached_event = Event()
DEFAULT_HEIGHT = 0.5
BOX_LIMIT = 0.5
logging.basicConfig(level=logging.ERROR)
def log_pos_callback(timestamp, data, logconf):
print(data)
def move_linear_simple(scf):
with MotionCommander(scf, default_height=DEFAULT_HEIGHT) as mc:
time.sleep(1)
mc.forward(0.5)
time.sleep(1)
mc.turn_left(180)
time.sleep(1)
mc.forward(0.5)
time.sleep(1)
mc.turn_right(180)
#mc.back(0.5)
time.sleep(1)
def move_linear_motion(scf):
with Motioncommander(scf, default_height=DEFAULT_HEIGHT) as mc:
x_vel = 0.2
y_vel = 0.1
def take_off_simple(scf):
with MotionCommander(scf, default_height=DEFAULT_HEIGHT) as mc:
# Dès que le motion commander est initialisé il fait un take off par défaut
time.sleep(1)
mc.up(0.3)
time.sleep(1)
mc.down(0.3)
time.sleep(3)
# Dès qu'il s'arrête, le drone atterit par défaut.
mc.stop()
def param_deck_flow(_, value_str):
value = int(value_str)
print(value)
if value:
deck_attached_event.set()
print('Deck is attached')
else:
print('Deck is NOT attached')
if __name__ == '__main__':
cflib.crtp.init_drivers()
with SyncCrazyflie(uri, cf=Crazyflie(rw_cache='./cache')) as scf:
scf.cf.param.add_update_callback(group="deck", name="bcFlow2", cb=param_deck_flow)
time.sleep(1)
logconf = LogConfig(name='Position', period_in_ms=10)
logconf.add_variable('stateEstimate.x', 'float')
logconf.add_variable('stateEstimate.y', 'float')
scf.cf.log.add_config(logconf)
logconf.data_received_cb.add_callback(log_pos_callback)
if not deck_attached_event.wait(timeout=5):
print('No flow deck detected!')
sys.exit(1)
logconf.start()
move_linear_simple(scf)
logconf.stop()