Metamotion R Logging Filtered Data

I'm logging using a periodicsample filter:

MBLFilter<MBLQuaternionData *> *quaternionFilter = [_device.sensorFusion.quaternion periodicSampleOfEvent:250];
[[quaternionFilter startLoggingAsync];

However I'm wondering how I might go about downloading the log if I can't persist a reference to the filter.  It works if the app continues to run, and I keep a reference to the filter and use that to download the logs:

[[_quaternionFilter downloadLogAndStopLoggingAsync:YES progressHandler:^(float number)...

However I can't really do that if I set the device to start logging, and then at some point later I want to download the data after the app has closed and re-opened. Is there a way to enumerate the active filters for an object, or retrieve it somehow?


  • See this post on the tutorials page.  It was written a while ago but I believe everything is still good for iOS api v2.8.3.

    Also see the Gotchas section for the MBLEvent documentation:
  • Ah thank you! exactly what I was looking for
  • Hello,
    I am trying to do something similar, but using the Swift API. I am currently using the develop branch 2.8.3, because 2.8.2 asserts when trying to periodicSample the sensor fusion quaternion data. I am using the following code to start logging periodically and then I receive an assertion when trying to stop logging.

    let filter = sensorNetwork?.getSensor(loc: .leftLower)?.sensorFusion?.quaternion.periodicSample(ofEvent: 200);

    And this is the assertion error I receive,
    Assertion failed: (self.activateCount >= 0), function -[MBLRegister deactivateAsync]_block_invoke

    Do you know if there is anything I can do to fix this? Thanks for your help.
  • Can you successfully log quaternions as is without using a filter?
  • edited May 5
    Yes, I am able to begin and stop logging unfiltered quaternions. I have noticed that my timestamps are not correct but the quaternion readings are correct. 
    I have also noticed that if I attempt to begin logging data on the same sensor twice without first stopping it logging, I get the assertion as well:
    Assertion failed: (self.activateCount >= 0), function -[MBLRegister deactivateAsync]_block_invoke
  • edited May 5
    Riley, here is my obj-c code if it helps: (I'm using 2.8.3 dev branch of the api, needed for quaternion filtering, as you said)

    (implements MBLRestorable for the runOnDeviceBoot method, the NSCoding method implementations shown in the tutorial Eric posted are no longer needed as FastCoding is now used to code all properties)
    #import <Foundation/Foundation.h>
    #import <MetaWear/MetaWear.h>

    #define SAMPLE_INTERVAL 0.25

    @interface QuaternionConfig : NSObject <MBLRestorable>
    @property (nonatomic, strong) MBLEvent *filteredQuaternion;

    #import "QuaternionConfig.h"

    @implementation QuaternionConfig
    -(void)runOnDeviceBoot:(MBLMetaWear *)device{
        //configure quaternion
        device.sensorFusion.mode = MBLSensorFusionModeNDoF;
        self.filteredQuaternion = [device.sensorFusion.quaternion periodicSampleOfEvent:SAMPLE_INTERVAL*1000];
        [self.filteredQuaternion startLoggingAsync];
  • edited May 5
    //-------------------------Code to start logging-------------------------//
    (Note: this restarts the Metawear sensor with the defined config and starts logging as per the runOnDeviceBoot method in QuaternionConfig class)
    [metawearDevice setConfigurationAsync:[[QuaternionConfig alloc] init]];

    //---------------Code to stop and download logging---------------// 
    (this will work even after a restart of the app)
    QuaternionConfig *qConfig = metawearDevice.configuration;
    [qConfig.filteredQuaternion downloadLogAndStopLoggingAsync:YES ....

Sign In or Register to comment.