Logging Quaternion and Linear Acceleration

Hi there,
for my project, I need to log and download Quaternion as well as Linear Acceleration.
My Code seems to work, however I don't receive an empty List as output.
Am I missing something or are there any major mistakes I made?

from ctypes import c_void_p, cast
from mbientlab.metawear import MetaWear, libmetawear, parse_value, cbindings,
    SensorFusionData, SensorFusionMode, FnVoid_VoidP_UByte_Long_UByteP_UByte,
    FnVoid_VoidP_DataP, byref, LogDownloadHandler, FnVoid_VoidP_UInt_UInt
from time import sleep
from threading import Event


device = MetaWear("D5:C9:76:EE:3C:92")
device.connect()
processor = None
output = []


def handler(ctx, data):
    values = parse_value(data, n_elem=2)
    output.append(values)


callback = cbindings.FnVoid_VoidP_DataP(handler)
libmetawear.mbl_mw_settings_set_connection_parameters(device.board, 7.5, 7.5, 0, 6000)
sleep(1.5)

e = Event()


def processor_created(context, pointer):
    global processor
    processor = pointer
    e.set()


fn_wrapper = cbindings.FnVoid_VoidP_VoidP(processor_created)

linAcc = libmetawear.mbl_mw_sensor_fusion_get_data_signal(device.board, SensorFusionData.LINEAR_ACC)
quat = libmetawear.mbl_mw_sensor_fusion_get_data_signal(device.board, SensorFusionData.QUATERNION)

signals = (c_void_p * 1)()
signals[0] = linAcc
libmetawear.mbl_mw_dataprocessor_fuser_create(quat, signals, 1, None, fn_wrapper)
e.wait()

print("Starting Logging")

libmetawear.mbl_mw_logging_start(device.board, 0)
libmetawear.mbl_mw_sensor_fusion_enable_data(device.board, SensorFusionData.LINEAR_ACC)
libmetawear.mbl_mw_sensor_fusion_enable_data(device.board, SensorFusionData.QUATERNION)
libmetawear.mbl_mw_sensor_fusion_set_mode(device.board, SensorFusionMode.NDOF)
libmetawear.mbl_mw_sensor_fusion_write_config(device.board)

libmetawear.mbl_mw_sensor_fusion_start(device.board)

sleep(5)

print("Logging Stopped")

libmetawear.mbl_mw_sensor_fusion_stop(device.board)
libmetawear.mbl_mw_sensor_fusion_clear_enabled_mask(device.board)

libmetawear.mbl_mw_logging_stop(device.board)

print("Starting Download")

libmetawear.mbl_mw_settings_set_connection_parameters(device.board, 7.5, 7.5, 0, 6000)
sleep(1.0)

de = Event()


def progress_update_handler(context, entries_left, total_entries):
    if entries_left == 0:
        de.set()
        print("Download Finished")


fn_wrapper = FnVoid_VoidP_UInt_UInt(progress_update_handler)
download_handler = LogDownloadHandler(context=None, received_progress_update=fn_wrapper,
                                      received_unknown_entry=cast(None, FnVoid_VoidP_UByte_Long_UByteP_UByte),
                                      received_unhandled_entry=cast(None, FnVoid_VoidP_DataP))

libmetawear.mbl_mw_logger_subscribe(processor, None, callback)
libmetawear.mbl_mw_logging_download(device.board, 1, byref(download_handler))
de.wait()

device.on_disconnect = lambda s: e.set()
libmetawear.mbl_mw_debug_reset(device.board)

print(output)

Comments

  • you can only log one sensor fusion output.
    quaternion OR linear acc

  • @Laura said:
    you can only log one sensor fusion output.
    quaternion OR linear acc

    I tested this with your app and it seems to be possible, provided you're not calculating sensor fusion data in the app by yourself from acceleration etc.

  • Remember sensor fusion comes out at 100Hz and there's a max of about 120Hz or so in a BLE link.
    You would have to downsample the acc.

  • Exxcelius,
    Did you ever figure this out? I would like to do the same thing.
    Didn't understand the comment regarding BLE bandwidth as this is logged data, not streamed data.
    Any feedback would be much appreciated.

  • @CLB said:
    Exxcelius,
    Did you ever figure this out? I would like to do the same thing.
    Didn't understand the comment regarding BLE bandwidth as this is logged data, not streamed data.
    Any feedback would be much appreciated.

    What exactly is your issue?

Sign In or Register to comment.