NI-Tutorial-2942-en.pdf

download NI-Tutorial-2942-en.pdf

of 5

Transcript of NI-Tutorial-2942-en.pdf

  • 8/14/2019 NI-Tutorial-2942-en.pdf

    1/51/5 www.ni.com

    1.

    2.

    3.

    4.

    5.

    6.

    Visualization of MATRIXx Simulation Results Using the FlightGear Flight Simulator Publish Date: Jul 01, 2008 | 5 Ratings | out of 53.40

    Table of ContentsOverview

    Running FlightGear With SystemBuild

    Installing the FlightGear User Code Block

    Adding and Connecting Interface Block

    Creating a FlightGear Run Script

    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 uso 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 InstrumentsMATRIXx 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 MATRIXxSystemBuild.

    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 dataexchange 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 configuringhttp://www.flightgear.orgFlightGear. 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 UCBis 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 benecessary that you run your simulation on one computer while running FlightGear for visualization on a separate system. For additional information, see the Hardware Requirements andDocumentation areas of the FlightGear Web site.

    2. Running FlightGear With SystemBuild

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

    Installing the UCB code for useInstalling the FlightGear User Code Blockin your SystemBuild model - Add and connect the interface UCB Adding and Connecting Interface Blocko your SystemBuild model

    - Create a FlightGear run script compatibleCreating a FlightGear Run Scriptwith your SystemBuild model - Start FlightGear first, then run your Running FlightGear with SystemBuildSystemBuild model

    3. Installing the FlightGear User Code Block

    http://www.flightgear.org/http://www.ni.com/http://www.flightgear.org/
  • 8/14/2019 NI-Tutorial-2942-en.pdf

    2/52/5 www.ni.com

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

    User Guide.

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

    The following files should be placed in the directory of the model you want to connecto FlightGear. They are makeucb.bat, makeucb.mk, usrFlightGear.c and

    CallFlightGear.cat. The other files that are downloaded are the libraries and header files necessary to build the UCB into the simulation. These libraries and header filescan be placed in a separate folder, but the makeucb.mk file must be updated with thecorrect 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 theUCB filename. It is currently set to look in its local directory.

    The makeucb.mk file initially lists the paths to necessary header and library files asfollows:

    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 andlibrary files from the zip. A suggestion would be to place all .lib and .h files into aC:\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 makeucb.mk file updated withhis information the next step is to add the UCB to your model.

    4. Adding and Connecting Interface Block

    Connecting the UCB to your model requires providing the data required by FlightGear o perform the visualization. The full FlightGear net_fdm structure for

    communicating with FlightGear contains the following elements.

    ypedef 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 airspeedfloat climb_rate; // feet per secondfloat v_north; // north velocity in local/body frame, fpsfloat v_east; // east velocity in local/body frame, fpsfloat v_down; // down/vertical velocity in local/body frame, fpsfloat v_wind_body_north; // north velocity in local/body frame// relative to local airmass, fpsfloat 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, fpsfloat A_X_pilot; // X accel in body frame ft/sec^2float A_Y_pilot; // Y accel in body frame ft/sec^2float A_Z_pilot; // Z accel in body frame ft/sec^2float stall_warning; // 0.0 - 1.0 indicating the amount of stallfloat slip_deg; // slip ball deflectionint num_engines; // Number of valid enginesint eng_state[FG_MAX_ENGINES]; // Engine state (off, cranking, running)float rpm[FG_MAX_ENGINES]; // Engine RPM rev/minfloat fuel_flow[FG_MAX_ENGINES]; // Fuel flow gallons/hr float egt[FG_MAX_ENGINES]; // Exhaust gas temp deg Ffloat cht[FG_MAX_ENGINES]; // Cylinder head temp deg Ffloat mp_osi[FG_MAX_ENGINES]; // Manifold pressurefloat tit[FG_MAX_ENGINES]; // Turbine Inlet Temperaturefloat oil_temp[FG_MAX_ENGINES]; // Oil temp deg Ffloat oil_px[FG_MAX_ENGINES]; // Oil pressure psiint num_tanks; // Max number of fuel tanksfloat fuel_quantity[FG_MAX_TANKS];

    int num_wheels;

  • 8/14/2019 NI-Tutorial-2942-en.pdf

    3/53/5 www.ni.com

    char wow[FG_MAX_WHEELS];float gear_pos[FG_MAX_WHEELS];float gear_steer[FG_MAX_WHEELS];float gear_compression[FG_MAX_WHEELS];ime_t cur_time;

    long int warp; // offset in seconds to Unix timefloat 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;} FGNetFDM;

    The FlightGear UCB uses a subset of these as inputs to FlightGear, but is easilymodified if additional inputs are desired. The following are the currently availablesignals. 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_flap11. right_flap12. left_aileron13. right_aileron14. rudder

    The UCB takes the inputs and packs them into the net_fdm structure. This structureis written using UDP packets to a running session of FlightGear. It is set to broadcastover port 5502 to the local machine at 127.0.0.1. One method to increase systemperformance is to run the SystemBuild model on one computer and FlightGear onanother. This can be accomplished by modifying the IPaddress and WritePortvariables in the usrFlightGear.c file to the desired machine IP address and port where

    he running FlightGear session will occur.

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

    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 usinghe 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 tosimulating your SystemBuild model.

    The FlightGear launcher GUI (part of Using the GUI provided with FlightGear.FlightGear) lets you build up simple and advanced options into a visible runcommand 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-

  • 8/14/2019 NI-Tutorial-2942-en.pdf

    4/54/5 www.ni.com

    documentation.Installation and Getting Started

    The setup for FlightGear to receive external flight information is a matter of changingsome internal options. The following figures show the settings necessary to enablehe 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 seenbelow. These options can be used in conjunction with the runfgfs batch file toimplement a command line launch mechanism.

    6. Running FlightGear with SystemBuild

    The easiest way to start FlightGear is too launch it from the WindowsStart>>Programs menu. FlightGear also supports the command line option alludedo previously that may be launched from a command shell or using the Xmath mathscript

    command. The process is further outlined in theoscmd FlightGear Flight Simulator- documentation.Installation and Getting Started

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

    1. Load your model. A demonstration model is provided in the CallFlightGear.catcatalog file. This model can be used to exercise altitude, pitch, roll, yaw andrudder 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

  • 8/14/2019 NI-Tutorial-2942-en.pdf

    5/55/5 www.ni.com

    are running SystemBuild and FlightGear from different computers, arrangeo see the two displays at the same time.

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

    With the FlightGear window in focus, the key can be used to alternateNote: Vbetween 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

    http://joule.ni.com/nidu/cds/view/p/lang/en/id/149http://joule.ni.com/nidu/cds/view/p/lang/en/id/149