【问题标题】:Get accelerometer and gyroscope data from apple watch (and not the iphone)?从苹果手表(而不是 iPhone)获取加速度计和陀螺仪数据?
【发布时间】:2015-09-09 18:37:58
【问题描述】:

看到this question 后,我尝试编写一个快速程序,将手表加速度计和陀螺仪数据保存到文件中。

@implementation InterfaceController{
    NSMutableArray *accData;
    bool recording;
}
- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];
    // Configure interface objects here.
    self.motionManager = [[CMMotionManager alloc] init];
    [self.motionManager setAccelerometerUpdateInterval:.01];
}

- (IBAction)startStopRecording {
    if (!recording){//We are starting to record.
        recording = YES;
        accData = [[NSMutableArray alloc] init];
        [self.startRecording setTitle:@"Stop Recording"];
        [self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
            [accData addObject:[NSString stringWithFormat:@"%f, %f, %f", accelerometerData.acceleration.x, accelerometerData.acceleration.y, accelerometerData.acceleration.z]];
        }];
    }else{
        recording = NO;//we are stopping the recording
        [self.motionManager stopAccelerometerUpdates];
        [self.startRecording setTitle:@"Start Recording"];
        [InterfaceController openParentApplication:@{ @"accData": accData } reply:^(NSDictionary *replyInfo, NSError *error) { //this method saves the array to a csv file.
            NSLog(@"Data has been saved.");
        }];
    }
}

我已经绘制了这些数据,并且在我的一生中,无论我如何用力摇晃手表,我的所有图表都是这样的:

直到 8 小时后,我开始怀疑我不是从手表上获取加速度数据,而是从手机(仍然坐在我旁边的桌子上)获取的。我进行了一些测试并确认这正是正在发生的事情。

这让我想到了最初的问题。如何从手表而不是 iPhone 中提取加速度/陀螺仪/数据?

【问题讨论】:

    标签: ios watchkit core-motion cmmotionmanager


    【解决方案1】:

    问题是我没有运行 watchOS2。我以为我是,但它仍处于测试阶段,我还没有安装它。我得到的数据是来自手机的加速度计数据。另外,目前只能使用watchOS2从手表获取acc数据,不能获取陀螺数据。

    【讨论】:

      【解决方案2】:

      您可以使用 CoreMotion 框架来获取活动数据。 虽然我只能获取加速度数据,但陀螺仪经常返回 false。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-29
        • 1970-01-01
        • 2010-12-07
        • 1970-01-01
        相关资源
        最近更新 更多