iphone - Coremotion加速始终为零!

时间:2010-11-12 18:06:40

标签: iphone

我正在尝试使用CoreMotion获取设备加速。我有这段代码:

用于设置

if (motionManager == nil) 
        motionManager = [[CMMotionManager alloc] init];

motionManager.deviceMotionUpdateInterval = framesPorKeyframes / 60.0; //60 Hz
motionManager.accelerometerUpdateInterval =  framesPorKeyframes / 60.0; //60 Hz

[motionManager startDeviceMotionUpdates];
referenceAttitude = nil;

阅读

vec3f_t translation = {0.0f, 0.0f, 0.0f};
CMRotationMatrix rotation;
CMAcceleration userAcceleration;


CMDeviceMotion *deviceMotion = motionManager.deviceMotion;      
attitude = deviceMotion.attitude;

rotation = attitude.rotationMatrix;

userAcceleration = deviceMotion.userAcceleration;
[userAccelerationLpf addAcceleration:userAcceleration withTimestamp:deviceMotion.timestamp];

// The user acceleration we want to use is the one computed by userAccelerationLpf
userAcceleration.x = userAccelerationLpf.x;
userAcceleration.y = userAccelerationLpf.y;
userAcceleration.z = userAccelerationLpf.z; 

NSLog(@"acc = %f, %f, %f", userAcceleration.x, userAcceleration.y, userAcceleration.z);

我在这里所有的都是零!!!!!!!!!

读取方法以30 Hz重复。

这是从Apple样本中获取的,不应该给我零! 任何线索?

感谢。

1 个答案:

答案 0 :(得分:3)

如果放下低通滤波器并记录原始加速度,您会看到什么? (我打赌我知道答案:)