how to smooth MPU6050 gyro reading with kalman.h?

Hi again.

I have just followed a tutorial online creating an "arduino gyro game". I won't be using the game but i will use the module to show me how level my van is parked.

After some googling around and some trial and error i found out that i need to put 3 more files in my sketch folder to get this thing to work.

Kalman.h
Kalman.cpp
I2C.ino

These are to be found in the kalman libraries after that was installed. Not sure if this all had to do with the issue but better save than sorry, so as much info given as possible.

So i got this thing running and it works "fine" but i would like to have some more elegant readings. Some sort of averaging. At this point when the MPU6050 lays still the angle output will vary a out 0.5 degrees jumping up and down. Screenshot added to show what i mean.

Now i found something about changing the Q_bias in the Kalman.h file but this won't do anything for me.

I changed this bit from the kalman.h

private:
    /* Kalman filter variables */
    float Q_angle; // Process noise variance for the accelerometer
    float Q_bias; // Process noise variance for the gyro bias
    float R_measure; // Measurement noise variance - this is actually the variance of the measurement noise

Into

private:
    /* Kalman filter variables */
    float Q_angle = 0.1; // Process noise variance for the accelerometer
    float Q_bias = 0.1; // Process noise variance for the gyro bias
    float R_measure = 0.1; // Measurement noise variance - this is actually the variance of the measurement noise

I know that q_bias is a bit extreme there but i tried various values between 0.1 and 0.003

The output is still jittery. Anybody knows where i need to change what to get some smoother output on my screen?

Actual sketch as attachment since it is over 9k caracters

arduino_gyro_game3.ino (13.4 KB)

That code isn't a Kalman filter and doesn't work well. Don't waste your time with it, unless you want to learn why it doesn't work, as discussed in this post.

There are much better IMUs than the MPU-6050, and good filter code to go with them, including Kalman filters. Here is one example and here are a couple of others.

I have this MPU6050 laying around here so i will use that since this is a fun weekend project nothing very accurate needed.

Was just wondering if the yitters could be filtered out somewhat and apparently it can be done, only i am not able to figure that out yet.

A moving average or digital low pass filter can be implemented in just a few lines of code. One filter for each variable of interest.

i will use the gyro to show me how level my van is parked

The gyro is of no use for that application, but the accelerometer will report tilt and roll quite accurately, with sufficient averaging.

https://www.dfrobot.com/wiki/index.php/How_to_Use_a_Three-Axis_Accelerometer_for_Tilt_Sensing

Edited the first post so it says i want to use the module instead of the gyro.

I have already something showing me roll and pitch. And if works quite ok. The only party is the filtering and i know it is adjustable in this "Kalman"code.

I have terrible finding out where and was hoping somebody can point me out where to find it exactly.

where to find it exactly

Find what?

jremington:
Find what?

Where to change the bias to get "smoother" results.

See the first sentence in reply #1.

Good luck with your project.