0

i am gathering accelerometer and gyroscope data using push methods( startDeviceMotionUpdatesToQueue:withHandler: and startGyroUpdatesToQueue:[NSOperationQueue mainQueue] I compare these raw data with certain thresholds, if it satisfies the threshold, I do increase a label counter by one , my problem is when I start detecting ie reading the methods and comparing it to thresholds , the counter increases so fast, I have read in (Simple iPhone motion detect) that " if condition will become true twice for every single motion" , so if this is what is happening with me, how do i solve the problem, my code is simple

checkData{

if ( (  acc_2 >= 0.03885) &&  (gyro_3  >= 0.0003)  && (gyro_3 <= 0.00838))
{
    i=i+1;
    //then Label data
    _Counter.text=[NSString stringWithFormat:@"%d",i];

}

else if (( acc_2>= 0.01103) && ( gyro_3 >= 0.00851))
{
    /

    //update the counter
    i=i+1;
    _Counter.text=[NSString stringWithFormat:@"%d",i];

}

...... same other conditions

}

then I do call this method inside startDeviceMotionUpdatesToQueue:withHandler: block.

[ self checkData];

what can i do to fix the problem, can you guide me ? }

Community
  • 1
  • 1
Dina
  • 467
  • 4
  • 18

1 Answers1

0

I'm not 100% sure if this is what you're asking, but if you're looking to change the rate a which you receive updates from the hardware, which would then slow the rate at which your label updates (and save battery), you could use CMMotionManager's setGyroUpdateInterval: and setDeviceMotionUpdateInterval: to adjust the refresh rate. A value of 1 is update once per second.

[_myMotionManager setDeviceMotionUpdateInterval:1];
[_myMotionManager setGyroUpdateInterval:1];
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
  • i have the two updateIntervalset as 1/30, and i need frequent readings, but is this what it cause my label to jump from 0 to 6 then 18 then 28 i feel the updates of label is so high, and the note ( about the if)that was mentioned in the question made me wondering, if this is what is leading to this kind of jumps in the counter. – Dina Aug 29 '13 at 20:00