I just want to get some gyroscope data with Core Motion from my iPhone 4 but always get roll=0, pitch=0 and yaw=0. After intensive search I recognized that
if (motionManager.isDeviceMotionAvailable)
{
[motionManager startDeviceMotionUpdates];
}
returns false, although I run it on an iPhone 4. Do I have to enable the gyro in the settings? Or what could I do wrong…?
Thats my reduced interface:
@interface GameLayer : CCLayer {
CMMotionManager *motionManager;
}
@property (nonatomic, retain) CMMotionManager *motionManager;
@end
And this is where I implement the motionManager:
- (id) init
{
self=[super init];
if(self)
{
self.motionManager = [[[CMMotionManager alloc] init] autorelease];
motionManager.deviceMotionUpdateInterval = 1.0/60.0;
if (motionManager.isDeviceMotionAvailable)
{
[motionManager startDeviceMotionUpdates];
}
else
{
NSLog(@"No motion captured");
}
[self scheduleUpdate];
}
return self;
}
and the loop where it's called:
- (void) update:(ccTime)delta
{
CMDeviceMotion *currentDeviceMotion = motionManager.deviceMotion;
motionManager.showsDeviceMovementDisplay = YES;
CMAttitude *currentDeviceAttitude = currentDeviceMotion.attitude;
float roll = currentDeviceAttitude.roll;
float pitch = currentDeviceAttitude.pitch;
float yaw = currentDeviceAttitude.yaw;
}
motionManager
is notnil
and that you are actually running on device and not the simulator. – schmotionManager
? Can you post the code? – Manlio