Step Counter/Step Dectector

Hey,
I am trying to stream the number of steps taken by a person just like stream_acc.py.
I tried the steps mentioned in the developer documentation for step counter. Unfortunalty I am unable to stream the steps. Can you give some pointers on how to do this, if possible?

I have metamotionR sensor.
Snippet of the code
class State:
def init(self, device):
self.device = device
self.samples = 0
self.callback = FnVoid_VoidP_DataP(self.data_handler)

def data_handler(self, ctx, data):
    print("Steps= %d" % (parse_value(data)))
    self.samples+= 1

for s in states:

        libmetawear.mbl_mw_acc_bmi160_set_step_counter_mode(s.device.board, AccBmi160StepCounterMode.NORMAL );
        libmetawear.mbl_mw_acc_bmi160_write_step_counter_config(s.device.board);

        #Enable the Counter
        libmetawear.mbl_mw_acc_bmi160_enable_step_counter(s.device.board);
        libmetawear.mbl_mw_acc_bmi160_write_step_counter_config(s.device.board);
        libmetawear.mbl_mw_acc_start(s.device.board);

        # read step counter
        step_counter= libmetawear.mbl_mw_acc_bmi160_get_step_counter_data_signal(s.device.board)
        libmetawear.mbl_mw_datasignal_subscribe(step_counter, None, s.callback)
        libmetawear.mbl_mw_datasignal_read(step_counter); 

    sleep(30.0)
    for s in states:

        libmetawear.mbl_mw_acc_bmi160_disable_step_counter(s.device.board)
        step_counter= libmetawear.mbl_mw_acc_bmi160_get_step_counter_data_signal(s.device.board)
        libmetawear.mbl_mw_datasignal_unsubscribe(step_counter, None, s.callback)
        libmetawear.mbl_mw_debug_disconnect(s.device.board) 

Comments

  • edited February 2020

    You need to enable to bmi as a whole as well -> libmetawear.mbl_mw_gyro_bmi160_start(self.device.board)

  • AKRAKR
    edited February 2020

    Thanks Laura it worked fine.
    Is it possible to stream the steps in real time?
    Similarly, I tried the same with the step detector, and it isn't able to detect the steps?
    for s in states:
    libmetawear.mbl_mw_gyro_bmi160_start(s.device.board)
    libmetawear.mbl_mw_acc_bmi160_enable_step_detector(s.device.board);
    libmetawear.mbl_mw_acc_bosch_start(s.device.board);
    sleep(25.0)
    for s in states:
    libmetawear.mbl_mw_acc_bmi160_disable_step_detector(s.device.board)

            step_detector= libmetawear.mbl_mw_acc_bmi160_get_step_detector_data_signal(s.device.board)
            libmetawear.mbl_mw_datasignal_unsubscribe(step_detector, None, s.callback)
            libmetawear.mbl_mw_debug_disconnect(s.device.board)  
    

    Is there a way to stream the step counter and the detector data like the accelerometer data? Not together, but separately. I have two different codes at the moment and required to stream the data individually.

    Thanks

  • yes you can do that.

  • thanks But, the step detector doesn't seem to detect steps. Not sure if its a mistake in the code or with the sensor.

  • I can't comment as you have given no information. It works for me.

  • I have given the code I used for step detector already.

    def data_handler(self, ctx, data):
    print("Steps detected")
    self.samples+= 1
    for s in states:
    libmetawear.mbl_mw_gyro_bmi160_start(s.device.board)
    libmetawear.mbl_mw_acc_bmi160_enable_step_detector(s.device.board);
    libmetawear.mbl_mw_acc_bosch_start(s.device.board);
    sleep(25.0)
    for s in states:
    libmetawear.mbl_mw_acc_bmi160_disable_step_detector(s.device.board)
    step_detector= libmetawear.mbl_mw_acc_bmi160_get_step_detector_data_signal(s.device.board)
    libmetawear.mbl_mw_datasignal_unsubscribe(step_detector, None, s.callback)
    libmetawear.mbl_mw_debug_disconnect(s.device.board)

  • edited February 2020

    PSEUDOCODE:

    mbl_mw_acc_bosch_set_range(device.board, 2G)
    mbl_mw_acc_set_odr(device.board, 25Hz)
    mbl_mw_acc_bosch_write_acceleration_config(device.board)
    
    let signal = mbl_mw_acc_bmi160_get_step_detector_data_signal(device.board)
        mbl_mw_datasignal_subscribe(signal, callback_handler_function)
        mbl_mw_acc_bmi160_enable_step_detector(device.board)
        mbl_mw_acc_start(device.board)
    
    ...        
    
    mbl_mw_acc_stop(self.device.board)
    mbl_mw_acc_bmi160_disable_step_detector(self.device.board)
    mbl_mw_datasignal_unsubscribe(signal)
    
  • @Laura said:
    PSEUDOCODE:

    mbl_mw_acc_bosch_set_range(device.board, 2G)
    mbl_mw_acc_set_odr(device.board, 25Hz)
    mbl_mw_acc_bosch_write_acceleration_config(device.board)

    let signal = mbl_mw_acc_bmi160_get_step_detector_data_signal(device.board)
    mbl_mw_datasignal_subscribe(signal, callback_handler_function)
    mbl_mw_acc_bmi160_enable_step_detector(device.board)
    mbl_mw_acc_start(device.board)

    ...

    mbl_mw_acc_stop(self.device.board)
    mbl_mw_acc_bmi160_disable_step_detector(self.device.board)
    mbl_mw_datasignal_unsubscribe(signal)

    Thanks will try again

  • edited February 2020

    @AKR, you might find this helpful: https://github.com/mbientlab/MetaWear-SDK-Cpp/blob/master/test/test_accelerometer_bmi160.py -> go to class TestBmi160StepCounterSetup(TestMetaWearBase):

Sign In or Register to comment.