sensor disconnection and counting steps with multiple sensors
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
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.
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.
Thanks for reply
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
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