Learning a Flight Dynamics Model

Introduction & Background

What is a flight dynamics model?

Flight dynamics is the science of air vehicle orientation and control in three dimensions. The three critical flight dynamics parameters are the angles of rotation in three dimensions about the vehicle’s center of gravity (cg), known as pitch, roll and yaw.

Wikipedia – obviously

A good model of an aircraft’s flight dynamics is useful for understanding how the aircraft will behave in all sorts of circumstances. Its useful for developing control algorithms to get the aircraft to do what you want. Critically, a flight dynamics model allows you to test your ideas without flying (or crashing) the actual airplane.

As far as I know, a flight dynamics model is typically built by passing a bunch of inputs to an existing flight dynamics model library, or from the ground up using theory and simulation results for a specific purpose. The problem with developing a flight dynamics model with theory or from “a bunch of inputs” is that flight dynamics are complex and depend on a huge number of factors. It is reasonable to assume that a “good” flight dynamics model derived from theory and simulation is a monumental effort in comparison to trying to learn flight dynamics from flight data (depending on the scale of the airplane).

Learn by Doing

This is a homebuilt (by yours truly) remote control airplane:

RC0 was lost in a tragic, beautiful crash

Learning to flying an RC plane is fun, but capturing flight data from a plane is better, which is where this device comes in:

The venerable Pixhawk1

The Pixhawk 1 is a flight-controller that is capable of running the Ardupilot Plane firmware. Ardupilot is a sophisticated open source firmware with auto-piloting capabilities. Ignoring a bunch of details – I installed it in the plane above like so:

The Rat’s Nest (not a bar & grill)

A wonderful capability of the pixhawk-ardupilot combination is logging attitude, heading and reference data. So now when I go fly the airplane, I can copy data files from the airplane, go through some cleaning and processing of the data shown in my repo here, and get synchronous time series data in a table.

A snippet of synchronous time series data

Each row in the table represents an instantaneous moment in time, and the columns represent the many characteristics of the state of the aircraft at that moment.

Do by Learning

I hypothesize that its possible to build a “good” flight dynamics model from flight data. So how do I know if a flight dynamics model is good? Ideally I compare it to an existing state of the art flight dynamics model for this particular airplane (which as far as I know doesn’t exist). So I’ll start by comparing it to a dummy model.

Dummy Model

The dummy model is a flight dynamics model (FDM) that predicts the next state of the aircraft will be the same as the current state. In other words, to predict what the airplane will be doing 200ms (1/5 of a second) from now, the dummy FDM predicts the airplane will be doing exactly what it is currently doing until it gets updated with new state information, then repeats the process.

I can quantify the error of the dummy FDM by comparing the actual dynamics of the aircraft at each time step in flight test data to the dummy model prediction. This will give me an aggregate measure of the difference between the predictions, and the actual dynamics over the course of a flight (or several flights) of test data.

A Learned Model

Recall that I have a table of recorded flight data from RC1 like this:

This is just a snippet, there are more measurements that are useful in determining the “state” of the aircraft, such as:

  • Airspeed (estimated by ardupilot, since I do not have an airspeed sensor installed)
  • Angle of attack (estimated)
  • GPS speed
  • Roll
  • Pitch
  • Slide slip angle
  • Angular Velocity X,Y,Z
  • Acceleration X,Y,Z
  • Climb Rate

Predictors of the next “state” of the aircraft include all of the current state features, control surface positions, and all variable derivatives. Ideally the model will take any relevant data leading up to the moment of prediction as input to make a good prediction about the next state of the aircraft.

How Does the Learned Model Work?

The learned model needs to predict everything about the state of the aircraft 200ms from now. The time step should depend on the dynamics of the system, the frequency at which you log data, and the speed at which your model can predict. I will test my hypothesis by building an artificial neural network using Keras. The model will take in the above list of parameters (and derivatives) and predict the values for the same list (excluding derivatives) 200ms in the future.

To train the model, I need to provide flight test data so that the model may learn about the relationships between the inputs and outputs. I currently have a small set of flight data (minutes not hours) to work with so I will use a portion from one flight to train the model, and then a separate portion from the same flight to test both the learned and dummy models.

You can see how the model is structured here.

Does It Work?

After training, we can see how the learned model and dummy model predictions compare against the true flight test data results. Lets look at some plots.

The above plot has true angle of attack measurements from the aircraft on the y axis. The predictions made by both the learned and dummy model are on the x axis. The learned model predictions are blue. The dummy model predictions are orange. The dashed line represents the best possible model where every prediction exactly matches the truth.

Notice that the dummy model is quite good at small angles of attack, when the airplane is likely to be maintaining its AOA, but anytime the AOA large (it is more likely to be changing quickly at higher magnitudes), it is less accurate. From the plot, it looks like the blue model is better, but does have bias at lower AOA. If measured by mean-squared-error, the learned model has about 4x less error. Lets look at plots of some more state variables:

Side Slip Angle
Y-axis (transverse/lateral) acceleration
Climb Rate (in meters per second)

In the aggregate (across all state variables), the learned model is 3.3x better at predicting the next state compared to the dummy model. In addition, there is no single state variable at which the dummy model is better than the learned model.

Continuing On

I am not satisfied knowing that a machine learned flight dynamics model is better than a dummy model, so it is worth building up a better flight dynamics model for comparison. It is my hope that with enough flight data, a state-of-the-art flight dynamics model can be learned, so that new ideas may be easily tested against a learned model instead of on the actual aircraft or software/hardware in the loop simulators.

Caveats to Learning from Data

There are some major limitations with learning a flight dynamics model solely from flight data. I will cover two that come to mind.

First – it is difficult to measure everything about the aircraft that influences its flight dynamics. For example, a center of gravity shift impacts flight dynamics. If it is not measured in the data, the model cannot learn about how center of gravity changes flight characteristics.

Second – You have to fly first. This is okay for relatively stable aircraft, skilled test pilots, and inexpensive flight hours, but does not work if a design cannot safely and economically get into the air to explore the flight envelope without already having a flight dynamics model. A chicken before the egg situation.

What Next?

My illustrious reader base will just have to wait and see when I will move the ball forward on this topic. I think some important things to do in no particular order are:

  • Visualize a learned model’s relationship between control inputs and state variables. For instance, does the model learn what we might expect about aileron inputs and roll?
  • Get some more test data at a wide variety of conditions (flying aerobatics, inverted, stalls, etc.)
  • Build a model that can run fast enough on hardware that can fit in the rats nest.

2 Replies to “Learning a Flight Dynamics Model”

Leave a Reply

Your email address will not be published. Required fields are marked *