Working with the Flight Simulator Interface

Introduction

Use this section to learn how to use the FlightGear flight simulator and the Aerospace Blockset software to visualize your Simulink aircraft models. If you have not yet installed FlightGear, see Introducing the Flight Simulator Interface first.

Simulink Driven HL-20 Model in a Landing Flare at KSFC

About Aircraft Geometry Models

Before you can visualize your aircraft's dynamics, you need to create or obtain an aircraft model file compatible with FlightGear. This section explains how to do this.

Aircraft Geometry Editors and Formats

You have a competitive choice of over twelve 3-D geometry file formats supported by FlightGear.

Currently, the most popular 3-D geometry file format is the AC3D format, which has the suffix *.ac. AC3D is a low-cost geometry editor available from www.ac3d.org. Another popular 3-D editor for aircraft models is Flight Sim Design Studio, distributed by Abacus Publications at www.abacuspub.com.

Aircraft Model Structure and Requirements

Aircraft models are contained in the FlightGearRoot/data/Aircraft/ directory and subdirectories. A complete aircraft model must contain a directory linked through the required aircraft master file named model-set.xml.

All other model elements are optional. This is a partial list of the optional elements you can put in an aircraft data directory:

Model behavior reverts to defaults when these elements are not used. For example,

Models can contain some, all, or even none of the above elements. If you always run FlightGear from the cockpit view, the aircraft geometry is often secondary to the instrument geometries.

A how-to document for including optional elements is included in the FlightGear documentation at:

http://www.flightgear.org/Docs/fgfs-model-howto.html 

Required Flight Dynamics Model Specification

The flight dynamics model (FDM) specification is a required element for an aircraft model. To set the Simulink software as the source of the flight dynamics model data stream for a given geometry model, you put this line in data/Aircraft/model/model-set.xml:

<flight-model>network</flight-model>

Obtaining and Modifying Existing Aircraft Models

You can quickly build models from scratch by referencing instruments, sounds, and other optional elements from existing FlightGear models. Such models provide examples of geometry, dynamics, instruments, views, and sounds. It is simple to copy an aircraft directory to a new name, rename the model-set.xml file, modify it for network flight dynamics, and then run FlightGear with the –aircraft flag set to the name in model-set.xml.

Many existing 3-D aircraft geometry models are available for use with FlightGear. Visit the download area of www.flightgear.org to see some of the aircraft models available. Additional models can be obtained via Web search. Search key words such as "flight gear aircraft model" are a good starting point. Be sure to comply with copyrights when distributing these files.

Hardware Requirements for Aircraft Geometry Rendering

When creating your own geometry files, keep in mind that your graphics card can efficiently render a limited number of surfaces. Some cards can efficiently render fewer than 1000 surfaces with bitmaps and specular reflections at the nominal rate of 30 frames per second. Other cards can easily render on the order of 10,000 surfaces.

If your performance slows while using a particular geometry, gauge the effect of geometric complexity on graphics performance by varying the number of aircraft model surfaces. An easy way to check this is to replace the full aircraft geometry file with a simple shape, such as a single triangle, then test FlightGear with this simpler geometry. If a geometry file is too complex for smooth display, use a 3-D geometry editor to simplify your model by reducing the number of surfaces in the geometry.

Working with Aircraft Geometry Models

Once you have obtained, modified, or created an aircraft data file, you need to put it in the correct directory for FlightGear to access it.

Importing Aircraft Models into FlightGear

To install a compatible model into FlightGear, use one of the following procedures. Choose the one appropriate for your platform. This section assumes that you have read Installing and Starting FlightGear.

If your platform is Windows:

  1. Go to your installed FlightGear directory. Open the data directory, then the Aircraft directory: \FlightGear\data\Aircraft\.

  2. Make a subdirectory model\ here for your aircraft data.

  3. Put model-set.xml in that subdirectory, plus any other files needed.

    It is common practice to make subdirectories for the vehicle geometry files (\model\), instruments (\instruments\), and sounds (\sounds\).

If your platform is UNIX or Linux:

  1. Go to your installed FlightGear directory. Open the data directory, then the Aircraft directory: $FlightGearBaseDirectory/data/Aircraft/.

  2. Make a subdirectory model/ here for your aircraft data.

  3. Put model-set.xml in that subdirectory, plus any other files needed.

    It is common practice to make subdirectories for the vehicle geometry files (/model/), instruments (/instruments/), and sounds (/sounds/).

If your platform is Mac:

  1. Open a terminal.

  2. Go to your installed FlightGear directory. Open the data directory, then the Aircraft directory:

    $FlightGearBaseDirectory/FlightGear.app/Contents/Resources/data/Aircraft/
  3. Make a subdirectory model/ here for your aircraft data.

  4. Put model-set.xml in that subdirectory, plus any other files needed.

    It is common practice to make subdirectories for the vehicle geometry files (/model/), instruments (/instruments/), and sounds (/sounds/).

Example: Animating Vehicle Geometries

This example illustrates how to prepare hinge line definitions for animated elements such as vehicle control surfaces and landing gear. To enable animation, each element must be a named entity in a geometry file. The resulting code forms part of the HL20 lifting body model presented in Running the NASA HL-20 Demo with FlightGear.

  1. The standard body coordinates used in FlightGear geometry models form a right-handed system, rotated from the standard body coordinate system in Y by -180 degrees:

    See About Aerospace Coordinate Systems for more details.

  2. Find two points that lie on the desired named-object hinge line in body coordinates and write them down as XYZ triplets or put them into a MATLAB calculation like this:

    a = [2.98, 1.89, 0.53];
    b = [3.54, 2.75, 1.46];
    
  3. Calculate the difference between the points:

    pdiff = b - a
    pdiff =
    	0.5600    0.8600    0.9300
    
  4. The hinge point is either of the points in step 2 (or the midpoint as shown here):

    mid = a + pdiff/2
    mid =
    	3.2600    2.3200    0.9950
    
  5. Put the hinge point into the animation scope in model-set.xml:

    <center>
    	<x-m>3.26</x-m>
    	<y-m>2.32</y-m>
    	<z-m>1.00</z-m>
    </center>
    
  6. Use the difference from step 3 to define the relative motion vector in the animation axis:

    <axis>
    	<x>0.56</x>
    	<y>0.86</y>
    	<z>0.93</z>
    </axis>
    
  7. Put these steps together to obtain the complete hinge line animation used in the HL20 demo model:

    <animation>
    	<type>rotate</type>
    	<object-name>RightAileron</object-name>
    	<property>/surface-positions/right-aileron-pos-norm</property>
    	<factor>30</factor>
    	<offset-deg>0</offset-deg>
    	<center>
    		<x-m>3.26</x-m>
    		<y-m>2.32</y-m>
    		<z-m>1.00</z-m>
    	</center>
    	<axis>
    		<x>0.56</x>
    		<y>0.86</y>
    		<z>0.93</z>
    	</axis>
    </animation>
    

Running FlightGear with the Simulink Models

To run a Simulink model of your aircraft and simultaneously animate it in FlightGear with an aircraft data file model-set.xml, you need to configure the aircraft data file and modify your Simulink model with some new blocks.

These are the main steps to connecting and using FlightGear with the Simulink software:

Setting the Flight Dynamics Model to Network in the Aircraft Data File

Be sure to

Obtaining the Destination IP Address

You need the destination IP address for your Simulink model to stream its flight data to FlightGear.

Adding and Connecting Interface Blocks

The easiest way to connect your model to FlightGear with the blockset is to use the FlightGear Preconfigured 6DoF Animation block:

The FlightGear Preconfigured 6DoF Animation block is a subsystem containing the Pack net_fdm Packet for FlightGear and Send net_fdm Packet to FlightGear blocks:

These blocks transmit data to a FlightGear session. The blocks are separate for maximum flexibility and compatibility.

Creating a FlightGear Run Script

To start FlightGear with the desired initial conditions (location, date, time, weather, operating modes), it is best to create a run script by Using the Generate Run Script Block or Using the Interface Provided with FlightGear.

If you make separate run scripts for each model you intend to link to FlightGear and place them in separate directories, run the appropriate script from the MATLAB interface just before starting your Simulink model.

Using the Generate Run Script Block.   The easiest way to create a run script is by using the Generate Run Script block. Use the following procedure:

  1. Open the Flight Simulator Interfaces Sublibrary.

  2. Create a new Simulink model or open an existing model.

  3. Drag a Generate Run Script block into the Simulink diagram.

  4. Double-click the Generate Run Script block. Its dialog opens.

  5. In the Output file name field, type the name of the output file. This name should be the name of the command, with the .bat extension, you want to use to start FlightGear with these initial parameters.

    For example, if your filename is runfg.bat, use the runfg command to execute the run script and start FlightGear.

  6. In the FlightGear base directory field, specify the name of your FlightGear installation directory.

  7. In the FlightGear geometry model name field, specify the name of the subdirectory, in the FlightGear/data/Aircraft directory, containing the desired model geometry.

  8. Specify the initial conditions as needed.

  9. Click the Generate Script button at the top of the Parameters area.

    The Aerospace Blockset software generates the run script, and saves it in your MATLAB working directory under the filename that you specified in the Output file name field.

  10. Repeat steps 5 through 9 to generate other run scripts, if needed.

  11. Click OK to close the dialog box. You do not need to save the Generate Run Script block with the Simulink model.

The Generate Run Script block saves the run script as a text file in your working directory. This is an example of the contents of a run script file:

>> cd D:\Applications\FlightGear-1.0
>> SET FG_ROOT=D:\Applications\FlightGear-1.0\data
>> cd \bin\Win32\
>> fgfs --aircraft=HL20 --fdm=network,localhost,5501,5502,5503
  --fog-fastest --disable-clouds --start-date-lat=2004:06:01:09:00:00 
  --disable-sound --in-air --enable-freeze --airport-id=KSFO --runway=10L
  --altitude=7224 --heading=113 --offset-distance=4.72 --offset-azimuth=0

Using the Interface Provided with FlightGear.   The FlightGear launcher GUI (part of FlightGear, not the Aerospace Blockset product) lets you build simple and advanced options into a visible FlightGear run command.

Starting FlightGear

If your computer has enough computational power to run both the Simulink software and FlightGear at the same time, a simple way to start FlightGear on a Windows system is to create a MATLAB desktop button containing the following command to execute a run script like the one created above:

system('runfg &')

To create a desktop button:

  1. From the Start button on your MATLAB desktop, click Shortcuts > New Shortcut. The Shortcut Editor dialog opens.

  2. Set the Label, Callback, Category, and Icon fields as shown in the following figure.

  3. Click Save.

    The FlightGear toolbar button appears in your MATLAB desktop. If you click it, the runfg.bat file runs in the current directory.

Once you have completed the setup, start FlightGear and run your model:

  1. Make sure your model is in a writable directory. Open the model, and update the diagram. This step ensures that any referenced block code is compiled and that the block diagram is compiled before running. Once you start FlightGear, it uses all available processor power while it is running.

  2. Click the FlightGear button or run the FlightGear run script manually.

  3. When FlightGear starts, it displays the initial view at the initial coordinates specified in the run script. If you are running the Simulink software and FlightGear on different computers, arrange to view the two displays at the same time.

  4. Now begin the simulation and view the animation in FlightGear.

Improving Performance

If your Simulink model is complex and cannot run at the aggregate rate needed for the visualization, you might need to

Running FlightGear and Simulink Software on Different Computers

It is possible to simulate an aerospace system in the Simulink environment on one computer (the source) and use its simulation output to animate FlightGear on another computer (the target). The steps are similar to those already explained, with certain modifications.

  1. Obtain the IP address of the computer running FlightGear. See Obtaining the Destination IP Address preceding.

  2. Enter this target computer's IP address in the Send net_fdm Packet to FlightGear block. See Adding and Connecting Interface Blocks preceding.

  3. Update the Generate Run Script block in your model with the target computer's FlightGear base directory. Regenerate the run script to reflect the target computer's separate identity.

    See Creating a FlightGear Run Script preceding.

  4. Copy the generated run script to the target computer. Start FlightGear there. See Starting FlightGear preceding.

  5. Start your Simulink model on the source computer. FlightGear running on the target displays the simulation motion.

Running the NASA HL-20 Demo with FlightGear

The Aerospace Blockset software contains a demo model of the NASA HL-20 lifting body that uses the FlightGear interface.

You need to have FlightGear installed and configured before attempting to simulate this model. See Introducing the Flight Simulator Interface. This section assumes that you have read Installing and Starting FlightGear. Before you start, perform the following, depending on your platform.

Windows

Copy the HL20 folder from matlabroot\toolbox\aeroblks\aerodemos\ directory to FlightGear\data\Aircraft\ directory. This folder contains the preconfigured geometries for the HL-20 simulation and HL20-set.xml. The file matlabroot\toolbox\aeroblks\aerodemos\HL20\models\HL20.xml defines the geometry.

For more about this step, see Importing Aircraft Models into FlightGear.

UNIX/Linux

Copy the HL20 directory from matlabroot/toolbox/aeroblks/aerodemos/ directory to $FlightGearBaseDirectory/data/Aircraft/ directory. This directory contains the preconfigured geometries for the HL-20 simulation and HL20-set.xml. The file matlabroot/toolbox/aeroblks/aerodemos/HL20/models/HL20.xml defines the geometry.

For more about this step, see Importing Aircraft Models into FlightGear.

Mac

Copy the HL20 directory from matlabroot/toolbox/aeroblks/aerodemos/ directory to $FlightGearBaseDirectory/FlightGear.app/Contents/Resources/data/Aircraft/ directory. This directory contains the preconfigured geometries for the HL-20 simulation and HL20-set.xml. The file matlabroot\toolbox\aeroblks\aerodemos\HL20\models\HL20.xml defines the geometry.

For more about this step, see Importing Aircraft Models into FlightGear.

  1. Start the MATLAB interface. Open the demo either by entering asbhl20 in the MATLAB Command Window or by finding the demo entry (NASA HL-20 with FlightGear Interface) in the Demos browser and clicking Open this model on its demo page. The model opens.

  2. If this is your first time running FlightGear for this model, double-click the Generate Run Script block to create a run script. Make sure to specify your FlightGear installation directory in the FlightGear base directory field. For more information, see Creating a FlightGear Run Script.

  3. Execute the script you just created manually by entering the following at the MATLAB command line:

    dos('runfg &')
    

    If you created a FlightGear desktop button, you can click it instead to start the run script and start FlightGear. For more information, see Starting FlightGear.

  4. Now start the simulation and view the animation in FlightGear.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS