Go Down

### Topic: IMU Filtering (Read 4370 times)previous topic - next topic

#### johnmchilton

##### Jun 23, 2011, 05:20 am
Hi all,

I'm building a balancing robot. I have an inertial measurement unit that I've successfully filtered with a complementary filter. It combines a high-pass filter on the gyro input with a low-pass filter on the accelerometer input.

The filter looks like this:
Code: [Select]
`angle = a*(angle + gyro_input * dt) + (1 - a)*(accelerometer_input)`

where a is determined by the equation:
Code: [Select]
`(a*dt) / (1-a) = T`

where T is the time cutoff under which you want to trust the gyro and above which you want to trust the accelerometer.

The good news is that this filter successfully eliminates gyroscopic drift and provides a reliable angle, even when the accelerometer is inside an accelerating reference frame vis a vis the earth.

The bad news is that (I wrote a visualization program that looks like a speedometer) the measured angle takes a loooong time to catch up to the actual angle. :~

The even worse news is that I'm considering switching to a Kalman filter despite not knowing how it works, which I feel ethically opposed to.

Does anybody have success stories to share about using the Kalman filter? Can anybody provide a working implementation of one that I don't have to rip out of somebody's program? Can anybody talk about how to find the constants used in the algorithm? Do I really have to measure the physical system and determine my covariance matrix based on the characteristics of my vehicle?

#### Eugene

#1
##### Jul 18, 2011, 12:12 am
First part - http://arduino.cc/forum/index.php/topic,8871.0.html
Next part - http://arduino.cc/forum/index.php/topic,60170.0.html

#### johnmchilton

#2
##### Jul 27, 2011, 06:37 am
Thanks... but I've already read all of both of those. What I was really looking for was:

Can anybody talk about how to find the constants used in the algorithm? Do I really have to measure the physical system and determine my covariance matrix based on the characteristics of my vehicle?

Or can somebody talk about how to algorithm works in the first place, assuming a working knowledge of calculus and linear algebra?

#### massit78

#3
##### Jul 27, 2011, 08:39 am
a quick guide about gyro and accelerometer with Arduino including Kalman filtering:

http://arduino.cc/forum/index.php/topic,58048.msg417140.html#msg417140

#### johnmchilton

#4
##### Jul 28, 2011, 03:14 am
Did you even read the article?

Quote
I did not make my own Kalman filter, so I can not tell exactly how it works, instead I used the Kalman filter from this project

#5
be costructive

#### johnmchilton

#6
##### Jul 29, 2011, 06:26 am
Well come on, everybody knows how to use a search engine.

#### danielaaro

#7
##### Aug 07, 2011, 12:06 pm
I actually made a similar function when I first started working on this. It hade accelerometers and gyro, and i trusted the gyro reading at all times. When the accelerometers had a steady reading I used that to correct the gyro angle. That works great actually, but since I was going to use it for a quadcopter, the dynamic acceleration(not vibration noise but the vessel accelerating) caused this filter to be useless. for a balancing robot on the other hand, it would be great.

I posted a thread on this on the old forum.

Here is a RTR kalman filter(its simple, but it works great and has a great response time). http://arduino.cc/forum/index.php/topic,52717.0.html

The kalman filter actually solves your problem, determining the averaging factor for you. The good thing about this is that it recalculates them continously. A weighted average with fixed weights would never be as good as a adaptive one, so why struggle.

Go Up