Skip to content

Commit a6b0cf2

Browse files
committed
Moved LogConfig in the __init__
This avoids hitting the 255 log block limit
1 parent fe74cab commit a6b0cf2

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

cflib/utils/supervisor_state.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ def __init__(self, crazyflie):
5151
else:
5252
self.cf = crazyflie
5353

54+
self.logconf = LogConfig(name='SupervisorInfo', period_in_ms=100)
55+
self.logconf.add_variable('supervisor.info', 'uint16_t')
56+
self.cf.log.add_config(self.logconf)
57+
58+
def close(self):
59+
try:
60+
self.logconf.delete()
61+
except Exception as e:
62+
print(f'Warning: failed to delete logconf: {e}')
63+
5464
def read_supervisor_state_bitfield(self):
5565
"""
5666
Reads 'supervisor.info' once from the Crazyflie.
@@ -67,27 +77,20 @@ def log_error(logconf, msg):
6777
print(f'Error when logging {logconf.name}: {msg}')
6878
event.set()
6979

70-
logconf = LogConfig(name='SupervisorInfo', period_in_ms=100)
71-
logconf.add_variable('supervisor.info', 'uint16_t')
72-
73-
try:
74-
self.cf.log.add_config(logconf)
75-
except KeyError as e:
76-
print('Could not add log config:', e)
77-
return None
78-
79-
logconf.data_received_cb.add_callback(log_callback)
80-
logconf.error_cb.add_callback(log_error)
81-
logconf.start()
80+
self.logconf.data_received_cb.add_callback(log_callback)
81+
self.logconf.error_cb.add_callback(log_error)
82+
self.logconf.start()
8283

8384
if event.wait(2.0):
8485
bitfield = value_holder['val']
8586
else:
8687
print('Timeout waiting for supervisor.info')
8788
bitfield = None
8889

89-
logconf.stop()
90-
logconf.delete()
90+
self.logconf.stop()
91+
self.logconf.data_received_cb.remove_callback(log_callback)
92+
self.logconf.error_cb.remove_callback(log_error)
93+
9194
return bitfield
9295

9396
def read_supervisor_state_list(self):

0 commit comments

Comments
 (0)