Flight Simulation . Flat Earth Quaternion Formulation Summary
Transcript
INSTRUCTOR: We've now reached a good point to review and summarize the equations that we've developed for flight simulation. So this is the flat Earth quaternion formulation, and let's just walk through
a few of these equations. So these top six equations, these come from Newton's second law, F equals Ma. So we'll just write
that out here. Newton's second law. And the top three are for translational acceleration and these three here are for rotational acceleration.
OK. And so for example, the translational acceleration here uvw depends on the aerodynamic and the forces due to aerodynamics and thrust. So this is aero/thrust forces.
And then this next set is actually our gravity vector. Our gravity vector is a body force that depends on our orientation. And we've written
the orientation here in terms of the quaternion. So this is gravity. And then finally, we've got Coriolis forces here. OK.
I think I misspelled Coriolis, but you know what those are. OK. So that's our translational. And then we could
work through something similar for the rotational acceleration. So our changes in p, q and r, which are our rotation rates, depend on the inertia tensor of the aircraft in body fixed coordinates.
So that sub b is the inertia tensor in the body fixed coordinate system. And then we also have a gyroscopic tensor here if there's gyroscopic effects on board.
So like a rotating propeller or a jet engine, something like that creates gyroscopic effects. So let me just label these. So this is the inertia tensor.
These are gyroscopic. And then right here, we've got the aerodynamic and thrust moments. OK. So mx, my, mz these
are moments that are due to the aerodynamics and the thrust combined. And then we've got a bunch more terms in here that fall out of this equation from this rotational version of Newton's second law, very
similar to these Coriolis type effects. But it depends on your inertia or differences in inertia and your rotation rates. So that's what the
rest of this here is. OK, then these bottom six equations are what we call the kinematic transformation equations. And basically those depend-- here we're using the
quaternion formulation and previously we've seen this in terms of the Euler angle formulation. But for example, we have uvw this is our velocity vector in body fixed coordinates and we need to know the change in our
location on Earth due to that. Well, that depends on our orientation. And so this is the quickest way to do the math with the orientation
using the quaternion formulation. So it's these two multiplications. So we do this inner multiplication first, and then we do this
outer multiplication, and then we can add a wind vector here. And this is really only good for the case of constant wind. So this simulation
is assuming that wind is constant and not changing. And this is in Earth fixed coordinates. So basically our orientation or excuse me, our location are
changing in x, y and z location we just add on the velocity of the wind because it's moving the aircraft along with the wind, because uv and w is our velocity relative to the local air. Anyways, so that's this
top set of equations here. And then finally, we need to know our change in our quaternion as a function of time. And so that depends on
our current quaternion and the rotation rates onboard the aircraft, pq and r, that's our rotation rates in body fixed coordinates. So these are actually 13 equations that-- and actually we have
one extra equation here in the Euler angle formulation. We had 12 equations and here we have 13 simply because we've got a quaternion representing our orientation instead of Euler angles.
And remember, we have one extra degree of freedom in these. And so we've assigned-- we've said that our extra equation here is that E0 squared plus ex squared plus ey squared plus ez squared equals 1.
So we're going to use a unit quaternion and we'll talk about how we renormalize that at each or every few time steps in order to keep that true throughout this simulation. OK.
So this is an overview of the equations and just a couple of comments maybe to be made about these is that, in the literature or I guess just in general, people have had a difficult time with quaternions in the past.
Sometimes they have the reputation of being difficult to understand and that probably has more to do with the scattered nature of the literature on quaternions than it does about the actual complexity
of using a quaternion. So hopefully, the way that we've walked through quaternion it makes a lot of sense. Hopefully very straightforward. I don't think there's anything
challenging to understand here. But some people have chosen to use Euler angle formulations for some simulations or direction cosine formulations because they are somewhat easier or more intuitive to understand what those direction
cosines are or what the Euler angles actually mean. Because obviously we can't look at some values for this quaternion and picture in our mind how this aircraft is oriented. We'd need to change this
back to Euler angles in order to be able to have some intuition into the orientation of that aircraft. So anyway, but I don't think that quaternions are really that much more difficult than the Euler angle formulation.
And in fact, by using those other formulations, you pay a penalty. So for example, the direction cosine formulation requires about 2 times, if not more computation then the Euler, error excuse me,
then the quaternion formulation. And because you're integrating, remember you have nine components of this direction cosine matrix that you're integrating forward in time instead of the four components of the quaternion.
And then if you use an Euler angle formulation that actually requires somewhere around 11 times more computation. And that's because the terms inside in these rotation matrices here, what's
happening inside of here, in the Euler angle formulation, we had a whole bunch of sines and cosines that have to be evaluated inside of those rotation matrices. And so sines and
cosines actually take quite a while for a computer to compute compared to straight up multiplication, which is what the Euler angles are here just direct multiplication. Anyway, that's why it can
take 11 times or more, depending on how you code that up. It can even take more than 11 times the computational effort for the Euler angle formulation. So there's a significant
computational savings that you get by using quaternions if you've coded it up correctly. And then I just want to review some comments that we've made about orthogonality error. So orthogonality error is
basically this equation right here. How close is the length of that quaternion equal to 1? How close to 1 are we? And in the early days when computers were new, they were analog computers or they were using first order integration methods.
And so they developed this thing called the Corbett wright, Corbett wright method for reducing orthogonality error and actually works fairly well. It is sensitive to the gains that you choose for it.
But you can be smart about that and it turns out working out pretty well. The thing is, it's really not necessary for fourth order integration which is what we use today on digital computers.
So I'm just going to make a note here. Not necessary for fourth order integration. And so the methods that
we usually use today, there's two common ones the RK4 Runge-Kutta four method or the Adams Bashforth Moulton method, which we've called the ABM method. Those are both fourth order integration methods.
And so you can use periodic renormalization. Let's see. Re-normalization. You can apply that periodically.
In my simulations, I usually apply it after every full time step. So within RK4 we're going to take one time step. And at the end of that time step
I renormalize the quaternion. So anyway, you can apply that every time step or just periodically, every few time steps. And it's much less
computationally expensive than the Corbett wright method and is just as effective at taking care of this orthogonality error. Well, I guess just then to finalize the thought here on RK4 and ABM, these provide
the fastest simulations for the amount of error. So we discussed that earlier, but these are the fastest simulations per error basically. So we looked at
the amount of error that these different methods accumulate, specifically orthogonality error. And there is another kind of error, the drift error, which all of these methods are going to suffer from to some extent.
And of course, you can always reduce the error by taking a smaller time step. So we looked at that what's the effect of taking a smaller time step using a higher order method or a lower order method.
And anyway, after you look at all these trade offs, the RK4 and the ABM method tend to give the fastest simulations for the amount of error that gets accumulated. Now, the drift there really
isn't much of an issue because it's similar to having your aerodynamic model off by a little bit, which is pretty normal. I mean, the aerodynamic model that you're using for these simulations
isn't going to be exact. And so a little bit of drift error basically will feel like a little bit of error in that model. And so that will be
simply corrected out by the pilot or the autopilot or whatever. So anyway, so let's just comment really quickly on this periodic renormalization.
So we've talked about two different ways to do it. This is the exact solution for renormalizing the quaternion. This is the exact solution.
And then we also looked at using a Taylor series expansion of this and including only the first two terms. And so this is an approximate solution.
So this is the approximate solution. And actually, if your errors is small, then this approximate solution is plenty sufficient.
So if you're applying this every single time step, you can use this approximate solution which is quite a bit faster actually to compute than the exact solution because in the exact solution you have a square root and a
division that has to happen and this can all happen with direct multiplication. So this approximate method, if you're renormalizing the quaternion after every full time step, you can use the
approximate method. And it's plenty accurate. OK. Because your error is still small.
And by the way, in the previous video when I developed this, I wrote this in terms of the error, what we defined as errors. So epsilon equals 1 minus and then it was E0 squared plus ex
squared plus ey squared plus ez squared. And anyway, so we came up with an equation in terms of epsilon. But if you just plug-in this definition for epsilon, then you come up with
this equation here. So that's where that comes from. So hopefully, this has given you a good overview of the quaternion formulation. And I hope that it doesn't
sound too daunting. These equations, I think are pretty straightforward and it should be something that you can implement due to our discussion here. Hopefully, it's not too
challenging to implement. And so next, we'll be talking about the actual aerodynamic forces and moments. How do we compute those on an aircraft and how do we develop an
aerodynamic model or a thrust model for a particular aircraft. And one last thing I should mention before we move on is that this is specifically the flat Earth quaternion formulation. And so this is x.y.
and z. This is assuming that this aircraft is flying on a perfectly flat Earth, which is not a bad approximation for short flights.
Anyway, so it turns out this is what we're going to start, but eventually we're going to then map our coordinates to a geographic coordinates. And so that will be the final state of our simulator.
We'll be able to tell us where on the Earth we are. But the physics here, what's presented here is just in flat Earth coordinates.