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?

  • I have now been able to stream both linear acceleration data and quaternion data using the dataprocessor_fuser_create function. However, the quaternion data is VERY unstable, even when the sensor is static (in a fixed position). I have also run the linear acceleration and quaternion data through two separate data handlers with the same results. Shown attached
    is a snippet of the fused dataset:

    You can also see from this data that the epoch timestamp data is very erratic as well. I can send my code, but I am using mbient example code modified for fuser_create method.

    Thanks for any guidance you can provide Eric.

  • By the way, here is my sensor information:

  • @CLB,
    I am not sure how this is possible. The sensor fusion module from bosh only allows one output at a time. So you should have linear acceleration OR quaternion. We and BOSCH do not support both at the same time.

  • Thank you for your response Laura. Can you please explain to me the purpose and use of the mbl_mw_dataprocessor_fuser_create() method? I thought this was the intent. In addition, as I indicated previously ... even when I set up two unique data handlers for the linear acceleration and quaternion data streams, I see the same behavior from the quaternion output. Thanks again.

  • edited February 7

    You can use it to do raw accelerometer + quaternion but not linear acceleration.

    EDIT: Looks like that's not true as per Eric's post. The fuser is for gyro + acc for example.

  • Laura, I stand corrected regarding my unique data handlers for quaternion and linear acceleration. The code runs the callbacks back-to-back, and I am tracking the number of samples recorded for each. They are almost always different, and I attributed this to "nan" values in the quaternion being ignored when I "joined" the arrays. However, I see now that this is simply the result of the asynchronous behavior of the data and data handlers. In other words, the data looks stable (at least for a static case), but now to work on the synchronization of the data.

  • @CLB said:
    I have now been able to stream both linear acceleration data and quaternion data using the dataprocessor_fuser_create function. However, the quaternion data is VERY unstable, even when the sensor is static (in a fixed position). I have also run the linear acceleration and quaternion data through two separate data handlers with the same results. Shown attached
    is a snippet of the fused dataset:

    You cannot use the data fuser with sensor fusion output, you will have to collect their values separately.

    You can also see from this data that the epoch timestamp data is very erratic as well. I can send my code, but I am using mbient example code modified for fuser_create method.

    Post your code

Sign In or Register to comment.