初级会员

- 积分
- 63
- 金钱
- 63
- 注册时间
- 2013-2-13
- 在线时间
- 0 小时
|

楼主 |
发表于 2013-6-27 17:36:31
|
显示全部楼层
回复【6楼】mygod:
---------------------------------
float MPU6050_Get_Acc_Angle(MPU_TypeDef Mympu,u8 dir)
{
float temp,x,y,z;
float res=0;
z = Mympu.Az/16384.0;
x = Mympu.Ax/16384.0;
y = Mympu.Ay/16384.0;
switch(dir)
{
case MPU6050_Z://与自然Z轴的角度
temp=sqrt((x*x+y*y))/z;
res=atan(temp);
break;
case MPU6050_X://与自然X轴的角度
temp=x/sqrt((y*y+z*z));
res=atan(temp);
break;
case MPU6050_Y://与自然Y轴的角度
temp=y/sqrt((x*x+z*z));
res=atan(temp);
break;
}
if (isnan(res)){
printf("Mympu.Ay %d\r\n",Mympu.Ay);
printf("Mympu.Ax %d\r\n",Mympu.Ax);
printf("Mympu.Az %d\r\n",Mympu.Az);
printf("res = %f\r\n",res);
while(1);
}
return res*180/3.14;//把弧度转换成角度
}
串口打印1:
-1 11
-1 10
-2 9
-1 8
Mympu.Ay 0
Mympu.Ax 0
Mympu.Az 0
res = nan
结果二:
4 -28
-5 -19
-12 -13
Mympu.Ay 0
Mympu.Ax 0
Mympu.Az 0
res = nan
结论就是。。因为这句话temp=sqrt((x*x+y*y))/z; |
|