Note that there are some explanatory texts on larger screens.

plurals
  1. POCMMotionManager vs UIAccelerometer efficiency
    primarykey
    data
    text
    <p>I've been working on an <a href="https://github.com/promet/PRAugmentedReality" rel="nofollow">AR framework</a> for a while now and am trying to <a href="https://github.com/promet/PRAugmentedReality/issues/23" rel="nofollow">update from UIAccelerometer (deprecated) to CMMotionManager</a> but am running into some efficiency problems?</p> <p>Basically it seems like CMMotionManager is MUCH larger and slower than UIAccelerometer is. Has anyone experienced performance issues with CMMotionManager before?</p> <hr> <p>As you can see <a href="https://github.com/promet/PRAugmentedReality/blob/master/Classes/Location/LocationWork.m" rel="nofollow">here</a>, I had this:</p> <pre><code>accelerometer = [UIAccelerometer sharedAccelerometer]; accelerometer.updateInterval = 0.01; [accelerometer setDelegate:self]; </code></pre> <p>and</p> <pre><code>-(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 &gt; 0.0) currentInclination = inc_avg(atan(rollingX / rollingZ) + M_PI / 2.0); else if (rollingZ &lt; 0.0) currentInclination = inc_avg(atan(rollingX / rollingZ) - M_PI / 2.0); else if (rollingX &lt; 0) currentInclination = inc_avg(M_PI/2.0); else if (rollingX &gt;= 0) currentInclination = inc_avg(3 * M_PI/2.0); } </code></pre> <p>and all works great even on "older" devices like the iPhone 4 (not really old but yea...).</p> <p>But when trying the exact same code but with CMMotionManager:</p> <pre><code>motionManager = [[CMMotionManager alloc] init]; </code></pre> <p>with</p> <pre><code>[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 &gt; 0.0) currentInclination = inc_avg(atan(rollingX / rollingZ) + M_PI / 2.0); else if (rollingZ &lt; 0.0) currentInclination = inc_avg(atan(rollingX / rollingZ) - M_PI / 2.0); else if (rollingX &lt; 0) currentInclination = inc_avg(M_PI/2.0); else if (rollingX &gt;= 0) currentInclination = inc_avg(3 * M_PI/2.0); }]; </code></pre> <p>The math seems to slow the crap out of it..! I say this because when I remove all the math part it works great.</p> <p>An iPhone 5 will work alright but an iPhone 4S will show signs of lag and the iPhone 4 will just freeze... </p> <p>(I can give you more details if you want but its relatively complicated to explain)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload