[mw_shl_code=c,true]float yaw = 0;
void TIM2_IRQHandler(void)
{
uint8_t gyroAcc[14];
uint8_t mag[6];
if (TIM_GetITStatus(TIM2,TIM_IT_Update)!= RESET)
{
LED_Set(Bit_RESET);
MPU9250_ReadGyroAcc(gyroAcc);
temperature = (int16_t)(((uint16_t)gyroAcc[6]<<8) | gyroAcc[7]);
gyrox = (int16_t)(((uint16_t)gyroAcc[8]<<8) | gyroAcc[9]);
gyroy = (int16_t)(((uint16_t)gyroAcc[10]<<8) | gyroAcc[11]);
gyroz = (int16_t)(((uint16_t)gyroAcc[12]<<8) | gyroAcc[13]);
// gyroz -= 31;
LowPassFilter((float *)&gyrox,(float *)&gyroy,(float *)&gyroz);
updateFlag = 1;
yaw += gyroz*0.001/32.768f;
LED_Set(Bit_SET);
TIM_ClearITPendingBit(TIM2,TIM_IT_Update);
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
}
}
[/mw_shl_code]
这是在中断中积分计算陀螺仪的值
[mw_shl_code=c,true]extern float yaw;
int main()
{
uint8_t err;
float a;
SystemInit();
DelayInit();
TIM2_Configuration();
// CAN1_Configuration();
USART2_Init(57600);
LED_Configuration();
SPI2_Configuration();
DelayMs(50);
MPU9250_Init();
SPI2_ClockConfig();//?á???????±??
LowPassFilter_Init();
EKF_Init();
// DelayMs(500);
TIM2_Start();
while(1)
{
printf("%lf
",yaw);
DelayMs(10);
}
}[/mw_shl_code]
[mw_shl_code=c,true]在main函数中用串口打印陀螺仪的值[/mw_shl_code]
[mw_shl_code=c,true]但是读出陀螺仪的值偏差太大[/mw_shl_code]
[mw_shl_code=c,true]
[/mw_shl_code]
[mw_shl_code=c,true]这是开电后不动打开串口助手,然后旋转90度的情况[/mw_shl_code]
---------------------------
现在我还怀疑的一点就是我的板子是不是焊的有问题,因为9250芯片不怎么好焊
一周热门 更多>