Adding RSS to accelerometer data stream

Hello!

I'm trying to create an app in Swift that returns the rss of the streamed data. I am able to get the regular streamed data, but am unsuccessful in applying a rss filter to the onboard processing before receiving the data on the iOS.

Is there any sample code available, or example from other projects, which makes this process clear?

Comments

  • More specifically, I am unclear for what to set for the parameters of mbl_mw_dataprocessor_rss_create(signal, context, processor). For the signal, I am passing in a variable set to mbl_mw_acc_get_acceleration_data_signal(device.board), but do not know how to deal with the context and processor.

  • edited June 16

    Some example code in Python:

    def processor_created(context, pointer):
        self.processor = pointer
        e.set()
    fn_wrapper = cbindings.FnVoid_VoidP_VoidP(processor_created)
    
    acc = libmetawear.mbl_mw_acc_get_acceleration_data_signal(self.device.board)
    libmetawear.mbl_mw_dataprocessor_rss_create(acc, None, fn_wrapper)
    e.wait()
    libmetawear.mbl_mw_datasignal_subscribe(self.processor, None, self.callback)
    
    def start(self):
        libmetawear.mbl_mw_acc_enable_acceleration_sampling(self.device.board)
        libmetawear.mbl_mw_acc_start(self.device.board)
    

    All you need to do is either log or stream the output of the rss creator.

  • Hey Laura! Thanks a lot for the reply. I really appreciate it. While this example does help me understand what's going on a little bit more, it is not quite what I need as I am coding in Swift. Do you perhaps have any Swift examples?

    To create my rms_processor_created function, I was going off of the code at the bottom of this post: https://mbientlab.com/community/discussion/comment/7959#Comment_7959. However, clearly the accounter code doesn't exactly translate to be applied to rms. With the following code, I received the error: "A C function pointer cannot be formed from a closure that captures context."

  • Conceptually, I still don't understand how to define the processor / where it gets defined. Any tips on that would be greatly appreciated.

    In addition, will I need to use MblMwFnDataProcessor? When I attempt to, passing in (context, rms_processor_created), I receive an error that MblMwFnDataProcessor has no member 'init'.

  • edited June 16

    Go ahead and download the swift example App, there should be examples there. I think you get it, you just have some syntax issues with swift.

  • I've gone through the whole example App and I cannot find instances of on-board data processing. There are data streams being set up and configurations being applied, but I see no evidence of anything similar to a rms processor.

    Perhaps you can help point out where my understanding is flawed / what I should look into more. This is how I understand the overview of how the rms data processor gets programmed onto the data route.

    • Create a processor (handler) to control what happens to the data after it goes through the RMS processor

      • pass in ptr to the context the enclosing function was called with
      • pass in ptr to processor to be used with the function
      • (I.e. print(RMS) )
      • PROBLEM (I think) - unsure of what specific arguments to put in, how to deal with them from within the closure
    • Create an acceleration signal

      • pass in the MW_Board
      • COMPLETED
    • Apply the data processor by calling mbl_mw_dataprocessor_rms_create

      • pass in signal (acceleration_data_signal)
      • nullptr
      • processor (handler) created (in first step)
      • PROBLEM (I think) - unsure of how to create the data processor and apply it while it is created within the function
    • Enable and start acceleration

      • COMPLETED

    Thanks a lot for your valuable time. I really appreciate it :)

  • edited June 17

    Turns out I did not look through the documentation enough. Although the Swift and C++ API do not have the examples I was looking for, the developer documentation tutorials have examples for all languages: https://mbientlab.com/tutorials/CppDevelopment.html#data-processing.

    Now that I've made some more progress, I have a new issue. It seems that there is no member streamingCleanup in the sample app provided (so generously by mbientlab). Could you help me understand what streamingCleanup is in the context?
    I think it is a dictionary, but do not know what to set the key and value types to. Another possibility is that it's an array, but would appreciate confirmation on this before I venture into manipulating raw memory through https://developer.apple.com/documentation/swift/unsafemutablerawpointer.

    Any workaround, solution code, or recommendation is greatly appreciated!

  • You can ignore that, in the examples we do multiple things all at the same time and this is just a helper function to clean it all up.

  • edited June 17

    Hey Laura. I now see that that part is already taken care of in my acceleration_stop() method. Thanks for the clarification.

    This is my current method:

    When I try to run this, and click the associated button, I receive a "Thread 7: Assertion failed" (the # of the thread changes every time) error message from /MetaWear-SDK-iOS-macOS-tvOS/MetaWear/Core/MetaWearData.swift, line 88. This line is "// Generalized flow
    assert(MemoryLayout.size == length)"

  • Not sure what that would be due to. Maybe try to run it on the main thread.

  • cast rms/rss values to float type, not MblMwCartesianFloat

  • Thanks a lot Eric! This got it working! I'm excited to start adding some more functionality to my app!

Sign In or Register to comment.