Hello all,
This is my first post, and I am cynical university professor in engineering going through a mid life crisis. So, with that in mind if you read the following, do so with a bit of skepticism, and try not to hold my cynicism and bad attitude against me too much

.
I like the flavor and approach of this project. But, in my opinion you are wasting time considering all these different variants of optimal state estimation (EKF, UKF, square root implementations, etc.). Just do a good job on the straight forward EKF and get it working. Maybe you are falling into the same trap as my graduate students and I do sometimes, where we let the explosion of bad (and some good) info in research articles overwhelm our decisions. You must realize that the reward systems at universities and the review process for research papers promote the practice of making the benefits of their ideas sound better than they really are and to downplay the draw backs. Also, the good old solid technique used in industry for years is never as good as the new stuff. Have you ever read a paper that shows the new, hot topic is worse than the old idea, although we all know that is true in at least SOME cases?
For example, looking at the paper in post below, I see that the real improvement in the simulation results due to the UKF over the EKF (without the latency compensation) is in my opinion not worth the headache you’ll get from doing the UKF, at this stage of your development. Also, in the real flight data you can see that the results are really pretty much the same except when you have GPS outages, which you hopefully don’t have very often with your good GPS system.
Lewcifer, on 24 May 2010 - 06:13 PM, said:
Here's a good paper explaining why the Sigma-Point Kalman filter (aka unscented Kalman filter, central difference Kalman filter) is preferred over the EKF for fusing MEMS sensors...
Sigma-Point Kalman Filters for Integrated Navigation
Here's a PDF slide presentation (by a different research group) on the same subject. It specifically mentions UAV's, as well as the fact that the filter deals with lagged measurements (inherent to GPS - see
this thread) in an elegant manner.
I'm not sure how it performs when compared to the integration method discussed by Sebastian Madgwick (as referenced in an earlier post of mine). Come to think of it, I don't remember if the Madgwick method includes GPS fusion or if it remains a stand-alone system. I may be mixing apples and pears.
It seems you made the right choice a while ago (the EKF) but now are getting (at least in the forum) a little distracted. I teach an applied course on optimal estimation with a focus on navigation systems. My experience in simulation (where the truth is known) with the UKF and EKF with the same data is that sometimes one is better other times the other is better. On actual data from a UAV I find they give pretty much the same answers in as far as being able to tell which is right. I dunno maybe I just don’t have a good UKF implementation. The UKF is more computationally expensive, even though it is “derivative free.” Yes the "Uncented Transformation" usually captures the mean and other statistics more accurately, but I have never seen a proof that the mean, for example, is the most likely value for the true value in a general nonlinear case (not possible to prove) or specifically for any of the real navigation problems (unlikely to prove). Furthermore, in the EKF if you assume the noise covariance matrix for the measurements, R, is diagonal (i.e. uncorrelated noise) then you can implement the needed matrix inversion as a set of n scalar divisions, where n is the number of measurements. Uncorrelated noise is probably a pretty good model, and it is unlikely that you will get a good estimate of the cross correlation terms (off diagonal) anyway. The diagonal terms are pretty easy - take some steady data and find the variance of the measurements with everything running for a start. Breaking the calculation into n separate divisions also allows you to easily drop out and add back in available measurements or new types of sensors. From what I know, which is admittedly not that much, the EKF is still the method of choice by the real practitioners in the navigation industry. Just as PID is for single-input-single-output control systems if applied right, although it is tuff to find a paper that says fuzzy logic doesn’t work as well as PID. But you can find a lot of papers that say it does.
Okay, now we do have to realize that the EKF is very well matched to the GPS aided INS problem (GPS/INS), but not as well matched to the AHRS problem. The covariance matrices, Q and R, respectively for the disturbance noise and the measurement noise, can be used pretty well to model the real situation (this is still true for the UKF also by the way if you go that route). You have inertial measurements (accels and rate gyros). These are the "inputs" to the dynamic system model (actually kinematic model), and they have noise that is modeled in Q. The "measurements" for the model are GPS position and velocity, hopefully magnetometers for heading when hovering, and potentially other sensors, for which we can also model the noise, in R. Now, Kalman’s proof, which is really just a least squares solution at its heart, shows that the best estimate of the true state is his solution if you have a linear dynamic model and white, Gaussian noise. It is still the best linear solution to the problem even if the noise is not Gaussian (but white). The EKF is just a linearization of the nonlinear problem. It is just a good idea that works very well, especially for GPS/INS, not to take anything away from the early giants who came up with all this. Because the model for the GPS/INS system is purely a kinematic model (not involving the inertias, forces on the moving body, etc.), and the sensor noise is probably pretty much the same no matter what you put it on, you won’t have to change the tunable parameters (Q and R). It will perform better/worse on different systems, but it is still probably about as good as you are going to get for that platform.
Back to the AHRS – in some of the ARHS algorithms you treat the accelerations of the system due to motion as noise on the accelerometers’ measurement of the gravity vector. In this case the noise on the inputs (modeled in Q) is dependent how the system moves, which will be different for different systems. This means the solution might have to be tuned for different systems. ------ I ENCOURAGE YOU TO IMPLEMENT A TRUE GPS/INS ALGORITHM RATHER THAN AN ARHS ALGORITHM AS YOUR BASIC SOLUTION. ----- A descent implementation will be better than an ARHS if you have GPS. An ARHS algorithm might be needed to keep it flying when you don’t have GPS, although if it just a short loss the GPS/INS can be implemented to carry you through. You don’t even really need heading to keep it flying.
Now, how to implement? I suggest a straight forward implementation of the EKF without square root filtering (and the such) just so you can maintain it without scratching your head all the time. Use the sequential update (n sequential divisions) (described on pg. 151 of “Optimal State Estimation,” Dan Simon, Wiley, 2006, for example) to avoid the matrix inversion. BTW, the referenced book is a pretty good one for engineers, as apposed to mathematicians, but does not give the details you probably need for your specific implementation. It is actually pretty hard to find a good, to the point, description of the full model etc… although I think I have one for GPS/INS without mags if one of the main developers contacts me. Mags would be easy to add. I also could probably dig up an old, mostly clean, C implementation from a few years back, used in a crude autopilot I did (Currently, I just use the Cloud Cap solution in Piccolo for the Nav solution and modify the control code for low level control and guidance loops.) I could be wrong but I think your AHRS processor could do all this without too much problem (does it have access to the GPS?). You are looking at a “loosely coupled” solution I am pretty sure, where you use the GPS position and velocity solutions as measurements rather than the raw pseudo range measurements (that involves satellite ephemeras data also – would be pretty crazy and overkill).
Anyway I have said waaaaay too much and you probably won’t read it given my curmudgeon attitude

. I do welcome discussions with one of the main developers if you so desire.