The Flight Module

The Flight module provides programmers with a method of simulating flight that is both accurate and easy to operate. The module allows programmers to create landable aircraft, including tail-dragger airplanes. The module also contains several useful subroutines.

There are currently two of this module, which are all available in the jsm directory of our GitHub repository:

* Flight4 - Used to create the flight simulation demo for airplanes.
* FlightH - Used to create the flight simulation demo for helicopters.
Using the Flight4 Module in Your Program
Load Airplane Data and Import Module into Program

At the beginning of the program, prior to the importmap, you can load the airplane data using the following command:

< script src="https://PhilCrowther.github.io/Aviation/models/fm2/data/data.js"></script>
After the importmap, you can import the Flight4 module using the following command:
import {Flight,Mod360,PoM360,MaxVal,rotLLD,makMsh} from "https://PhilCrowther.github.io/Aviation/jsm/Flight4.js";
Variables

The Flight4 module uses the following variables to store data.

//- Starting Values
let BegPwr = 0;         // Initial Power Percent
let BegSpd = 0;         // Speed (kph)
let BegPos = new THREE.Vector3(0,0,0); // Position (m)
//- Constants
let	DLTime = 1/60;      // Delta Time (1/60 seconds)
let	GrvMPS = 9.80665;   // Gravity (mps)
let	AirDSL = 1.225;     // Density - Sea Level (kg/m3)
//- Variables
let	flight = 0;
let air_ = {
    // General Variables
    DLTime: DLTime,     // Seconds per frame (can vary)
    GrvMPS: GrvMPS,     // Gravity (ups)
    AirDSL: AirDSL,     // Air Density (varies with altitude)
    // Designators
    AirDat: data_,      // Aircraft Data
    // Airplane Rotation: Vertical Angle, Horizontal Angle, Bank Angle
    AirRot: new THREE.Vector3(0,0,0), // Rotation (in degrees)
    AirObj: makMsh(),   // Airplane Object 
    AirPBY: makMsh(),   // Changes in radians
    // Changes to Airplane Pitch Bank and Yaw
    RotDif: new THREE.Vector3(0,0,0), // Change
    // Airplane Speed
    SpdKPH: BegSpd,     // Speed in KPH
    SpdMPS: BegSpd/3.6, // Speed - meters per second
    SpdMPF: (BegSpd/3.6)*DLTime, // Speed - meters per frame	
    // Airplane Map Speed and Position		
    MapSpd: new THREE.Vector3(), // Map Speed (meters)
    MapPos: new THREE.Vector3().copy(BegPos), // Map Position (meters)
    MapSPS: new THREE.Vector3(0,BegPos.y,0), // MSX, MPY, MSZ (meters)	
    // Variables Obtained from Flight
    PwrPct: BegPwr,     // % of Primary Power (0 to 1) (Main and Flight)
    SupPct: 0,          // Percent of Supplemental Power (War Enmergency or Afterburner)
    CfLift: 0,          // Coefficient of Lift (user input) - determines lift
    CfFlap: 0,          // Coefficient of Lift due to flaps (user input)
    FlpPct: 0,          // Percent of Flaps
    LngPct: 0,          // Percent of Landing Gear
    BrkPct: 0,          // Percent of Air Brakes
    SplPct: 0,          // Percent of Spoiler
    AGBank: 0,          // Aileron Bank on Ground
    BrkVal: 0,          // Brakes
    GrdZed: 0,          // Ground level (default)
    GrdFlg: 0,          // Ground Flag (1 = on ground)
    ACPAdj: 0,          // Airplane pitch adjustment
    MovFlg: 0,          // If Sitting on a Moving Object
    // Values for the Selected Airplane Type (obtained from Flight)
    CfLMax: 0,          // Maximum Coefficient of Lift
    FlpCfL: 0,          // Max Flap Cfl (0.2*CfLMax)
    ACMass: 0,          // Airplane Mass
    Weight: 0,          // Used by AutoPilot
    PYBmul: new THREE.Vector3(0,0,0), // Airplane Pitch/Yaw/Bank Multiplier
    BnkMax: 0,          // Maximum bank rate
    // AutoPilot - Additional Variables
    AutoOn: 0,          // Autopilot Flag
    InpKey: new THREE.Vector3(), // Inputs - Keys (replace InpKey)
    OldRot: new THREE.Vector3(), // Old Rotation (radians)
    CfLDif: 0,          // Change in CfL
    MaxBnk: 0,          // Max Bank (display only)
    HdgDif: 0           // Horizontal Turn Rate (display only)
}
// Adjustments
	air_.AirObj.rotation.order = "YXZ";
	air_.AirPBY.rotation.order = "YXZ";
	air_.AirObj.add(air_.AirPBY); // PBY includes air_.ACPAdj
Initialization
You can use the following command in your initialization section to initialize the Flight4 module:
flight = new Flight(air_);
Animation
In your render section, you need to compute the new values for: air_.PwrPct, air_.CfLift (lift), air_.RofDif.z (bank), air_.RofDif.y (yaw). If you are on the ground, you need to compute new values for: air_.BrkVal Once you have done that, you can use the following command to update the airplane position and orientation:
flight.update();
Discussions

Here are some additional discussions of the Flight Module:

Theory - Animated examples show the underlying theory.
Programmer Guide - A Guide for Programmers.
Computations - The Flight computations.
Validating - Validating your aircraft performance.