sensor disconnection and counting steps with multiple sensors

Hello,  

I am trying to track accelerometer data tracking steps. In development we have run into one issue. Counting steps accurately using two devices. 


Challenge1-   Sometimes one of the sensors disconnects from the iOS device (stops displaying data). After a few seconds or less sometimes, the sensor reconnects and begins to display data. Is this an issue on our end or within the device?  


Challenge 2 - We are currently calculating the peaks and troughs of the accelerometer data in the Z-axis to count steps. However noise and the occasional disconnect randomly throws off the calculation.  Is there a simpler more accurate measurement for counting steps when using two sensors (kind of like tracking the impact of throwing punches)? 


Should we change the sampling rate? if so how?  or reduce noise? if so how?


For our application, counting steps based on impact forces is our intention. However if we must utilize another method of counting steps then we would gladly do so. 


What would be your suggestion for accurately counting steps with two sensors (left and right)? 


Thank you in advance for your time.

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; -webkit-text-stroke: #000000; min-height: 16.0px}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Verdana; -webkit-text-stroke: #000000}
li.li3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 16.0px Calibri; -webkit-text-stroke: #000000}
span.s1 {font-kerning: none}
ol.ol1 {list-style-type: decimal}

Comments

  • What board are you using and how fast are you streaming the data?
  • Hello Eric. The Board is BMI160. Sample Frequency is 50.  Scale: -2/+2
  • edited November 2016
    Metawear RG
  • edited November 2016
    The bmi160 has a step counter built into its firmware.  You can utilize that instead to avoid streaming larges amounts of acceleration data to your ios device.

    If you are intent on processing the raw data yourself, take a look at the fitness tracker app which has a step counter approximation using the rms values.
  • Hello,

    I
    have written the code for collecting combined data at the same from the
    2 sensors connected to the iOS device.

    The Board is BMI160. Sample Frequency is 50.  Scale: -2/+2
    As per your suggestion to zz3d, I also update framework of Metawear SDK and try to get step counter/ steps from sensors.
    but I am not able to get proper steps from each sensor. Please help me to get out of this.

    Here is the following code:

    for( MBLMetaWear *device in self.aDevices ) {
            NSLog(@%@",[device.accelerometer class]);
            @weakify( device );
           
            // start accelerometer
            [self.aStreamingEventsAccel addObject:device.accelerometer.dataReadyEvent];
            [device.accelerometer.dataReadyEvent startNotificationsWithHandlerAsync:^(MBLAccelerometerData* accel, NSError *error) {

                @strongify( self );
                @strongify( device );

                if( !error ) {

                    if( [self.delegate respondsToSelector:@selector(gotAccelerometerDeviceData:xVal:yVal:zVal:timestamp:)] ) {

                        NSLog(@xVal = %f, yVal = %f, zVal = %f, timestamp = %@",accel.x,accel.y,accel.z,accel.timestamp);
                        [self.delegate gotAccelerometerDeviceData:[self getDeviceIndex:device] xVal:accel.x yVal:accel.y zVal:accel.z timestamp:accel.timestamp];
                    }
                }
                else {

                    _ALOG( @%@", error.localizedDescription );
                }
            }];
           
            if ([device.accelerometer isKindOfClass:[MBLAccelerometerMMA8452Q class]])
              {
                MBLAccelerometerMMA8452Q *accelerometerMMA8452Q = (MBLAccelerometerMMA8452Q *)device.accelerometer;
                [self.streamingEvents addObject:accelerometerMMA8452Q.tapEvent];
                [accelerometerMMA8452Q.tapEvent startNotificationsWithHandlerAsync:^(MBLDataSample * _Nullable obj, NSError * _Nullable error) {
                    if (obj) {
                        NSLog(@Tap Count: %d, ++self.tapCount);
                    }
                }];
            }
            else if ([device.accelerometer isKindOfClass:[MBLAccelerometerBMI160 class]])
              {
         MBLAccelerometerBMI160 *accelerometerBMI160 = (MBLAccelerometerBMI160 *)device.accelerometer;
               
                [self.stepsSreamingEvents addObject:accelerometerBMI160.stepEvent];
                [accelerometerBMI160.stepEvent startNotificationsWithHandlerAsync:^(MBLNumericData * _Nullable obj, NSError * _Nullable error) {
                    @strongify( self );
                    @strongify( device );
                   
                    if (obj) {
                        if( !error ) {
                            if( [self.delegate respondsToSelector:@selector(gotstepsFromDeviceData:stepVal:timestamp:)] )
                              {
                                steps = ++self.accelerometerBMI160StepCount;
                                NSUInteger deviceIndex = [self.aDevices indexOfObject:device];
                                [self.delegate gotstepsFromDeviceData:[self getDeviceIndex:device] stepVal:steps timestamp:obj.timestamp];
                              }}
                        else{
                        _ALOG( @%@", error.localizedDescription );
                        }}}];}}


    self.aDevices = contains connected MetaWear sensors array
    in delegate method m just using step value to display for Left steps/Right steps.

    Challenge 1: Sometimes my sensors gets step events while they are steady on table.
    Challenge 2: Also step events count from 2 steps per sensors, sometimes it gives 4 steps in one reading or more. I'm getting stuck to minimize this. is it kind of Firmware issue?

    What would be your suggestion for accurately counting steps with two sensors (left and right)? 

    Thank you in advance for your time.

  • How frequently are you reading the step counter?  Also, have you tried using the step counter by itself and with only one device?  That is, no acceleration streaming and no tap detection.
  • trttrt
    edited January 2017
    Hello Eric,
    Thanks for reply.

    I had tried both way to read step counter.
    1. I had add step event after connect sensor successful and write below code,
     self.stepEvent = [[accel.stepCounter periodicReadWithPeriod:500] differentialSampleOfEvent:60000];
            [self.stepEvent startLoggingAsync];

    than I used to download data in every 1 min of time interval.

    2. I had add step event after getting accel data from device ,after loop through each device I had added step event and read data at a time. here is code.

    for( MBLMetaWear *device in self.aDevices ) {

    MBLAccelerometerBMI160 *accelerometerBMI160 = (MBLAccelerometerBMI160 *)self.device.accelerometer;
        [self.streamingEvents addObject:accelerometerBMI160.stepEvent];
        [accelerometerBMI160.stepEvent startNotificationsWithHandlerAsync:^(MBLNumericData * _Nullable obj, NSError * _Nullable error) {
            if (obj) {
                self.accelerometerBMI160StepLabel.text = [NSString stringWithFormat:@Step Count: %d, ++self.accelerometerBMI160StepCount];
            }
        }];
    }

    where, self.aDevices = Array of connected sensor.

    Also, have you tried using the step counter by itself and with only one device?
    - Yes, I had tried it with only one device also, but I'm getting twice steps. I don't know why, but I though it refresh setting.
     accel.tapType = (int)0; (MBLAccelerometerTapTypeSingle)

    Let me know where I'm wrong or doing mistake to read step counter?

    I need accurate step counter because my app is based on only that. Help me to get out of this.

    again, Thank you so much for your time.
  • One thing that may be causing confusion is that the stepCounter on counts when stepEvent is activated.

    Aside from that, can you erase the app from your iOS device just to confirm a clean start and then try out the stepEvent on just one device:
    [accelerometerBMI160.stepEvent startNotificationsWithHandlerAsync:^(MBLNumericData *obj, NSError * error) {
    NSLog(@%@", obj);
    }];
       
  • trttrt
    edited January 2017
    Hello stephen,
    Thanks for reply
  • Also, can you confirm if you are using two devices, one mounted on the right leg and one of the left?  The step detector is sensitive enough to register a step taken by either leg, so maybe this could explain your "getting twice steps"?  If not, can you explain your exact configuration and experiment where double steps are being recorded?

    Thanks!
    -Stephen
  • Hello Stephen,

    Let me explain my scenario, I'm using two Metawear sensor at a time and get connected one by one. (this devices are stored in my global array). Currently I'm assume that index=0 is Left leg sensor and index=1 is Right leg sensor (though i can not figure out which one is right/left sensor at a time). Than I add step event while getting Accel data for a device within For loop, and calculating offset.

    Regarding twice steps, it's happen when I'm using startNotificationsWithHandlerAsync, but whenever I disconnect device i'm not using stopNotificationsAsync. I think this is the problem where data are stored on flash memory of sensor. M I right?

    one more confusing thing happen, whenever I check device.accelerometer, sometimes it gives me MBLAccelerometerMMA8452Q and sometimes it gives me MBLAccelerometerBMI160.

    Thanks for figure out issues and help me to get out of this situation. I'll let you know what happen or what result I get after add stopNotificationsAsync.
    stopNotificationsAsync and
  • Hello Stephen,

    Step event give me always +1 interval which is right as per documentation. Is it possible that I'm using for loop  to print a step of each sensor along with delegate method to another class. So is there any possibility of loop hole in code to get twice steps per sensor at a time?

    Waiting for your suggestion.
    Thanks for co-ordination. :)


    Thanks!
    - Trupti
  • - Not calling stopNotificationsAsync:
    This is okay, we understand that unexpected disconnects occur and so the SDK will take care of cleaning up any un-used notifications next time you connect.

    MBLAccelerometerMMA8452Q vs MBLAccelerometerBMI160:
    This is odd, the type shouldn't change, is it possible you are connecting to different types of MetaWears?  If you can reproduce this let me know.

    It's hard for me to comment further on the "twice steps per sensor", since it appears the the event itself is producing the correct data.  It could likely be some issue with the for loop or delegate methods as you suggested.

    Thanks,
    -Stephen
This discussion has been closed.