CMMotionManager deviceMotion态度值过度“闪烁”

时间:2013-04-09 19:03:17

标签: ios gyroscope core-motion

我正在记录我在CADisplayLink回调中从CMMotionManager deviceMotion获得的“态度”值(我需要根据设备旋转执行动画)。

这些值似乎每隔几毫秒就会“抽搐”很多程度(高达30%)。这似乎有很多不稳定因素,让我想知道我做错了什么,或者它是否与设备有关。

请查看下面的日志。印刷的“角度”是“态度”的“滚动”部分,转换为度:


2013-04-10 00:07:12.683 MyApp[450:707] Angle: -92.91
2013-04-10 00:07:12.712 MyApp[450:707] Angle: -70.52
2013-04-10 00:07:12.714 MyApp[450:707] Angle: -92.25
2013-04-10 00:07:12.745 MyApp[450:707] Angle: -70.03
2013-04-10 00:07:12.747 MyApp[450:707] Angle: -91.74
2013-04-10 00:07:12.779 MyApp[450:707] Angle: -69.67
2013-04-10 00:07:12.784 MyApp[450:707] Angle: -91.23
2013-04-10 00:07:12.812 MyApp[450:707] Angle: -69.43
2013-04-10 00:07:12.815 MyApp[450:707] Angle: -91.19
2013-04-10 00:07:12.846 MyApp[450:707] Angle: -69.53
2013-04-10 00:07:12.849 MyApp[450:707] Angle: -91.33
2013-04-10 00:07:12.879 MyApp[450:707] Angle: -69.74
2013-04-10 00:07:12.881 MyApp[450:707] Angle: -91.57
2013-04-10 00:07:12.912 MyApp[450:707] Angle: -70.01
2013-04-10 00:07:12.915 MyApp[450:707] Angle: -91.85
2013-04-10 00:07:12.945 MyApp[450:707] Angle: -70.13
2013-04-10 00:07:12.949 MyApp[450:707] Angle: -91.99
2013-04-10 00:07:12.979 MyApp[450:707] Angle: -70.03
2013-04-10 00:07:12.983 MyApp[450:707] Angle: -91.93
2013-04-10 00:07:13.012 MyApp[450:707] Angle: -69.76
2013-04-10 00:07:13.016 MyApp[450:707] Angle: -91.71
2013-04-10 00:07:13.046 MyApp[450:707] Angle: -69.34
2013-04-10 00:07:13.051 MyApp[450:707] Angle: -91.19
2013-04-10 00:07:13.079 MyApp[450:707] Angle: -68.89
2013-04-10 00:07:13.082 MyApp[450:707] Angle: -90.94
2013-04-10 00:07:13.112 MyApp[450:707] Angle: -68.52
2013-04-10 00:07:13.114 MyApp[450:707] Angle: -90.66
2013-04-10 00:07:13.151 MyApp[450:707] Angle: -67.85
2013-04-10 00:07:13.156 MyApp[450:707] Angle: -89.47
2013-04-10 00:07:13.179 MyApp[450:707] Angle: -65.66
2013-04-10 00:07:13.181 MyApp[450:707] Angle: -88.10
2013-04-10 00:07:13.212 MyApp[450:707] Angle: -63.81
2013-04-10 00:07:13.216 MyApp[450:707] Angle: -86.33
2013-04-10 00:07:13.245 MyApp[450:707] Angle: -61.07
2013-04-10 00:07:13.248 MyApp[450:707] Angle: -83.63
2013-04-10 00:07:13.279 MyApp[450:707] Angle: -58.95
2013-04-10 00:07:13.282 MyApp[450:707] Angle: -81.46
2013-04-10 00:07:13.312 MyApp[450:707] Angle: -56.71
2013-04-10 00:07:13.314 MyApp[450:707] Angle: -79.06
2013-04-10 00:07:13.346 MyApp[450:707] Angle: -53.29
2013-04-10 00:07:13.350 MyApp[450:707] Angle: -75.23
2013-04-10 00:07:13.380 MyApp[450:707] Angle: -51.63
2013-04-10 00:07:13.383 MyApp[450:707] Angle: -73.37
2013-04-10 00:07:13.414 MyApp[450:707] Angle: -50.35
2013-04-10 00:07:13.418 MyApp[450:707] Angle: -72.11
2013-04-10 00:07:13.446 MyApp[450:707] Angle: -50.08
2013-04-10 00:07:13.450 MyApp[450:707] Angle: -72.01
2013-04-10 00:07:13.479 MyApp[450:707] Angle: -50.50
2013-04-10 00:07:13.488 MyApp[450:707] Angle: -73.51
2013-04-10 00:07:13.512 MyApp[450:707] Angle: -51.25
2013-04-10 00:07:13.514 MyApp[450:707] Angle: -74.14
2013-04-10 00:07:13.545 MyApp[450:707] Angle: -49.98
2013-04-10 00:07:13.547 MyApp[450:707] Angle: -72.96
2013-04-10 00:07:13.579 MyApp[450:707] Angle: -46.99
2013-04-10 00:07:13.582 MyApp[450:707] Angle: -68.58
2013-04-10 00:07:13.612 MyApp[450:707] Angle: -43.01
2013-04-10 00:07:13.616 MyApp[450:707] Angle: -65.32
2013-04-10 00:07:13.645 MyApp[450:707] Angle: -40.92
2013-04-10 00:07:13.647 MyApp[450:707] Angle: -62.80
2013-04-10 00:07:13.680 MyApp[450:707] Angle: -39.70
2013-04-10 00:07:13.683 MyApp[450:707] Angle: -61.30
2013-04-10 00:07:13.712 MyApp[450:707] Angle: -40.74
2013-04-10 00:07:13.714 MyApp[450:707] Angle: -63.06
2013-04-10 00:07:13.745 MyApp[450:707] Angle: -42.29
2013-04-10 00:07:13.747 MyApp[450:707] Angle: -65.68
2013-04-10 00:07:13.779 MyApp[450:707] Angle: -43.18
2013-04-10 00:07:13.780 MyApp[450:707] Angle: -67.58
2013-04-10 00:07:13.812 MyApp[450:707] Angle: -42.13
2013-04-10 00:07:13.815 MyApp[450:707] Angle: -66.35
2013-04-10 00:07:13.845 MyApp[450:707] Angle: -40.95
2013-04-10 00:07:13.848 MyApp[450:707] Angle: -64.67
2013-04-10 00:07:13.879 MyApp[450:707] Angle: -39.73
2013-04-10 00:07:13.881 MyApp[450:707] Angle: -62.90
2013-04-10 00:07:13.913 MyApp[450:707] Angle: -40.06
2013-04-10 00:07:13.916 MyApp[450:707] Angle: -63.12
2013-04-10 00:07:13.947 MyApp[450:707] Angle: -40.78
2013-04-10 00:07:13.949 MyApp[450:707] Angle: -63.39
2013-04-10 00:07:13.979 MyApp[450:707] Angle: -41.51
2013-04-10 00:07:13.981 MyApp[450:707] Angle: -62.78
2013-04-10 00:07:14.012 MyApp[450:707] Angle: -42.06
2013-04-10 00:07:14.014 MyApp[450:707] Angle: -61.77
2013-04-10 00:07:14.045 MyApp[450:707] Angle: -43.89
2013-04-10 00:07:14.047 MyApp[450:707] Angle: -61.02
2013-04-10 00:07:14.079 MyApp[450:707] Angle: -45.41
2013-04-10 00:07:14.080 MyApp[450:707] Angle: -61.20
2013-04-10 00:07:14.112 MyApp[450:707] Angle: -46.93
2013-04-10 00:07:14.114 MyApp[450:707] Angle: -61.53
2013-04-10 00:07:14.146 MyApp[450:707] Angle: -49.21
2013-04-10 00:07:14.147 MyApp[450:707] Angle: -62.76
2013-04-10 00:07:14.179 MyApp[450:707] Angle: -51.34
2013-04-10 00:07:14.182 MyApp[450:707] Angle: -64.51
2013-04-10 00:07:14.212 MyApp[450:707] Angle: -53.39
2013-04-10 00:07:14.214 MyApp[450:707] Angle: -66.41
2013-04-10 00:07:14.245 MyApp[450:707] Angle: -56.29
2013-04-10 00:07:14.248 MyApp[450:707] Angle: -69.30
2013-04-10 00:07:14.279 MyApp[450:707] Angle: -57.85
2013-04-10 00:07:14.280 MyApp[450:707] Angle: -70.88
2013-04-10 00:07:14.312 MyApp[450:707] Angle: -60.23

测量的角度每几毫秒“闪烁”几乎20度。根据我到目前为止读到的关于CoreMotion的内容,我期待错误,但不是这个范围。

我可能做错了什么 - 我不是在衡量正确的事吗?



编辑:下面的代码 - 抱歉格式化。 “code”和“blockquote”似乎都无法正常工作。


//在开始动作更新之前,我让用户稍稍休息一下。
//目前,这是一个天真的空闲计时器,之后被解雇
//启动应用程序的前9秒(正当理由)


- (void)didFireIdleTimer:(id)theTimer {

[mReferenceAttitude release];
mReferenceAttitude = [[[sSharedMotionManager deviceMotion]态度]保留];

[self stopIdleTimer];
}

// sSharedMotionManager是CMMotionManager的一个实例

//然后,我正在设置一个显示链接回调,其中“当前”的deviceMotion
每次检索//和当前“态度”之间的差异
//并参考“态度”计算。正是这种差异
//转换为度数并打印

//这是显示链接回调,懒洋洋地命名。 :)
- (void)didRefreshScreen:(id)sender {

CMAttitude * thisAttitude = [[sSharedMotionManager deviceMotion]态度];
[thisAttitude multiplyByInverseOfAttitude:mReferenceAttitude];

NSLog(@“Angle:%0.2f”,thisAttitude.roll * 180 / 3.14159);

//其余代码
// ....
}

3 个答案:

答案 0 :(得分:1)

几小时的测试确认问题出现是因为deviceMotionUpdateInterval实例未设置CMMotionManager。将其设置为1.0/60.0(或任何其他有效值)可修复此“闪烁”并导致值平滑变化。

答案 1 :(得分:0)

看看这些值,我注意到每一秒测量的系列似乎都没问题。这意味着1,3,5,7,......和2,4,6,8 ......是稳定的稳定序列。在大多数情况下,这表示正在运行2个实例或切换参考姿态。

答案 2 :(得分:0)

这是我的代码,以避免在may app中闪烁:

float xAxis,yAxis, zAxis;
xAxis = self.manager.accelerometerData.acceleration.x;
yAxis = self.manager.accelerometerData.acceleration.y;
zAxis = self.manager.accelerometerData.acceleration.z;

// returns if the phone is lying on the table:
if (zAxis < -0.8 || zAxis > 0.8) return;

CGFloat angle =  atan2f(xAxis, yAxis ); // The angle!!!

float noise = 0.011; // Flicker noise (the noise you want to filter)

// max and min are global variables
if (angle > max){
    max = angle;
    min = max - noise;
}
if (angle < min){
    min = angle;
    max = min + noise;
}

// Average: (no flickering):
angle = min + (max - min) / 2.0;