This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

There is a problem applying the 'complementary filter' to the value of mpu6050

Hello

I use mpu6050 and I want to use a 'Complementary Filter' to get the angle of the X, Y, and Z axes.

Applying this filter to the value of mpu6050 seems to reduce noise at first and produce good results. However, after some time, the value of the Z-axis continues to grow.

It keeps getting bigger and bigger, and after a while, the value is printed out too strangely.

This is the output when the sensor is placed on the floor.  The X and Y axes seem to come out normally, but the Z axis has a strange value.

This is the code I wrote about filtering. I wrote it while referring to the example of Arduino, is there anything strange?
Or is it possible that this is a sensor problem?

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//mpu6050
void mpu_init(void)
{
ret_code_t ret_code;
// Initiate MPU driver
ret_code = app_mpu_init();
APP_ERROR_CHECK(ret_code); // Check for errors in return value
// Setup and configure the MPU with intial values
app_mpu_config_t p_mpu_config = MPU_DEFAULT_CONFIG(); // Load default values
p_mpu_config.smplrt_div = 19; // Change sampelrate. Sample Rate = Gyroscope Output Rate / (1 + SMPLRT_DIV). 19 gives a sample rate of 50Hz
p_mpu_config.accel_config.afs_sel = AFS_2G; // Set accelerometer full scale range to 2G
p_mpu_config.gyro_config.fs_sel = AFS_2G; // Set gyro full scale range to 2G
ret_code = app_mpu_config(&p_mpu_config); // Configure the MPU with above values
APP_ERROR_CHECK(ret_code); // Check for errors in return value
}
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
double mpu_accel_x, mpu_accel_y, mpu_accel_z;
double mpu_gyro_x, mpu_gyro_y, mpu_gyro_z;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Thank you.

//==================================================

I think I found a problem.
The value of dt in void calcDT() comes out as a fixed value as shown below, and suddenly becomes very large.

Can you tell me the cause of this problem??

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
dt : 0.153000
Gyro_xyz : 0.0, 0.0, 0.0
Filter : -0.3, 0.1, -8.5
dt : 0.152000
Gyro_xyz : 0.1, 0.0, -0.0
Filter : -0.3, 0.1, -8.5
dt : 4294836.500000
Gyro_xyz : 0.0, -0.0, 0.0
Filter : 195136.5, -31473.5, 19662.5
dt : 0.153000
Gyro_xyz : -0.0, -0.0, 0.0
Filter : 187331.0, -30214.6, 19662.5
dt : 0.153000
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX