I have been working on the AR framework for some time and have been trying to upgrade from UIAccelerometer (deprecated) to CMMotionManager , but have I encountered some performance issues?
Basically, it seems that the CMMotionManager is much larger and slower than the UIAccelerometer. Has anyone encountered performance issues with CMMotionManager before?
As you can see here , I had this:
accelerometer = [UIAccelerometer sharedAccelerometer]; accelerometer.updateInterval = 0.01; [accelerometer setDelegate:self];
and
-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { rollingZ = (acceleration.z * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor)); rollingX = (acceleration.y * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor)); if (rollingZ > 0.0) currentInclination = inc_avg(atan(rollingX / rollingZ) + M_PI / 2.0); else if (rollingZ < 0.0) currentInclination = inc_avg(atan(rollingX / rollingZ) - M_PI / 2.0); else if (rollingX < 0) currentInclination = inc_avg(M_PI/2.0); else if (rollingX >= 0) currentInclination = inc_avg(3 * M_PI/2.0); }
and everything works fine even on "old" devices such as the iPhone 4 (not very old, but yes ...).
But when trying to use the same code, but with CMMotionManager:
motionManager = [[CMMotionManager alloc] init];
with
[motionManager setAccelerometerUpdateInterval:0.01]; [motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] withHandler: ^(CMAccelerometerData *accelerometerData, NSError *error){ rollingZ = (accelerometerData.acceleration.z * kFilteringFactor) + (rollingZ * (1.0 - kFilteringFactor)); rollingX = (accelerometerData.acceleration.y * kFilteringFactor) + (rollingX * (1.0 - kFilteringFactor)); if (rollingZ > 0.0) currentInclination = inc_avg(atan(rollingX / rollingZ) + M_PI / 2.0); else if (rollingZ < 0.0) currentInclination = inc_avg(atan(rollingX / rollingZ) - M_PI / 2.0); else if (rollingX < 0) currentInclination = inc_avg(M_PI/2.0); else if (rollingX >= 0) currentInclination = inc_avg(3 * M_PI/2.0); }];
Math seems to slow down shit. I say this because when I delete the entire math part, it works great.
The iPhone 5 will work fine, but the iPhone 4S will show signs of lag, and the iPhone 4 will just freeze ...
(I can give you more details if you want, but relatively difficult to explain)