我无法弄清楚为什么在记录时滚动、俯仰和偏航值给出 0.0000.. 我确定这是我想念的东西,但我无法弄清楚..
这是代码:
//ViewController.m
#import "ViewController.h"
@interface ViewController (){
}
@property (nonatomic) CMMotionManager *motionManager;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.motionManager = [[CMMotionManager alloc] init];
CMDeviceMotion *devMotion = [[CMDeviceMotion alloc]init];
if ([self.motionManager isDeviceMotionAvailable]) {
NSLog(@"Device Motion Available");
[self.motionManager setDeviceMotionUpdateInterval:1.0/30.0];
// Pull mechanism is used
[self.motionManager startDeviceMotionUpdates];
}
devMotion = self.motionManager.deviceMotion;
NSLog(@"Roll Pitch and Yaw are %f, %f, %f",devMotion.attitude.roll, devMotion.attitude.pitch, devMotion.attitude.yaw);
}
我已经解决了这个类似的问题:SO Question
请帮助我理解这一点..
谢谢..
更新代码:
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.motionManager = [[CMMotionManager alloc] init];
if ([self.motionManager isDeviceMotionAvailable]) {
NSLog(@"Device Motion Available");
[self.motionManager setDeviceMotionUpdateInterval:1.0/30.0];
// Pull mechanism is used
[self.motionManager startDeviceMotionUpdates];
}
CMDeviceMotion *devMotion = self.motionManager.deviceMotion;
NSLog(@"*Roll,Pitch and Yaw are %f, %f, %f",devMotion.attitude.roll, devMotion.attitude.pitch, devMotion.attitude.yaw);
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0/30.0 target:self selector:@selector(updateValues:) userInfo:nil repeats:YES];
}
-(void) updateValues:(NSTimer *)timer{
CMDeviceMotion *currDeviceMotion = self.motionManager.deviceMotion;
NSLog(@"Roll Pitch and Yaw are %f, %f, %f",currDeviceMotion.attitude.roll, currDeviceMotion.attitude.pitch, currDeviceMotion.attitude.yaw);
}
这段代码也有很大一部分初始值为 0.000000 。之后它开始获得价值......所以我想startDeviceMotionUpdates
为提供价值有一些延迟deviceMotion
。所以看起来我需要弄清楚如何保存第一个非零值。