-
Notifications
You must be signed in to change notification settings - Fork 3
/
cf_console.py
57 lines (41 loc) · 1.33 KB
/
cf_console.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
#
# Copyright (C) 2023 ETH Zurich
# All rights reserved.
#
# This software may be modified and distributed under the terms
# of the GPL-3.0 license. See the LICENSE file for details.
#
# Author: Carl Friess
#
import os.path
import sys
import cflib.crtp
from cflib.crazyflie import Crazyflie
if len(sys.argv) != 2:
print(f"Usage: {os.path.basename(sys.argv[0])} uri")
exit(1)
cflib.crtp.init_drivers(enable_debug_driver=False)
cf = Crazyflie(rw_cache='./cf_cache')
is_connected = False
def _connected(link_uri):
global is_connected
print("[CF]", f"Connected to {link_uri}")
is_connected = True
def _connection_failed(link_uri, msg):
global is_connected
print("[CF]", f"Connection to {link_uri} failed: {msg}")
is_connected = False
def _connection_lost(link_uri, msg):
global is_connected
print("[CF]", f"Connection to {link_uri} lost: {msg}")
is_connected = False
def _disconnected(link_uri):
global is_connected
print("[CF]", f"Disconnected from {link_uri}")
is_connected = False
cf.connected.add_callback(_connected)
cf.disconnected.add_callback(_disconnected)
cf.connection_failed.add_callback(_connection_failed)
cf.connection_lost.add_callback(_connection_lost)
cf.console.receivedChar.add_callback(lambda chars: sys.stdout.write(chars))
cf.open_link(sys.argv[1] + "?rate_limit=10")