I want to use the complementary filter to get the roll and pitch angles using an IMU sensor with an stm32l4+ microcontroller but get (nan(0x400000). I get some values at first then it shows nan. this How I implement it.
/* Read the Data of the accelerometre*/
accelerometer_reading(&MyAccel_DataDef,hspi3);
gyroscope_reading(&MyGyro_DataDef,hspi3);
/*Calculate roll (phi) and pitch (theta) angle using the Accelerometer */
phiHat_acc_rad = atanf(MyAccel_DataDef.y / MyAccel_DataDef.z);
thetaHat_acc_rad = asin(MyAccel_DataDef.x / GRAVITY);
/*Transform body rates to Euler rates*/
phiDot_rps = MyGyro_DataDef.x + tanf(thetaHat_rad) * ( sinf(phiHat_rad) * MyGyro_DataDef.y + cosf(phiHat_rad) * MyGyro_DataDef.z);
thetaDot_rps = cosf(phiHat_rad) * MyGyro_DataDef.y - sinf(phiHat_rad) * MyGyro_DataDef.z ;
/*Complementary filter*/
phiHat_rad = COMP_FILT_ALPHA * phiHat_acc_rad + ( 1.0f - COMP_FILT_ALPHA) * (phiHat_rad +(SAMPLE_TIME_MS_USB / 1000.0f) * phiDot_rps);
thetaHat_rad = COMP_FILT_ALPHA * thetaHat_acc_rad + ( 1.0f - COMP_FILT_ALPHA) * (thetaHat_rad +(SAMPLE_TIME_MS_USB / 1000.0f) * thetaDot_rps);
I test the accelerometer and the gyroscope and I get the roll and pitch angles with their problem but both i get this error.