标题: 各位大佬,问一下有关mpu6050自检函数的问题 [打印本页]

作者: avetuer    时间: 2021-10-25 14:18
标题: 各位大佬,问一下有关mpu6050自检函数的问题
mpu6050 自检的结果返回2,没有办法完成自检,可能是什么原因,我有将模块放平,而且将result=3改成2之后,能通过但是roll的值为177。
自检函数内部
        gyro_result = gyro_self_test(gyro, gyro_st);
        
    accel_result = accel_self_test(accel, accel_st);
//        delay_ms(100);
//   gyro_result = gyro_self_test(gyro, gyro_st);

    result = 0;
    if (!gyro_result)
        result |= 0x01;
    if (!accel_result)
        result |= 0x02;


自检函数外部
        result = mpu_run_self_test(gyro, accel);

        if (result == 0x2)//3 0
        {
                /* Test passed. We can trust the gyro data here, so let's push it down
                * to the DMP.
                */
                float sens;
                unsigned short accel_sens;
                mpu_get_gyro_sens(&sens);
                gyro[0] = (long)(gyro[0] * sens);
                gyro[1] = (long)(gyro[1] * sens);
                gyro[2] = (long)(gyro[2] * sens);
                dmp_set_gyro_bias(gyro);
                mpu_get_accel_sens(&accel_sens);

                accel[0] *= accel_sens;
                accel[1] *= accel_sens;
                accel[2] *= accel_sens;
                dmp_set_accel_bias(accel);
                return 0;
        }else return 1;


作者: avetuer    时间: 2021-10-25 14:23
  gyro_result = gyro_self_test(gyro, gyro_st); 的结果为04

static int gyro_self_test(long *bias_regular, long *bias_st)
{
    int jj, result = 0;
    unsigned char tmp[3];//3
    float st_shift, st_shift_cust, st_shift_var;
    if (i2c_read(st.hw->addr, 0x0D, 3, tmp))
        return 0x07;
       
    if (i2c_read(st.hw->addr, 0x0D, 7, tmp))
        return 0x07;
       
    tmp[0] &= 0x1F;
    tmp[1] &= 0x1F;
    tmp[2] &= 0x1F;
       
//        tmp[5] &= 0x1F;
//    tmp[6] &= 0x1F;
//    tmp[7] &= 0x1F;
       

    for (jj = 0; jj < 3; jj++) {
        st_shift_cust = labs(bias_regular[jj] - bias_st[jj]) / 65536.f;
        if (tmp[jj]) {
            st_shift = 3275.f / test.gyro_sens;
            while (--tmp[jj])
                st_shift *= 1.046f;
            st_shift_var = st_shift_cust / st_shift - 1.f;
            if (fabs(st_shift_var) > test.max_gyro_var)
                result |= 1 << jj;
        } else if ((st_shift_cust < test.min_dps) ||
            (st_shift_cust > test.max_dps))
            result |= 1 << jj;
    }

    return result;
}
作者: yzwzfyz    时间: 2021-10-25 15:44
自检函数是你自己写的吗?
作者: avetuer    时间: 2021-10-25 15:48
yzwzfyz 发表于 2021-10-25 15:44
自检函数是你自己写的吗?

在官方库函数上改动了一些,用的是硬件iic

作者: AUG    时间: 2021-10-25 17:46
考虑一下是不是硬件IIC的时序和MPU6050的时许有些许对不上




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1