The ratio of CoreMotion iOS 5 to the reference system does not work

I'm trying to use the new CoreMotion features, first of all, the ability to set a reference frame, but if I use DeviceMotionHandler, and the reference frame set to CMAttitudeReferenceFrameXTrueNorthZVertical, some of CMAttitudeReferenceFrameXArbitraryCorrectedZVertical is thrown. I run the application with iphone always in the same rotation as my table, and I test different initial rotation of the rotation, but the result is always the same.

motionManager = [[CMMotionManager alloc] init]; motionManager.showsDeviceMovementDisplay = YES; motionManager.deviceMotionUpdateInterval = 1.0/60.0; CMDeviceMotionHandler motionHandler = ^ (CMDeviceMotion *motion, NSError *error) { NSLog(@"%f %f %f", motion.attitude.pitch, motion.attitude.roll, motion.attitude.yaw); }; [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical toQueue:[NSOperationQueue currentQueue] withHandler:motionHandler]; 

I found a solution to my problem, but I can not understand why the previous code does not work. I add only the CMAttitude * a variable to motionHandler.

 - (void)viewDidLoad { [super viewDidLoad]; motionManager = [[CMMotionManager alloc] init]; motionManager.showsDeviceMovementDisplay = YES; motionManager.deviceMotionUpdateInterval = 1.0/60.0; CMDeviceMotionHandler motionHandler = ^ (CMDeviceMotion *motion, NSError *error) { CMAttitude *a = motionManager.deviceMotion.attitude; labelAngle.text = [NSString stringWithFormat:@"%f %f %f",a.pitch, a.roll,a.yaw]; labelAngle2.text = [NSString stringWithFormat:@"%f %f %f", motion.attitude.pitch, motion.attitude.roll, motion.attitude.yaw]; }; [motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXTrueNorthZVertical toQueue:[NSOperationQueue currentQueue] withHandler:motionHandler];} 
+6
source share
1 answer

I think this is because .. if you first define a handler, the relationship property of your motion object is already set to the default value. Later in your own code, this relationship property becomes read-only. So, when you start a motion update using this handler, the motion relation property can no longer be changed. But the motionManager.deviceMotion relationship property is set to whatever you specify in startDeviceMotionUpdatesUsingReferenceFrame, and this is read into the object when you start motion updates using startDeviceMotionUpdatesUsingReferenceFrame. The object now has the correct relation, while the motion object has the default relation.

0
source

Source: https://habr.com/ru/post/900208/


All Articles