-
Notifications
You must be signed in to change notification settings - Fork 927
Open
Labels
priorityIssues discussed in the triage meeting that are high on our priority list.Issues discussed in the triage meeting that are high on our priority list.
Description
I recently came across an issue when I wanted to read a specific variable once.
Here are the steps I followed:
- Create a
LogConfig, - Add the desired variable name using
LogConfig().add_variable() - Wait until I get a value, and
- Delete the created
LogConfigusingLogConfig().delete()
After 255 iterations, the script reaches the limit of Log blocks that the firmware allows. This probably means that all LogConfigs are not deleted properly.
A workaround to that is to create a single LogConfig and start logging the variable each time you want to read it. However, it would be nice to investigate why this happens.
Below is a simple script that tries to read the acceleration on the Z axis 300 times but stops after 255.
import time
import cflib.crtp
from cflib.crazyflie import Crazyflie
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
from cflib.utils import uri_helper
import threading
from cflib.crazyflie.log import LogConfig
from cflib.crazyflie.syncCrazyflie import SyncCrazyflie
# URI to the Crazyflie to connect to
uri = uri_helper.uri_from_env(default='radio://0/30/2M/BADC0DE010')
def read_accZ_once(scf: SyncCrazyflie):
"""
Reads 'acc.z' once from the Crazyflie.
Returns the value or None if timed out.
"""
value_holder = {'val': None}
event = threading.Event()
def log_callback(timestamp, data, logconf):
value_holder['val'] = data['acc.z']
event.set()
def log_error(logconf, msg):
print(f'Error when logging {logconf.name}: {msg}')
event.set()
logconf = LogConfig(name='acceleration', period_in_ms=100)
logconf.add_variable('acc.z', 'float')
scf.cf.log.add_config(logconf)
logconf.data_received_cb.add_callback(log_callback)
logconf.error_cb.add_callback(log_error)
logconf.start()
if event.wait(2.0):
bitfield = value_holder['val']
else:
print('Timeout waiting for acc.z')
bitfield = None
logconf.stop()
logconf.delete()
return bitfield
if __name__ == '__main__':
cflib.crtp.init_drivers()
with SyncCrazyflie(uri, cf=Crazyflie(rw_cache='./cache')) as scf:
time.sleep(1)
for i in range(300):
accZ = read_accZ_once(scf)
print(f'{i}.) accZ = {accZ}')Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
priorityIssues discussed in the triage meeting that are high on our priority list.Issues discussed in the triage meeting that are high on our priority list.