libmetawear.mbl_mw_dataprocessor_lowpass_create error

AKRAKR
edited June 20 in Python

Hi, I am trying to create a low pass filter using the api.
I am getting the following error

libmetawear.mbl_mw_dataprocessor_lowpass_create(quaternion,8, None, self.fuse_callback) ctypes.ArgumentError: argument 4:: expected CFunctionType instance instead of CFunctionType

any idea on how to fix this?
code snippet
``fuse_callback = FnVoid_VoidP_DataP(self.processor_created)
def processor_created(self,data):
print(data)

quaternion = libmetawear.mbl_mw_sensor_fusion_get_data_signal(self.device.board, SensorFusionData.QUATERNION)
libmetawear.mbl_mw_dataprocessor_lowpass_create(quaternion,8, None, fuse_callback)
libmetawear.mbl_mw_datasignal_subscribe(quaternion, None , self.callback)
libmetawear.mbl_mw_sensor_fusion_enable_data(self.device.board, SensorFusionData.QUATERNION)
libmetawear.mbl_mw_sensor_fusion_start(self.device.board)``

Thanks

Comments

  • edited June 20

    Your stuff looks fine to me but you might have some syntax issue. Again it's hard to tell because you didn't give me a proper code snippet.

    def processor_created(self, context, pointer):
        // DO STUFF
    
    processor_handler = FnVoid_VoidP_VoidP(processor_created)
    
    signal = libmetawear.mbl_mw_acc_get_acceleration_data_signal(board)
    libmetawear.mbl_mw_dataprocessor_lowpass_create(signal, 4, None, processor_handler)
    
  • Hey Laura, thanks
    Not sure what was the issue. Based on the examples i found in the git, i manged to make it work.
    I was doing as an experiment to test how these filters work and I noticed the following outputs.

    I plotted the values and this was the result.
    No filter

    low pass filter

    Average Filter

    Any reasons why this might happen?

    Thanks

  • Probably just not using the filter correctly. I am not 100% sure I understand your graphs though.

  • `
    def setup(self):
    print("Configuring Device %s" %(self.device_name))
    libmetawear.mbl_mw_settings_set_connection_parameters(self.device.board, 7.5, 7.5, 0, 6000)
    #sleep(1.5)
    libmetawear.mbl_mw_acc_set_odr(self.device.board, 100.0)
    libmetawear.mbl_mw_acc_set_range(self.device.board, 4.0)
    libmetawear.mbl_mw_settings_set_tx_power(self.device.board,4)
    libmetawear.mbl_mw_sensor_fusion_set_mode(self.device.board, SensorFusionMode.NDOF)
    libmetawear.mbl_mw_sensor_fusion_set_acc_range(self.device.board, SensorFusionAccRange._2G)
    libmetawear.mbl_mw_sensor_fusion_set_gyro_range(self.device.board, SensorFusionGyroRange._2000DPS)
    libmetawear.mbl_mw_sensor_fusion_write_config(self.device.board)
    e = Event()

        def processor_created(context, pointer):
            self.processor = pointer
            print(context)
            e.set()
        fn_wrapper = cbindings.FnVoid_VoidP_VoidP(processor_created)
        quaternion = libmetawear.mbl_mw_sensor_fusion_get_data_signal(self.device.board, SensorFusionData.QUATERNION)
        # acc = libmetawear.mbl_mw_acc_get_acceleration_data_signal(self.device.board)
        libmetawear.mbl_mw_dataprocessor_lowpass_create(quaternion,1, None, fn_wrapper)
        e.wait()
        libmetawear.mbl_mw_datasignal_subscribe(self.processor, None, self.callback)`
    

    I have a MMR placed on a table and streaming quaternions. I have plotted the quaternion values [x,y,z,w].
    For the above code snippet, the (size Number of previous data samples to compare against) is set to one. and the output is alright.

    And when the size is changed to 8
    libmetawear.mbl_mw_dataprocessor_lowpass_create(quaternion,8, None, fn_wrapper)
    the output of the quaternions while on the table is very noisy

    Can you tell what could be causing this?

  • Remove this:
    libmetawear.mbl_mw_sensor_fusion_set_acc_range(self.device.board, SensorFusionAccRange._2G)
    libmetawear.mbl_mw_sensor_fusion_set_gyro_range(self.device.board, SensorFusionGyroRange._2000DPS)

  • edited June 21

    Some noise is ok btw (you can look at the bosch datasheet for expected noise levels).

  • AKRAKR
    edited June 22

    I removed the lines. Yes, some noise is fine..but the filtered data produces random values. for instance if you notice the quaternion z values are very noisy(second graph) even when the sensor is placed on the table. shouldn't be similar to the first graph? Or does this filter work only with the accelerometer data?

  • edited June 22

    Hey @AKR,
    I apologize but I finally heard back from the firmware engineer. The data processor does not support quaternion inputs.

    Or does this filter work only with the accelerometer data?

    Exactly! Nice job noticing.

Sign In or Register to comment.