Skip to content

Commit 237ec6c

Browse files
committed
Added a simple supervisor example
1 parent 55195de commit 237ec6c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import time
2+
3+
import cflib.crtp
4+
from cflib.crazyflie import Crazyflie
5+
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
6+
from cflib.utils import uri_helper
7+
from cflib.utils.reset_estimator import reset_estimator
8+
from cflib.utils.supervisor_state import SupervisorState
9+
10+
11+
# URI to the Crazyflie to connect to
12+
uri = uri_helper.uri_from_env(default='radio://0/80/2M/E7E7E7E7E7')
13+
14+
15+
def safety_check(sup: SupervisorState):
16+
if sup.is_crashed():
17+
raise Exception('Crazyflie crashed!')
18+
if sup.is_locked():
19+
raise Exception('Crazyflie locked!')
20+
if sup.is_tumbled():
21+
raise Exception('Crazyflie tumbled!')
22+
23+
24+
def run_sequence(scf: SyncCrazyflie, sup: SupervisorState):
25+
commander = scf.cf.high_level_commander
26+
27+
try:
28+
if sup.can_be_armed():
29+
safety_check(sup)
30+
scf.cf.platform.send_arming_request(True)
31+
time.sleep(1)
32+
33+
if sup.can_fly():
34+
print('The Crazyflie can fly...taking off!')
35+
commander.takeoff(1.0, 2.0)
36+
time.sleep(3)
37+
safety_check(sup)
38+
if sup.is_flying():
39+
print('The Crazyflie is flying...landing!')
40+
commander.land(0.0, 2.0)
41+
time.sleep(3)
42+
safety_check(sup)
43+
44+
except Exception as e:
45+
print(e)
46+
47+
48+
if __name__ == '__main__':
49+
cflib.crtp.init_drivers()
50+
51+
with SyncCrazyflie(uri, cf=Crazyflie(rw_cache='./cache')) as scf:
52+
time.sleep(1)
53+
supervisor = SupervisorState(scf)
54+
reset_estimator(scf)
55+
time.sleep(1)
56+
run_sequence(scf, supervisor)

0 commit comments

Comments
 (0)