Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving a problem with Core Motion gyro rotation
    primarykey
    data
    text
    <p>I'm working on an app that needs to detect a rotation gesture from the iPhone. I have written code that polls CMMotionManager for rotation data, but for some reason these values are constantly changing even though the phone is stationary on the table. I'm not sure what I am doing wrong here. I have consulted the Apple docs and it seems like I am doing what they suggest, and the thing does run without crashing, but the numbers that come out make no sense. Here is what I am doing:</p> <pre><code> -(void)startDetectingMotion { if (!motionQueue){ motionQueue = [[NSOperationQueue mainQueue] retain]; } if (motionManager.isDeviceMotionAvailable) { CMDeviceMotionHandler motionHandler = ^ (CMDeviceMotion *motion, NSError *error) { [self processMotion:motion withError:error]; }; [motionManager startDeviceMotionUpdatesToQueue:motionQueue withHandler:motionHandler]; } else { NSLog(@"motion not available"); } } </code></pre> <p>.....</p> <pre><code>-(void)processMotion:(CMDeviceMotion *)motion withError:(NSError *)error { CMRotationRate rotation = motion.rotationRate; if(rotation.y &gt; 2 || rotation.y &lt; -2) { NSLog(@"CM Motion X rotation:%f, Y rotation:%f, Z Rotation:%f", rotation.x, rotation.y, rotation.y); .... [self stopDetectingMotion]; } } </code></pre> <p>The point of trapping for y > 2 or &lt; 2 is to look for rapid rotation of the iphone on a horizontal plane, which is what I am looking for.</p> <p>The output looks like this:</p> <p>2010-08-15 16:15:43.475 PokerFoldTest[539:307] CM Motion X rotation:11.415660, Y rotation:7.865920, Z Rotation:7.865920</p> <p>2010-08-15 16:04:33.843 PokerFoldTest[539:307] CM Motion X rotation:8.925084, Y rotation:8.414384, Z Rotation:8.414384</p> <p>2010-08-15 16:11:14.314 PokerFoldTest[539:307] CM Motion X rotation:10.245130, Y rotation:-8.243847, Z Rotation:-8.243847</p> <p>2010-08-15 16:11:16.136 PokerFoldTest[539:307] CM Motion X rotation:10.212860, Y rotation:-4.303616, Z Rotation:-4.303616</p> <p>2010-08-15 16:11:18.242 PokerFoldTest[539:307] CM Motion X rotation:9.988654, Y rotation:-7.074587, Z Rotation:-7.074587</p> <p>2010-08-15 16:11:19.678 PokerFoldTest[539:307] CM Motion X rotation:16.092894, Y rotation:-10.562743, Z Rotation:-10.562743</p> <p>2010-08-15 16:15:41.662 PokerFoldTest[539:307] CM Motion X rotation:12.854285, Y rotation:7.247667, Z Rotation:7.247667</p> <p>As these numbers are supposed to be radians/sec rotation, they are suggesting that when the phone is stationary on the table it is spinning wildly. What the hell? Any chance my phone has a bad gyro?</p>
    singulars
    1. This table or related slice is empty.
    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.
    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