2

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

这些值似乎每隔几毫秒就会“抽搐”很大程度(高达 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] 态度] 保留];

[自停止空闲定时器];
}

//sSharedMotionManager 是 CMMotionManager 的一个实例

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

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

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

NSLog(@"角度:%0.2f", thisAttitude.roll * 180 / 3.14159);

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

3 回答 3

1

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

于 2013-04-12T07:09:40.417 回答
0

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

于 2013-04-10T08:42:23.917 回答
0

这是我的代码,以避免在可能的应用程序中闪烁:

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;
于 2014-05-23T02:57:34.603 回答