我目前正在开发iOS项目,我使用的是运动数据。 我的俯仰和滚转值得到了很好的结果,但是偏航值不断漂移。我已经应用了卡尔曼滤波器,结果保持不变。 有谁知道如何解决它? 这是一些源代码(Objective C)
[self.motionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXArbitraryCorrectedZVertical
toQueue:[NSOperationQueue currentQueue]
withHandler:^(CMDeviceMotion *motion, NSError *error)
{
//NSString *yaw = [NSString
//stringWithFormat:@" %.3f", motion.attitude.yaw];
NSString *pitch = [NSString
stringWithFormat:@" %.3f", motion.attitude.pitch];
NSString *roll = [NSString
stringWithFormat:@" %.3f", motion.attitude.roll];
//Converting NSSring type variable in to a double
//double a_yaw = [yaw doubleValue];
double a_pitch = [pitch doubleValue];
double a_roll = [roll doubleValue];
CMQuaternion quat = self.motionManager.deviceMotion.attitude.quaternion;
double yaw = 180/M_PI * (asin(2*quat.x*quat.y + 2*quat.w*quat.z));
// Kalman filtering
static float q = 0.1; // process noise
static float r = 0.1; // sensor noise
static float p = 0.1; // estimated error
static float k = 0.5; // kalman filter gain
float x = motionLastYaw;
p = p + q;
k = p / (p + r);
x = x + k*(yaw - x);
p = (1 - k)*p;
motionLastYaw = x;
//Converting angles to degrees
//yaw = yaw * 180/M_PI;
a_pitch = a_pitch * 180/M_PI;
a_roll = a_roll * 180/M_PI;
答案 0 :(得分:0)
为了以最高精度完成这项任务,需要实施" yaw"更稳定的坐标系中的值。我有一个传感器9-DOF(陀螺仪,加速度计和磁力计),只有结合所有这些数据才能得到正确的输出......