金牌会员
积分 1394
金钱 1394
注册时间 2016-6-2
在线时间 166 小时
1 金钱
本帖最后由 hyarcher25 于 2019-1-25 21:09 编辑
使用mpu9250 dmp方式获取欧拉角 用原子哥的程序是 飞机是以初始静止位置为参照。即水平放置,上电后获取的欧拉角为0;飞机倾斜一些角度放置稳定,上电初始化后,获取到的欧拉角也是0。这个已经调试好。
但有没有办法能够在初始化时获取到实际的相对于水平面的pitch和roll角度呢?例如我倾斜30°放置,上电后得到的pitch或者roll就是30°,之后再放平,则得到角度为0°。?
看了论坛这个帖子 http://www.openedv.com/posts/list/54174.htm 已经改好了,但获取的角度还是不对
//MPU9250自测试
//返回 0正常 1失败
u8 run_self_test(void)
{
int result;
//char test_packet[4] = {0};
long gyro[3], accel[3];
result = mpu_run_self_test(gyro, accel);
if (result == 0x07)
{
/* 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;
}
u8 mpu_dmp_init(void)
{
u8 res=0;
if(mpu_init()==0)
{
res=mpu_set_sensors(INV_XYZ_GYRO|INV_XYZ_ACCEL);
if(res)return 1;
res=mpu_configure_fifo(INV_XYZ_GYRO|INV_XYZ_ACCEL);
if(res)return 2;
res=mpu_set_sample_rate(DEFAULT_MPU_HZ);
if(res)return 3;
res=dmp_load_motion_driver_firmware();
if(res)return 4;
res=dmp_set_orientation(inv_orientation_matrix_to_scalar(gyro_orientation));
if(res)return 5;
res=dmp_enable_feature(DMP_FEATURE_6X_LP_QUAT|DMP_FEATURE_TAP|
DMP_FEATURE_ANDROID_ORIENT|DMP_FEATURE_SEND_RAW_ACCEL|DMP_FEATURE_SEND_CAL_GYRO|
DMP_FEATURE_GYRO_CAL);
if(res)return 6;
res=dmp_set_fifo_rate(DEFAULT_MPU_HZ);
if(res)return 7;
res=run_self_test();
if(res)return 8;
res=mpu_set_dmp_state(1);
if(res)return 9;
}else return 10;
return 0;
}
我来回答