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. This module is available in the jsm directory of our GitHub repository.
At the beginning of the program, prior to the importmap, you can load the airplane data using something like the following command:
< script src="https://PhilCrowther.github.io/Aviation/models/fm2/data/data.js"></script>
Here is the data file for the fm2:
// FM2 Wildcat
let data_ = {
// Lift
WingSp: 11.58, // Wing Span (m)
WingSq: 24.15, // Wing Area (m2)
WingAR: 5.56, // Wing Aspect Ratio (WingAr/WingSp for one wing)
WingEf: 0.75, // Wing Efficiency
AngInc: 5, // Angle of Incidence
GrvMax: 8, // Maximum G-Force
TrmAdj: 2.5, // Elevator Trim Adjustment (### - not used)
// Gravity
ACMass: 3400, // Aircraft Mass (kg)
// Thrust: Prop
PwrMax: 1007, // Prop Maximum Power (kW)
PropEf: 0.8, // Prop Efficiency
WEPMax: 0, // War Emergency Power (kW)
// Thrust: Jet
JetMax: 0, // Jet Maximum Thrust (kW)
AftMax: 0, // Jet Afterburner Maximum Thrust (kW)
// Drag
DrgCd0: 0.0211, // Coefficient of Drag
// Taildragger Geometry and Speed
Ax2CGD: 1.6667, // Axle to CG distance (m)
Ax2CGA: 330, // Axle to CG angle (deg)
WheelR: 0.3048, // Wheel radius (m)
TDrAng: 11, // Taildragger Max Angle (deg)
TDrSpd: 11.176, // Speed at which tail lifts (25 mph = 11.18 m/s)
// Optional: Flaps
FlpCfL: 0.28, // Max Flap Cfl (0.2*CfLMax) (shared with main program)
DrgCdf: 0.01, // Coefficient of Drag - Flaps
FlpAIn: 10, // Max Flap Angle of Incidence (2*AngInc)
// Optional: Landing Gear Retractable
DrgCdg: 0.005, // Coefficient of Drag - Gear
// Optional: Spoiler (not used by FM2)
SplCfL: 0, // Max Spoiler CfL
DrgCds: 0, // Coefficient of Drag - Spoiler
// Optional: Airbrake (not used by FM2)
DrgCdb: 0, // Coefficient of Drag - Airbrake
// Controls (shared with air_. and main program)
CfLMax: 1.4, // Maximum Coefficient of Lift
BnkMax: 1, // Maximum bank rate
}
After the importmap, you can import the Flight module using the following command:
import {Flight,Mod360,PoM360,MaxVal,rotLLD,makMsh} from "https://PhilCrowther.github.io/Aviation/jsm/Flight.js";
The Flight 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 BegTmp = 303.15; // Sea Level Temperature K = 86F
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: new THREE.Object3D(), // Airplane Object
AirPBY: new THREE.Object3D(), // 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 Emergency 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
// 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)
// Air Density and IAS Comps
BegTmp: BegTmp, // Beginning Sea Level Temperature (K) 303.15K = 86F
BegPrs: AirDSL, // Beginning Sea Level Air Pressure (kg/m3)
SpdIAS: 0, // Indicated Airspeed
// Ship Pitch and Bank
MovFlg: 0, // If Sitting on Moving Ship
ShpPit: 0,
ShpBnk: 0,
// G-Force
GFmult: 0,
// Vibration
LokFlg: 0,
HrzBuf: 0,
}
// Adjustments
air_.AirObj.rotation.order = "YXZ";
air_.AirPBY.rotation.order = "YXZ";
air_.AirObj.add(air_.AirPBY); // PBY includes air_.ACPAdj
You either add the above to your program or you can put the information in a separate file which you can load by using a command similar to the command for loading the data file.
If you do that, you cannot use three.js commands in the file (since the file is loaded before three.js).
Instead, you must format the variables in your program.
flight = new Flight(air_);
flight.update();
You can find several examples of flight demos here. These files include the InitAirObj and MoveAirObj subroutines which are used to initialize and move your aircraft.
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. |