Pages: [1]   Go Down
 Author Topic: Using MPU6050 with kalman filter  (Read 2007 times) 0 Members and 1 Guest are viewing this topic.
Offline
Newbie
Karma: 0
Posts: 7
 « on: January 30, 2013, 09:55:18 pm » Bigger Smaller Reset

Since I am the first time to use the MPU6050, I have some question about that.

How to link the kalman filter program with the MPU6050 program? I was found the MPU6050 program in arduino playground. Also, I found the kalman filter program in the internet.

Thanks for help.

 Logged

Offline
Newbie
Karma: 0
Posts: 7
 « Reply #1 on: January 30, 2013, 10:02:01 pm » Bigger Smaller Reset

The code of the Kalman filter is shown below:
Code:
// KasBot V1  -  Kalman filter module

float Q_angle  =  0.01; //0.001    //0.005
float Q_gyro   =  0.0003;  //0.003  //0.0003
float R_angle  =  0.01;  //0.03     //0.008

float x_bias = 0;
float P_00 = 0, P_01 = 0, P_10 = 0, P_11 = 0;
float  y, S;
float K_0, K_1;

float kalmanCalculate(float newAngle, float newRate,int looptime)
{
float dt = float(looptime)/1000;                                    // XXXXXXX arevoir
x_angle += dt * (newRate - x_bias);
P_00 +=  - dt * (P_10 + P_01) + Q_angle * dt;
P_01 +=  - dt * P_11;
P_10 +=  - dt * P_11;
P_11 +=  + Q_gyro * dt;

y = newAngle - x_angle;
S = P_00 + R_angle;
K_0 = P_00 / S;
K_1 = P_10 / S;

x_angle +=  K_0 * y;
x_bias  +=  K_1 * y;
P_00 -= K_0 * P_00;
P_01 -= K_0 * P_01;
P_10 -= K_1 * P_00;
P_11 -= K_1 * P_01;

return x_angle;
}
 Logged

Offline
Edison Member
Karma: 27
Posts: 2033
 « Reply #2 on: January 31, 2013, 02:19:27 am » Bigger Smaller Reset

It depends what you are trying to filter,  and if you are trying to filter a single variable or
some kind of fusion of several variables,  which may or may not have some physical model
interconnecting them.

 Logged

Offline
Newbie
Karma: 0
Posts: 7
 « Reply #3 on: January 31, 2013, 10:23:49 pm » Bigger Smaller Reset

How can I get the raw data from MPU6050??

As I saw that the register map mention the 1A, 1B and 1C address is used for config. Also, the 0D, 0E and 0F is used for read data from X, Y and Z.
Should I use those address to get some raw data??
 Logged

Offline
Edison Member
Karma: 27
Posts: 2033
 « Reply #4 on: January 31, 2013, 10:29:52 pm » Bigger Smaller Reset

You need to get the datasheet for the device and read it carefull.  The 6050 can be used in quite
a number of ways  and it has a lot of registers to put data in and out of.
 Logged

Offline
Edison Member
Karma: 27
Posts: 2033
 « Reply #5 on: January 31, 2013, 10:51:52 pm » Bigger Smaller Reset

Quote
The code of the Kalman filter is shown below:

This code is specifically for a segway-type device in one dimension  and probably won't do you much
good for anything else.
 Logged

Offline
Edison Member
Karma: 27
Posts: 2033
 « Reply #6 on: January 31, 2013, 11:03:02 pm » Bigger Smaller Reset

You need a bunch of documents for this device.   The one describing the register set is called RM-MPU-6000A.pdf

This device has a lot of registers that you can read or write to, through I2C,  the register numbers go up to 117 decimal.

The accelerometer measurement is in 6 registers  3B to 40 hex  and the gyro measurement in 43 to 48 hex.

You need to configure the device,  and then get the data from the device,   and then you can do any calculations
you like ( including Kalman filter, if you want to ) after you get the data.

The device has the really nifty feature that it can be programmed to calculate the orientation of the device
itself, which means the arduino doesn't have to do it.

For configuring and accessing the data from the device, I recommend the library developed by Jeff Rowberg
which is apparently called MPU6050

 Logged

Offline
Newbie
Karma: 0
Posts: 6
 « Reply #7 on: February 18, 2013, 12:57:36 pm » Bigger Smaller Reset

i want to use this MPU-6050 for balancing bot using kalman filter can it be done??

thanq
 Logged

 Pages: [1]   Go Up
Jump to: