DSPRelated.com
Forums

Kalman Filter for Electronic Compass and Gyro

Started by priya90 November 10, 2010
Hello,

I'm using an electronic compass and 3-axis gyro to estimate orientation for
my undergraduate project. The idea is that a user will hold and turn the
device, while walking, and I should estimate the true orientation of the
device at each step. 

I will be using a Kalman Filter to estimate the orientation, given the
noisy compass + gyro. I've gone through a lot of material, but I'm unclear
on how to proceed. This is how I see it (and I'm most probably wrong, so
please correct me):

My system :

Compass : LinearAccel + noise (Gaussian distribution?) 
Gyro: RotationalAccel + noise

So each time I get a set of readings from the compass n gyro, I have to
compute the variance with the mean and...?

I see there's a KFilter library for filtering in C++, and it takes in
inputs of the state vector, process noise, covariance matrix and initial
conditions. 

My initial conditions will be 0( I assume, for the electronic compass) and
the initial heading of the gyro. Process Noise, is that a Gaussian
distribution? How do I numerically compute it? And my state vector? Is it
simply the double integration of the Accelerations to give displacement?

I'm really confused, and I have no previous experience with Filters (save a
simple LPF in a purely analytical context (for circuits with capacitors,
inductors etc)

Please help me out! 

Thanks!


On 11/10/2010 06:50 AM, priya90 wrote:
> Hello, > > I'm using an electronic compass and 3-axis gyro to estimate orientation for > my undergraduate project. The idea is that a user will hold and turn the > device, while walking, and I should estimate the true orientation of the > device at each step. > > I will be using a Kalman Filter to estimate the orientation, given the > noisy compass + gyro. I've gone through a lot of material, but I'm unclear > on how to proceed. This is how I see it (and I'm most probably wrong, so > please correct me): > > My system : > > Compass : LinearAccel + noise (Gaussian distribution?) > Gyro: RotationalAccel + noise
How can you be measuring linear acceleration? What with? I think you need to think about what a gyro does, and what a compass does.
> So each time I get a set of readings from the compass n gyro, I have to > compute the variance with the mean and...?
Each time you get a set of readings you iterate the Kalman filter. You re-estimate your states, and you re-estimate the variance of the states.
> I see there's a KFilter library for filtering in C++, and it takes in > inputs of the state vector, process noise, covariance matrix and initial > conditions.
I wouldn't use it unless I already understood Kalman filtering. It's not something that you can blindly plug numbers into and get good results. Further, there are variations on the Kalman theme; if you assume your tool uses one of them and it uses another you'll be messed up and won't know why.
> My initial conditions will be 0( I assume, for the electronic compass) and > the initial heading of the gyro.
That's probably wise, except depending on how you represent your 3D angle you may run into problems with the gyro (you do realize you need the gyro angle in 3D, right?)
> Process Noise, is that a Gaussian distribution?
You'd certainly like it to be.
> How do I numerically compute it?
With difficulty. But you can make a guess, see how the filter works, then try again. Depending on what approximation you use for gyro angular update you'll have to play more or fewer games with process noise to keep the filter reasonably accurate.
> And my state vector? Is it > simply the double integration of the Accelerations to give displacement?
What accelerations? What displacement? I thought you had a gyro and a compass -- how do you get position out of that?
> I'm really confused, and I have no previous experience with Filters (save a > simple LPF in a purely analytical context (for circuits with capacitors, > inductors etc)
Then you'd best treat the Kalman filter as an interesting mathematical construct that happens to be called a filter -- anything you may know about more mundane filters won't really hold. Have you looked at the Wikipedia entry on Kalman filters? Do you have a good book on Kalman filters? I recommend Dan Simon's book: http://www.powells.com/partner/30696/biblio/9780471708582?p_isbn, but I'm sure there's others that are as good. Keep in mind that the basic idea behind a Kalman filter is that you have a simulation of the process with all the 'significant' inputs. If your simulation is perfect, there's no process noise, no input error and you start out at exactly the right initial value, then you'd never need to correct it. But your simulation isn't perfect, so you wrap that with a mechanism that compares your simulated outputs with the known measured output of the real system, and use the difference to correct your simulation. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html