603133791 发表于 2014-7-2 15:43:00

姿态解算的一点疑问

        //Attitude estimation
        AttitudeFilter(&gyro, &acc, &acc_filter, MixConstant);
        AttitudeFilter(&gyro, &mag, &mag_filter, 0.950f);//那为什么数字罗盘测出来的数据也要这么干?
       
        RPY = CalculateRollPitchYaw(&acc_filter, &mag_filter); //acc_filter较为准确的重力加速度向量

//MPU6050->gyrox-->pitch
//                   gyroy-->roll
//         gyroz-->yaw
inline void AttitudeFilter(vector_f *gyro, vector_i *acc, vector_i *acc_filter, float mixConstant)
{//complementation filter
        //calculate acc vector based on last value and gyroscope value
        vector_f acc_gyro;
        vector_f delta_theta;
        int32_t acceleration;
        float mixConstant1;
        acc_gyro.x = acc_filter->x;
        acc_gyro.y = acc_filter->y;
        acc_gyro.z = acc_filter->z;
        delta_theta.y = gyro->x * dt;
        delta_theta.x = gyro->y * dt;
        delta_theta.z = gyro->z * dt;//陀螺仪的值乘以dt,这个在方向余弦旋转变换矩阵中有出现过。
        rotateV(&acc_gyro, &delta_theta);
       
//        acceleration = acc->x*acc->x + acc->y*acc->y + acc->z*acc->z;
       
        //if acceleration<8m/s2 or acceleration>12m/s2, don't use acceleration information
//        if(acceleration<64000000 || acceleration>144000000)
//                mixConstant = 1.0f;
       
        //Complementary filter
        mixConstant1 = 1.0f - mixConstant;
        acc_filter->x = acc_gyro.x * mixConstant + acc->x * mixConstant1;//acc_filter的值是陀螺仪和上一次姿态估算出的值。而acc就是此次加速度计的值,在这两个值作一个加权。只要时间足够上的话,最后的值还是等于加速度计的值,也就是准确的值。
        acc_filter->y = acc_gyro.y * mixConstant + acc->y * mixConstant1;
        acc_filter->z = acc_gyro.z * mixConstant + acc->z * mixConstant1;
        //此时acc_gyro的值就是经过了旋转矩阵处理之后的值。是通过上次的估计出这次的数据,灵气来源是陀螺仪。而后和加速度计的值来一个加权平均。
}


//Calculate roll/pitch/yaw
//Roll:ret.x        -180~180 deg
//Pitch:ret.y        -90~90 deg
//yaw:ret.z                -180~180 deg
inline vector_f CalculateRollPitchYaw(vector_i *acc, vector_i *mag)
{
        vector_f temp;

        temp.x = atan2f(acc->x, acc->z);
        temp.y = asinf(acc->y/sqrtf(acc->x*acc->x + acc->y*acc->y + acc->z*acc->z));
        temp.z = -atan2f(mag->y*cos(temp.y) - mag->z*sin(temp.y),
                                        -mag->y*sin(temp.x)*sin(temp.y) + mag->x*cos(temp.x) - mag->z*sin(temp.x)*cos(temp.y)) * 57.30f;
        temp.x *= 57.30f;
        temp.y *= 57.30f;
        return temp;
}


通过陀螺仪测量得到的数据作为旋转矩阵来估计重力矢量,再和加速度计测得的重力矢量进行一下加权,得到最后的重力加速度的矢量值。

这是我自己理解的,但是我不懂得为什么电子罗盘得到的数值要和陀螺仪的数据进行融合。而且最后求出姿态角(个人认为是欧拉角),那个解算的过程是怎样的,求解的过程是怎样的,我不是很理解啊。

老衲人称秃驴 发表于 2014-7-2 16:33:19

因为陀螺仪积分会发散,需要加速计校正,个人理解

603133791 发表于 2014-7-2 19:09:26

但就是不知道具体的过程为什么是这样的,比如公式为什么是这样的。这好像是参考MWC的。
页: [1]
查看完整版本: 姿态解算的一点疑问