Visualization of MATRIXx™ Simulation Results Using the FlightGear Flight Simulator

Publish Date: Jul 01, 2008 | 6 Ratings | 3.50 out of 5 | Print

Table of Contents

  1. Overview
  2. Running FlightGear With SystemBuild™
  3. Installing the FlightGear User Code Block
  4. Adding and Connecting Interface Block
  5. Creating a FlightGear Run Script
  6. Running FlightGear with SystemBuild

1. Overview

Simulation is used by engineers as a cost effective method for reducing time to market while producing ever more reliable products. Since a simulation is in effect a numerical experiment it allows us to attempt a variety of scenarios. The benefits of simulation can be further extended through the use of visualization software. Areas that can benefit directly from the use of visualization aids are simulation verification and validation, understanding a systems physics and use in training.

The FlightGear Flight Simulator is an open source flight simulator software package (currently through Gnu General Public License) that when utilized in conjunction with National Instruments MATRIXx™ SystemBuild™ allows for direct visual feedback of aircraft flight dynamic model simulation results in real-time. This connectivity is provided via a user code block (UCB) in MATRIXx™ SystemBuild™.

This FlightGear user code block (UCB) supports an interface via a unidirectional transmission from MATRIXx™ SystemBuild™ to FlightGear using FlightGear's published net_fdm binary data exchange specification. Data is transmitted via UDP to a running instance of FlightGear.

Figure 1 Sample FlightGear Visualization

You can obtain the FlightGear Flight Simulator from or by ordering CDs from FlightGear. The download area contains extensive documentation on installing and configuring FlightGear. Binaries are available for installation and since it is an open source project, source downloads are also available for customization and porting to custom environments.

The FlightGear UCB currently supports the standard binary distributions of FlightGear version 0.9.8a. If you have other versions of FlightGear you wish to interface with, the source code for the UCB is provided for modification.

Note: The FlightGear environment appears to be sensitive to other computer interactions during its startup phase. It is best to not move, resize, mouse over, overlap, or cover up the FlightGear window until the initial simulation scene appears after the splash screen fades out.

You must have a high performance graphics card to make the best use of FlightGear. Performance is highly dependent on graphics capability and CPU loading. For these reasons it may be necessary that you run your simulation on one computer while running FlightGear for visualization on a separate system. For additional information, see the Hardware Requirements and Documentation areas of the FlightGear Web site.

Back to Top

2. Running FlightGear With SystemBuild™

There are four main steps to connecting SystemBuild™ to FlightGear for visualization:

· Installing the FlightGear User Code Block – Installing the UCB code for use
in your SystemBuild™ model
· Adding and Connecting Interface Block - Add and connect the interface UCB
to your SystemBuild™ model
· Creating a FlightGear Run Script - Create a FlightGear run script compatible
with your SystemBuild™ model
· Running FlightGear with SystemBuild - Start FlightGear first, then run your
SystemBuild™ model

Back to Top

3. Installing the FlightGear User Code Block

Installing the FlightGear User Code Block follows the general procedure found in the
Building, Linking, and Debugging UCBs section of the MATRIXx™ SystemBuild™
User Guide.

Note: The links to download the necessary files are found at the end of this
document. The CVI Runtime engine will also need to be downloaded and installed on
machine running MATRIXx.

The following files should be placed in the directory of the model you want to connect
to FlightGear. They are makeucb.bat,, usrFlightGear.c and The other files that are downloaded are the libraries and header
files necessary to build the UCB into the simulation. These libraries and header files
can be placed in a separate folder, but the file must be updated with the
correct path information to these files. The usrFlightGear.c file can also be placed
where the libraries and header files are, but you will need to update the path in the
UCB filename. It is currently set to look in its local directory.

The file initially lists the paths to necessary header and library files as

USRINCS = /Iudp.h\
/I"C:\Program Files\Microsoft Visual Studio\VC98\Include\WINSOCK2.H"\
/I"C:\Program Files\National Instruments\CVI70\include"\
/I"C:\Program Files\National Instruments\CVI70\include\ansi"\
/I"C:\Program Files\National Instruments\CVI70\include\utility.h"\
/I"C:\Program Files\National Instruments\CVI70\include\ansi_c.h"
USRLIBS = udp.lib "C:\Program Files\National Instruments\CVI70\extlib\cvirt.lib"\
"C:\Program Files\Microsoft Visual Studio\VC98\Lib\ws2_32.lib"

These paths should be updated to point to the correct locations of the header and
library files from the zip. A suggestion would be to place all .lib and .h files into a
C:\MATRIXxToFlightGear directory and then update the makeucb file as follows:

USRINCS = /I"C:\MATRIXxToFlightGear"\
/I"C:\Program Files\Microsoft Visual Studio\VC98\Include\WINSOCK2.H"\
USRLIBS = "C:\MATRIXxToFlightGear\udp.lib" "C:\MATRIXxToFlightGear\cvirt.lib"\
"C:\Program Files\Microsoft Visual Studio\VC98\Lib\ws2_32.lib"

With the files placed in the correct directories and the file updated with
this information the next step is to add the UCB to your model.

Back to Top

4. Adding and Connecting Interface Block

Connecting the UCB to your model requires providing the data required by FlightGear
to perform the visualization. The full FlightGear net_fdm structure for
communicating with FlightGear contains the following elements.

typedef struct {
int version;
int pad;
double longitude; // geodetic (radians)
double latitude; // geodetic (radians)
double altitude; // above sea level (meters)
float agl; // above ground level (meters)
float phi; // roll (radians)
float theta; // pitch (radians)
float psi; // yaw or true heading (radians)
float alpha; // angle of attack (radians)
float beta; // side slip angle (radians)
float phidot; // roll rate (radians/sec)
float thetadot; // pitch rate (radians/sec)
float psidot; // yaw rate (radians/sec)
float vcas; // calibrated airspeed
float climb_rate; // feet per second
float v_north; // north velocity in local/body frame, fps
float v_east; // east velocity in local/body frame, fps
float v_down; // down/vertical velocity in local/body frame, fps
float v_wind_body_north; // north velocity in local/body frame
// relative to local airmass, fps
float v_wind_body_east; // east velocity in local/body frame
// relative to local airmass, fps
float v_wind_body_down; // down/vertical velocity in local/body
// frame relative to local airmass, fps
float A_X_pilot; // X accel in body frame ft/sec^2
float A_Y_pilot; // Y accel in body frame ft/sec^2
float A_Z_pilot; // Z accel in body frame ft/sec^2
float stall_warning; // 0.0 - 1.0 indicating the amount of stall
float slip_deg; // slip ball deflection
int num_engines; // Number of valid engines
int eng_state[FG_MAX_ENGINES]; // Engine state (off, cranking, running)
float rpm[FG_MAX_ENGINES]; // Engine RPM rev/min
float fuel_flow[FG_MAX_ENGINES]; // Fuel flow gallons/hr
float egt[FG_MAX_ENGINES]; // Exhaust gas temp deg F
float cht[FG_MAX_ENGINES]; // Cylinder head temp deg F
float mp_osi[FG_MAX_ENGINES]; // Manifold pressure
float tit[FG_MAX_ENGINES]; // Turbine Inlet Temperature
float oil_temp[FG_MAX_ENGINES]; // Oil temp deg F
float oil_px[FG_MAX_ENGINES]; // Oil pressure psi
int num_tanks; // Max number of fuel tanks
float fuel_quantity[FG_MAX_TANKS];
int num_wheels;
char wow[FG_MAX_WHEELS];
float gear_pos[FG_MAX_WHEELS];
float gear_steer[FG_MAX_WHEELS];
float gear_compression[FG_MAX_WHEELS];
time_t cur_time;
long int warp; // offset in seconds to Unix time
float visibility; // visibility in meters (for env. effects)
float elevator;
float elevator_trim_tab;
float left_flap;
float right_flap;
float left_aileron;
float right_aileron;
float rudder;
float nose_wheel;
float speedbrake;
float spoilers;

The FlightGear UCB uses a subset of these as inputs to FlightGear, but is easily
modified if additional inputs are desired. The following are the currently available
signals. The first six are necessary to model the vehicles 6 degrees-of-freedom.

1. Latitude (degrees)
2. Longitude (degrees)
3. Altitude (degrees)
4. phi (degrees)
5. theta (degrees)
6. psi (degrees)
7. VCAS (calibrated airspeed) (not necessary, but will display on cockpit instruments)
8. climb rate (ft/sec) (same as VCAS)
9. Elevator Angle (All control surface values are normalized from (-1..0..1))
10. left_flap
11. right_flap
12. left_aileron
13. right_aileron
14. rudder

The UCB takes the inputs and packs them into the net_fdm structure. This structure
is written using UDP packets to a running session of FlightGear. It is set to broadcast
over port 5502 to the local machine at One method to increase system
performance is to run the SystemBuild™ model on one computer and FlightGear on
another. This can be accomplished by modifying the IPaddress and WritePort
variables in the usrFlightGear.c file to the desired machine IP address and port where
the running FlightGear session will occur.

If your SystemBuild™ model is complex and is still unable to run at the rate needed
for the visualization, you may need to use SystemBuild™ HyperBuild to speed the
execution of your model.

Back to Top

5. Creating a FlightGear Run Script

In order to start FlightGear with the desired initial conditions (location, date, time,
weather, operating modes), it is best to create a run script. You can do this by using
the GUI provided with FlightGear.

If you make separate run scripts for each model you intend to interface to FlightGear
and they are in separate directories, run the appropriate script just prior to
simulating your SystemBuild™ model.

Using the GUI provided with FlightGear. The FlightGear launcher GUI (part of
FlightGear) lets you build up simple and advanced options into a visible run
command that may be used to create a batch file for launching FlightGear from a
command line. This process is outlined further in the FlightGear Flight Simulator-
Installation and Getting Started documentation.

The setup for FlightGear to receive external flight information is a matter of changing
some internal options. The following figures show the settings necessary to enable
the communication. Using the Advanced options you set the flight model to external

and set the Input/Output socket to UDP and a desired port number for the communication as shown below.

The command line options for the GUI setting are also shown by the wizard as seen
below. These options can be used in conjunction with the runfgfs batch file to
implement a command line launch mechanism.

Back to Top

6. Running FlightGear with SystemBuild

The easiest way to start FlightGear is too launch it from the Windows
Start>>Programs menu. FlightGear also supports the command line option alluded
to previously that may be launched from a command shell or using the Xmath mathscript
oscmdcommand. The process is further outlined in the FlightGear Flight Simulator-
Installation and Getting Started documentation.

Once you have performed all the setup steps, follow this sequence to both start
FlightGear and run your model:

1. Load your model. A demonstration model is provided in the
catalog file. This model can be used to exercise altitude, pitch, roll, yaw and
rudder to demonstrate that the communication is working as expected.
2. Run your FlightGear script or launch FlightGear manually.
3. When FlightGear starts, it will display the initial view and at the initial
coordinates specified in the run script or based on your use of the GUI. If you
are running SystemBuild™ and FlightGear from different computers, arrange
to see the two displays at the same time.
4. Now begin the simulation and view the animation in FlightGear.

Note: With the FlightGear window in focus, the V key can be used to alternate
between the different aircraft views. Available views are cockpit, helicopter, chase,
and tower views.
Related Links:
LabWindows/CVI Run-time Engine Version 7.1 for Windows 2000/NT/XP

Back to Top

Bookmark & Share


Rate this document

Answered Your Question?
Yes No