Initial revision.
This commit is contained in:
parent
91cb0e2a99
commit
bef268a4cd
32 changed files with 4289 additions and 0 deletions
450
JSBsim/FGAircraft.cpp
Normal file
450
JSBsim/FGAircraft.cpp
Normal file
|
@ -0,0 +1,450 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGAircraft.cpp
|
||||||
|
Author: Jon S. Berndt
|
||||||
|
Date started: 12/12/98
|
||||||
|
Purpose: Encapsulates an aircraft
|
||||||
|
Called by: FGFDMExec
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
Models the aircraft reactions and forces.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/12/98 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
COMMENTS, REFERENCES, and NOTES
|
||||||
|
********************************************************************************
|
||||||
|
[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
|
||||||
|
Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
|
||||||
|
School, January 1994
|
||||||
|
[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
|
||||||
|
JSC 12960, July 1977
|
||||||
|
[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
|
||||||
|
NASA-Ames", NASA CR-2497, January 1975
|
||||||
|
[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
|
||||||
|
Wiley & Sons, 1979 ISBN 0-471-03032-5
|
||||||
|
[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
|
||||||
|
1982 ISBN 0-471-08936-2
|
||||||
|
|
||||||
|
The aerodynamic coefficients used in this model are:
|
||||||
|
|
||||||
|
Longitudinal
|
||||||
|
CL0 - Reference lift at zero alpha
|
||||||
|
CD0 - Reference drag at zero alpha
|
||||||
|
CDM - Drag due to Mach
|
||||||
|
CLa - Lift curve slope (w.r.t. alpha)
|
||||||
|
CDa - Drag curve slope (w.r.t. alpha)
|
||||||
|
CLq - Lift due to pitch rate
|
||||||
|
CLM - Lift due to Mach
|
||||||
|
CLadt - Lift due to alpha rate
|
||||||
|
|
||||||
|
Cmadt - Pitching Moment due to alpha rate
|
||||||
|
Cm0 - Reference Pitching moment at zero alpha
|
||||||
|
Cma - Pitching moment slope (w.r.t. alpha)
|
||||||
|
Cmq - Pitch damping (pitch moment due to pitch rate)
|
||||||
|
CmM - Pitch Moment due to Mach
|
||||||
|
|
||||||
|
Lateral
|
||||||
|
Cyb - Side force due to sideslip
|
||||||
|
Cyr - Side force due to yaw rate
|
||||||
|
|
||||||
|
Clb - Dihedral effect (roll moment due to sideslip)
|
||||||
|
Clp - Roll damping (roll moment due to roll rate)
|
||||||
|
Clr - Roll moment due to yaw rate
|
||||||
|
Cnb - Weathercocking stability (yaw moment due to sideslip)
|
||||||
|
Cnp - Rudder adverse yaw (yaw moment due to roll rate)
|
||||||
|
Cnr - Yaw damping (yaw moment due to yaw rate)
|
||||||
|
|
||||||
|
Control
|
||||||
|
CLDe - Lift due to elevator
|
||||||
|
CDDe - Drag due to elevator
|
||||||
|
CyDr - Side force due to rudder
|
||||||
|
CyDa - Side force due to aileron
|
||||||
|
|
||||||
|
CmDe - Pitch moment due to elevator
|
||||||
|
ClDa - Roll moment due to aileron
|
||||||
|
ClDr - Roll moment due to rudder
|
||||||
|
CnDr - Yaw moment due to rudder
|
||||||
|
CnDa - Yaw moment due to aileron
|
||||||
|
|
||||||
|
This class expects to be run in a directory which contains the subdirectory
|
||||||
|
structure shown below (where example aircraft X-15 is shown):
|
||||||
|
|
||||||
|
aircraft/
|
||||||
|
X-15/
|
||||||
|
X-15.dat reset00 reset01 reset02 ...
|
||||||
|
CDRAG/
|
||||||
|
a0 a M De
|
||||||
|
CSIDE/
|
||||||
|
b r Dr Da
|
||||||
|
CLIFT/
|
||||||
|
a0 a M adt De
|
||||||
|
CROLL/
|
||||||
|
b p r Da Dr
|
||||||
|
CPITCH/
|
||||||
|
a0 a adt q M De
|
||||||
|
CYAW/
|
||||||
|
b p r Dr Da
|
||||||
|
F-16/
|
||||||
|
F-16.dat reset00 reset01 ...
|
||||||
|
CDRAG/
|
||||||
|
a0 a M De
|
||||||
|
...
|
||||||
|
|
||||||
|
The General Idea
|
||||||
|
|
||||||
|
The file structure is arranged so that various modeled aircraft are stored in
|
||||||
|
their own subdirectory. Each aircraft subdirectory is named after the aircraft.
|
||||||
|
There should be a file present in the specific aircraft subdirectory (e.g.
|
||||||
|
aircraft/X-15) with the same name as the directory with a .dat appended. This
|
||||||
|
file contains mass properties information, name of aircraft, etc. for the
|
||||||
|
aircraft. In that same directory are reset files numbered starting from 0 (two
|
||||||
|
digit numbers), e.g. reset03. Within each reset file are values for important
|
||||||
|
state variables for specific flight conditions (altitude, airspeed, etc.). Also
|
||||||
|
within this directory are the directories containing lookup tables for the
|
||||||
|
stability derivatives for the aircraft.
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
#include "FGAircraft.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
FGAircraft::FGAircraft(void) : FGModel()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
strcpy(Name,"FGAircraft");
|
||||||
|
|
||||||
|
for (i=0;i<6;i++) Axis[i] = (char*)malloc(7);
|
||||||
|
for (i=0;i<6;i++) coeff_ctr[i] = 0;
|
||||||
|
|
||||||
|
strcpy(Axis[LiftCoeff],"CLIFT");
|
||||||
|
strcpy(Axis[DragCoeff],"CDRAG");
|
||||||
|
strcpy(Axis[SideCoeff],"CSIDE");
|
||||||
|
strcpy(Axis[RollCoeff],"CROLL");
|
||||||
|
strcpy(Axis[PitchCoeff],"CPITCH");
|
||||||
|
strcpy(Axis[YawCoeff],"CYAW");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGAircraft::~FGAircraft(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGAircraft::LoadAircraft(char* fname)
|
||||||
|
{
|
||||||
|
char path[250];
|
||||||
|
char fullpath[275];
|
||||||
|
char filename[275];
|
||||||
|
char aircraftDef[2100];
|
||||||
|
char tag[220];
|
||||||
|
DIR* dir;
|
||||||
|
DIR* coeffdir;
|
||||||
|
struct dirent* dirEntry = 0L;
|
||||||
|
struct dirent* coeffdirEntry = 0L;
|
||||||
|
struct stat st;
|
||||||
|
struct stat st2;
|
||||||
|
ifstream coeffInFile;
|
||||||
|
|
||||||
|
char scratch[250];
|
||||||
|
|
||||||
|
sprintf(aircraftDef, "/h/curt/projects/FlightGear/Simulator/FDM/JSBsim/aircraft/%s/%s.dat", fname, fname);
|
||||||
|
ifstream aircraftfile(aircraftDef);
|
||||||
|
|
||||||
|
if (aircraftfile) {
|
||||||
|
aircraftfile >> AircraftName;
|
||||||
|
aircraftfile >> WingArea;
|
||||||
|
aircraftfile >> WingSpan;
|
||||||
|
aircraftfile >> cbar;
|
||||||
|
aircraftfile >> Ixx;
|
||||||
|
aircraftfile >> Iyy;
|
||||||
|
aircraftfile >> Izz;
|
||||||
|
aircraftfile >> Ixz;
|
||||||
|
aircraftfile >> Weight;
|
||||||
|
m = Weight / 32.174;
|
||||||
|
aircraftfile >> tag;
|
||||||
|
|
||||||
|
numTanks = numEngines = 0;
|
||||||
|
numSelectedOxiTanks = numSelectedFuelTanks = 0;
|
||||||
|
|
||||||
|
while (strstr(tag,"EOF") == 0) {
|
||||||
|
if (strstr(tag,"CGLOC")) {
|
||||||
|
aircraftfile >> Xcg;
|
||||||
|
aircraftfile >> Ycg;
|
||||||
|
aircraftfile >> Zcg;
|
||||||
|
} else if (strstr(tag,"EYEPOINTLOC")) {
|
||||||
|
aircraftfile >> Xep;
|
||||||
|
aircraftfile >> Yep;
|
||||||
|
aircraftfile >> Zep;
|
||||||
|
} else if (strstr(tag,"TANK")) {
|
||||||
|
Tank[numTanks] = new FGTank(aircraftfile);
|
||||||
|
switch(Tank[numTanks]->GetType()) {
|
||||||
|
case 0:
|
||||||
|
numSelectedOxiTanks++;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
numSelectedFuelTanks++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
numTanks++;
|
||||||
|
} else if (strstr(tag,"ENGINE")) {
|
||||||
|
aircraftfile >> tag;
|
||||||
|
Engine[numEngines] = new FGEngine(tag);
|
||||||
|
numEngines++;
|
||||||
|
}
|
||||||
|
aircraftfile >> tag;
|
||||||
|
}
|
||||||
|
aircraftfile.close();
|
||||||
|
PutState();
|
||||||
|
|
||||||
|
// Read subdirectory for this aircraft for stability derivative lookup tables:
|
||||||
|
//
|
||||||
|
// Build up the path name to the aircraft file by appending the aircraft
|
||||||
|
// name to the "aircraft/" initial path. Initialize the directory entry
|
||||||
|
// structure dirEntry in preparation for reading through the directory.
|
||||||
|
// Build up a path to each file in the directory sequentially and "stat" it
|
||||||
|
// to see if the entry is a directory or a file. If the entry is a file, then
|
||||||
|
// compare it to each string in the Axis[] array to see which axis the
|
||||||
|
// directory represents: Lift, Drag, Side, Roll, Pitch, Yaw. When the match
|
||||||
|
// is found, go into that directory and search for any coefficient files.
|
||||||
|
// Build a new coefficient by passing the full pathname to the coefficient
|
||||||
|
// file to the FGCoefficient constructor.
|
||||||
|
//
|
||||||
|
// Note: axis_ctr=0 for the Lift "axis", 1 for Drag, 2 for Side force, 3 for
|
||||||
|
// Roll, 4 for Pitch, and 5 for Yaw. The term coeff_ctr merely keeps
|
||||||
|
// track of the number of coefficients registered for each of the
|
||||||
|
// previously mentioned axis.
|
||||||
|
|
||||||
|
sprintf(path,"/h/curt/projects/FlightGear/Simulator/FDM/JSBsim/aircraft/%s/",AircraftName);
|
||||||
|
if ( dir = opendir(path) ) {
|
||||||
|
|
||||||
|
while (dirEntry = readdir(dir)) {
|
||||||
|
sprintf(fullpath,"%s%s",path,dirEntry->d_name);
|
||||||
|
stat(fullpath,&st);
|
||||||
|
if ((st.st_mode & S_IFMT) == S_IFDIR) {
|
||||||
|
for (int axis_ctr=0; axis_ctr < 6; axis_ctr++) {
|
||||||
|
if (strstr(dirEntry->d_name,Axis[axis_ctr])) {
|
||||||
|
if (coeffdir = opendir(fullpath)) {
|
||||||
|
while (coeffdirEntry = readdir(coeffdir)) {
|
||||||
|
if (coeffdirEntry->d_name[0] != '.') {
|
||||||
|
sprintf(filename,"%s%s/%s",path,Axis[axis_ctr],coeffdirEntry->d_name);
|
||||||
|
stat(filename,&st2);
|
||||||
|
if (st2.st_size > 6) {
|
||||||
|
Coeff[axis_ctr][coeff_ctr[axis_ctr]] = new FGCoefficient(filename);
|
||||||
|
coeff_ctr[axis_ctr]++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cerr << "Could not open directory " << path << " for reading" << endl;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
cerr << "Unable to open aircraft definition file " << fname << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGAircraft::Run(void)
|
||||||
|
{
|
||||||
|
if (!FGModel::Run()) { // if false then execute this Run()
|
||||||
|
GetState();
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) Forces[i] = Moments[i] = 0.0;
|
||||||
|
|
||||||
|
FProp(); FAero(); FGear(); FMass();
|
||||||
|
MProp(); MAero(); MGear(); MMass();
|
||||||
|
|
||||||
|
PutState();
|
||||||
|
} else { // skip Run() execution this time
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGAircraft::FAero(void)
|
||||||
|
{
|
||||||
|
float F[3];
|
||||||
|
|
||||||
|
F[0] = F[1] = F[2] = 0.0;
|
||||||
|
|
||||||
|
for (int axis_ctr = 0; axis_ctr < 3; axis_ctr++)
|
||||||
|
for (int ctr=0; ctr < coeff_ctr[axis_ctr]; ctr++)
|
||||||
|
F[axis_ctr] += Coeff[axis_ctr][ctr]->Value();
|
||||||
|
|
||||||
|
Forces[0] += F[LiftCoeff]*sin(alpha) - F[DragCoeff]*cos(alpha) - F[SideCoeff]*sin(beta);
|
||||||
|
Forces[1] += F[SideCoeff]*cos(beta);
|
||||||
|
Forces[2] += -F[LiftCoeff]*cos(alpha) - F[DragCoeff]*sin(alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGAircraft::FGear(void)
|
||||||
|
{
|
||||||
|
if (GearUp) {
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGAircraft::FMass(void)
|
||||||
|
{
|
||||||
|
Forces[0] += -g*sin(tht) * m;
|
||||||
|
Forces[1] += g*sin(phi)*cos(tht) * m;
|
||||||
|
Forces[2] += g*cos(phi)*cos(tht) * m;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGAircraft::FProp(void)
|
||||||
|
{
|
||||||
|
float Oshortage, Fshortage;
|
||||||
|
|
||||||
|
for (int i=0;i<numEngines;i++) {
|
||||||
|
Forces[0] += Engine[i]->CalcThrust();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// UPDATE TANK CONTENTS
|
||||||
|
//
|
||||||
|
// For each engine, cycle through the tanks and draw an equal amount of
|
||||||
|
// fuel (or oxidizer) from each active tank. The needed amount of fuel is
|
||||||
|
// determined by the engine in the FGEngine class. If more fuel is needed
|
||||||
|
// than is available in the tank, then that amount is considered a shortage,
|
||||||
|
// and will be drawn from the next tank. If the engine cannot be fed what it
|
||||||
|
// needs, it will be considered to be starved, and will shut down.
|
||||||
|
|
||||||
|
for (int e=0; e<numEngines; e++) {
|
||||||
|
Fshortage = Oshortage = 0.0;
|
||||||
|
for (int t=0; t<numTanks; t++) {
|
||||||
|
switch(Engine[e]->GetType()) {
|
||||||
|
case 0: // Rocket
|
||||||
|
switch(Tank[t]->GetType()) {
|
||||||
|
case 0: // Fuel
|
||||||
|
if (Tank[t]->GetSelected()) {
|
||||||
|
Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/numSelectedFuelTanks)*(dt*rate) + Fshortage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 1: // Oxidizer
|
||||||
|
if (Tank[t]->GetSelected()) {
|
||||||
|
Oshortage = Tank[t]->Reduce((Engine[e]->CalcOxidizerNeed()/numSelectedOxiTanks)*(dt*rate) + Oshortage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default: // piston, turbojet, turbofan, etc.
|
||||||
|
if (Tank[t]->GetSelected()) {
|
||||||
|
Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/numSelectedFuelTanks)*(dt*rate) + Fshortage);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((Fshortage < 0.0) || (Oshortage < 0.0)) Engine[e]->SetStarved();
|
||||||
|
else Engine[e]->SetStarved(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGAircraft::MAero(void)
|
||||||
|
{
|
||||||
|
for (int axis_ctr = 0; axis_ctr < 3; axis_ctr++)
|
||||||
|
for (int ctr = 0; ctr < coeff_ctr[axis_ctr+3]; ctr++)
|
||||||
|
Moments[axis_ctr] += Coeff[axis_ctr+3][ctr]->Value();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGAircraft::MGear(void)
|
||||||
|
{
|
||||||
|
if (GearUp) {
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGAircraft::MMass(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGAircraft::MProp(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGAircraft::GetState(void)
|
||||||
|
{
|
||||||
|
Ixx = State->GetIxx();
|
||||||
|
Iyy = State->GetIyy();
|
||||||
|
Izz = State->GetIzz();
|
||||||
|
Ixz = State->GetIxz();
|
||||||
|
alpha = State->Getalpha();
|
||||||
|
beta = State->Getbeta();
|
||||||
|
m = State->Getm();
|
||||||
|
phi = State->Getphi();
|
||||||
|
tht = State->Gettht();
|
||||||
|
psi = State->Getpsi();
|
||||||
|
g = State->Getg();
|
||||||
|
dt = State->Getdt();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGAircraft::PutState(void)
|
||||||
|
{
|
||||||
|
State->SetIxx(Ixx);
|
||||||
|
State->SetIyy(Iyy);
|
||||||
|
State->SetIzz(Izz);
|
||||||
|
State->SetIxz(Ixz);
|
||||||
|
State->SetFx(Forces[0]);
|
||||||
|
State->SetFy(Forces[1]);
|
||||||
|
State->SetFz(Forces[2]);
|
||||||
|
State->SetL(Moments[0]);
|
||||||
|
State->SetM(Moments[1]);
|
||||||
|
State->SetN(Moments[2]);
|
||||||
|
State->Setm(m);
|
||||||
|
}
|
||||||
|
|
194
JSBsim/FGAircraft.h
Normal file
194
JSBsim/FGAircraft.h
Normal file
|
@ -0,0 +1,194 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGAircraft.h
|
||||||
|
Author: Jon S. Berndt
|
||||||
|
Date started: 12/12/98
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/12/98 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGAIRCRAFT_H
|
||||||
|
#define FGAIRCRAFT_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
COMMENTS, REFERENCES, and NOTES
|
||||||
|
********************************************************************************
|
||||||
|
[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
|
||||||
|
Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
|
||||||
|
School, January 1994
|
||||||
|
[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
|
||||||
|
JSC 12960, July 1977
|
||||||
|
[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
|
||||||
|
NASA-Ames", NASA CR-2497, January 1975
|
||||||
|
[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
|
||||||
|
Wiley & Sons, 1979 ISBN 0-471-03032-5
|
||||||
|
[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
|
||||||
|
1982 ISBN 0-471-08936-2
|
||||||
|
|
||||||
|
The aerodynamic coefficients used in this model are:
|
||||||
|
|
||||||
|
Longitudinal
|
||||||
|
CL0 - Reference lift at zero alpha
|
||||||
|
CD0 - Reference drag at zero alpha
|
||||||
|
CDM - Drag due to Mach
|
||||||
|
CLa - Lift curve slope (w.r.t. alpha)
|
||||||
|
CDa - Drag curve slope (w.r.t. alpha)
|
||||||
|
CLq - Lift due to pitch rate
|
||||||
|
CLM - Lift due to Mach
|
||||||
|
CLadt - Lift due to alpha rate
|
||||||
|
|
||||||
|
Cmadt - Moment due to alpha rate
|
||||||
|
Cm0 - Reference moment at zero alpha
|
||||||
|
Cma - Pitching moment slope (w.r.t. alpha)
|
||||||
|
Cmq - Pitch damping (pitch moment due to pitch rate)
|
||||||
|
CmM - Moment due to Mach
|
||||||
|
|
||||||
|
Lateral
|
||||||
|
Cyb - Side force due to sideslip
|
||||||
|
Cyr - Side force due to yaw rate
|
||||||
|
|
||||||
|
Clb - Dihedral effect (roll moment due to sideslip)
|
||||||
|
Clp - Roll damping (roll moment due to roll rate)
|
||||||
|
Clr - Roll moment due to yaw rate
|
||||||
|
Cnb - Weathercocking stability (yaw moment due to sideslip)
|
||||||
|
Cnp - Rudder adverse yaw (yaw moment due to roll rate)
|
||||||
|
Cnr - Yaw damping (yaw moment due to yaw rate)
|
||||||
|
|
||||||
|
Control
|
||||||
|
ClDe - Lift due to elevator
|
||||||
|
CdDe - Drag due to elevator
|
||||||
|
CyDr - Side force due to rudder
|
||||||
|
CyDa - Side force due to aileron
|
||||||
|
|
||||||
|
CmDe - Pitch moment due to elevator
|
||||||
|
ClDa - Roll moment due to aileron
|
||||||
|
ClDr - Roll moment due to rudder
|
||||||
|
CnDr - Yaw moment due to rudder
|
||||||
|
CnDa - Yaw moment due to aileron
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fstream.h>
|
||||||
|
|
||||||
|
#include "FGModel.h"
|
||||||
|
#include "FGCoefficient.h"
|
||||||
|
#include "FGEngine.h"
|
||||||
|
#include "FGTank.h"
|
||||||
|
//#include "FGMatrix.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
DEFINITIONS
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
class FGAircraft : public FGModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGAircraft(void);
|
||||||
|
~FGAircraft(void);
|
||||||
|
|
||||||
|
bool Run(void);
|
||||||
|
bool LoadAircraft(char*);
|
||||||
|
char* GetAircraftName(void) {return AircraftName;}
|
||||||
|
inline void SetGearUp(bool tt) {GearUp = tt;}
|
||||||
|
inline bool GetGearUp(void) {return GearUp;}
|
||||||
|
inline float GetWingArea(void) {return WingArea;}
|
||||||
|
inline float GetWingSpan(void) {return WingSpan;}
|
||||||
|
inline float Getcbar(void) {return cbar;}
|
||||||
|
inline FGEngine* GetEngine(int tt) {return Engine[tt];}
|
||||||
|
inline FGTank* GetTank(int tt) {return Tank[tt];}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void GetState(void);
|
||||||
|
void PutState(void);
|
||||||
|
|
||||||
|
void FAero(void);
|
||||||
|
void FGear(void);
|
||||||
|
void FMass(void);
|
||||||
|
void FProp(void);
|
||||||
|
|
||||||
|
void MAero(void);
|
||||||
|
void MGear(void);
|
||||||
|
void MMass(void);
|
||||||
|
void MProp(void);
|
||||||
|
|
||||||
|
float Moments[3];
|
||||||
|
float Forces[3];
|
||||||
|
|
||||||
|
char AircraftName[50];
|
||||||
|
float Ixx, Iyy, Izz, Ixz, m;
|
||||||
|
float Xcg, Ycg, Zcg;
|
||||||
|
float Xep, Yep, Zep;
|
||||||
|
float rho, qbar, Vt;
|
||||||
|
float alpha, beta;
|
||||||
|
float WingArea, WingSpan, cbar;
|
||||||
|
float g, phi, tht, psi;
|
||||||
|
float Weight;
|
||||||
|
float dt;
|
||||||
|
|
||||||
|
int numTanks;
|
||||||
|
int numEngines;
|
||||||
|
int numSelectedOxiTanks;
|
||||||
|
int numSelectedFuelTanks;
|
||||||
|
FGTank* Tank[30];
|
||||||
|
FGEngine *Engine[10];
|
||||||
|
|
||||||
|
FGCoefficient *Coeff[6][10];
|
||||||
|
int coeff_ctr[6];
|
||||||
|
|
||||||
|
bool GearUp;
|
||||||
|
|
||||||
|
enum Param {LiftCoeff,
|
||||||
|
DragCoeff,
|
||||||
|
SideCoeff,
|
||||||
|
RollCoeff,
|
||||||
|
PitchCoeff,
|
||||||
|
YawCoeff,
|
||||||
|
numCoeffs};
|
||||||
|
|
||||||
|
char* Axis[6];
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef FDM_MAIN
|
||||||
|
extern FGAircraft* Aircraft;
|
||||||
|
#else
|
||||||
|
FGAircraft* Aircraft;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
73
JSBsim/FGAtmosphere.cpp
Normal file
73
JSBsim/FGAtmosphere.cpp
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGAtmosphere.cpp
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 11/24/98
|
||||||
|
Purpose: Models the atmosphere
|
||||||
|
Called by: FGSimExec
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
Models the atmosphere. The equation used below was determined by a third order
|
||||||
|
curve fit using Excel. The data is from the ICAO atmosphere model.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
11/24/98 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGAtmosphere.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
FGAtmosphere::FGAtmosphere() : FGModel()
|
||||||
|
{
|
||||||
|
strcpy(Name,"FGAtmosphere");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGAtmosphere::~FGAtmosphere()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGAtmosphere::Run(void)
|
||||||
|
{
|
||||||
|
if (!FGModel::Run()) { // if false then execute this Run()
|
||||||
|
State->Setrho(0.002377 - 7.0E-08*State->Geth()
|
||||||
|
+ 7.0E-13*State->Geth()*State->Geth()
|
||||||
|
- 2.0E-18*State->Geth()*State->Geth()*State->Geth());
|
||||||
|
|
||||||
|
State->SetMach(State->GetVt()/State->Geta());
|
||||||
|
} else { // skip Run() execution this time
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
68
JSBsim/FGAtmosphere.h
Normal file
68
JSBsim/FGAtmosphere.h
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGAtmosphere.h
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 11/24/98
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
11/24/98 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGATMOSPHERE_H
|
||||||
|
#define FGATMOSPHERE_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGModel.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGAtmosphere : public FGModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGAtmosphere(void);
|
||||||
|
~FGAtmosphere(void);
|
||||||
|
bool Run(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef FDM_MAIN
|
||||||
|
extern FGAtmosphere* Atmosphere;
|
||||||
|
#else
|
||||||
|
FGAtmosphere* Atmosphere;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
69
JSBsim/FGAuxiliary.cpp
Normal file
69
JSBsim/FGAuxiliary.cpp
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGAuxiliary.cpp
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 01/26/99
|
||||||
|
Purpose: Calculates additional parameters needed by the visual system, etc.
|
||||||
|
Called by: FGSimExec
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
This class calculates various auxiliary parameters, mostly used by the visual
|
||||||
|
system
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
01/26/99 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGAuxiliary.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
FGAuxiliary::FGAuxiliary() : FGModel()
|
||||||
|
{
|
||||||
|
strcpy(Name, "FGAuxiliary");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGAuxiliary::~FGAuxiliary()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGAuxiliary::Run()
|
||||||
|
{
|
||||||
|
if (!FGModel::Run()) {
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
72
JSBsim/FGAuxiliary.h
Normal file
72
JSBsim/FGAuxiliary.h
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGAuxiliary.h
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 01/26/99
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
11/22/98 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGAUXILIARY_H
|
||||||
|
#define FGAUXILIARY_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
#include "FGModel.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
DEFINES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGAuxiliary : public FGModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGAuxiliary(void);
|
||||||
|
~FGAuxiliary(void);
|
||||||
|
|
||||||
|
bool Run(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef FDM_MAIN
|
||||||
|
extern FGAuxiliary* Auxiliary;
|
||||||
|
#else
|
||||||
|
FGAuxiliary* Auxiliary;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
412
JSBsim/FGCoefficient.cpp
Normal file
412
JSBsim/FGCoefficient.cpp
Normal file
|
@ -0,0 +1,412 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGCoefficient.cpp
|
||||||
|
Author: Jon S. Berndt
|
||||||
|
Date started: 12/28/98
|
||||||
|
Purpose: Encapsulates the stability derivative class FGCoefficient;
|
||||||
|
Called by: FGAircraft
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
This class models the stability derivative coefficient lookup tables or
|
||||||
|
equations. Note that the coefficients need not be calculated each delta-t.
|
||||||
|
|
||||||
|
The coefficient files are located in the axis subdirectory for each aircraft.
|
||||||
|
For instance, for the X-15, you would find subdirectories under the
|
||||||
|
aircraft/X-15/ directory named CLIFT, CDRAG, CSIDE, CROLL, CPITCH, CYAW. Under
|
||||||
|
each of these directories would be files named a, a0, q, and so on. The file
|
||||||
|
named "a" under the CLIFT directory would contain data for the stability
|
||||||
|
derivative modeling lift due to a change in alpha. See the FGAircraft.cpp file
|
||||||
|
for additional information. The coefficient files have the following format:
|
||||||
|
|
||||||
|
<name of coefficient>
|
||||||
|
<short description of coefficient with no embedded spaces>
|
||||||
|
<method used in calculating the coefficient: TABLE | EQUATION | VECTOR | VALUE>
|
||||||
|
<parameter identifier for table row (if required)>
|
||||||
|
<parameter identifier for table column (if required)>
|
||||||
|
<OR'ed list of parameter identifiers needed to turn this coefficient into a force>
|
||||||
|
<number of rows in table (if required)>
|
||||||
|
<number of columns in table (if required)>
|
||||||
|
|
||||||
|
<value of parameter indexing into the column of a table or vector - or value
|
||||||
|
itself for a VALUE coefficient>
|
||||||
|
<values of parameter indexing into row of a table if TABLE type> <Value of
|
||||||
|
coefficient at this row and column>
|
||||||
|
|
||||||
|
<... repeat above for each column of data in table ...>
|
||||||
|
|
||||||
|
As an example for the X-15, for the lift due to mach:
|
||||||
|
|
||||||
|
CLa0
|
||||||
|
Lift_at_zero_alpha
|
||||||
|
Table 8 3
|
||||||
|
16384
|
||||||
|
32768
|
||||||
|
16387
|
||||||
|
|
||||||
|
0.00
|
||||||
|
0.0 0.0
|
||||||
|
0.5 0.4
|
||||||
|
0.9 0.9
|
||||||
|
1.0 1.6
|
||||||
|
1.1 1.3
|
||||||
|
1.4 1.0
|
||||||
|
2.0 0.5
|
||||||
|
3.0 0.5
|
||||||
|
|
||||||
|
30000.00
|
||||||
|
0.0 0.0
|
||||||
|
0.5 0.5
|
||||||
|
0.9 1.0
|
||||||
|
1.0 1.7
|
||||||
|
1.1 1.4
|
||||||
|
1.4 1.1
|
||||||
|
2.0 0.6
|
||||||
|
3.0 0.6
|
||||||
|
|
||||||
|
70000.00
|
||||||
|
0.0 0.0
|
||||||
|
0.5 0.6
|
||||||
|
0.9 1.1
|
||||||
|
1.0 1.7
|
||||||
|
1.1 1.5
|
||||||
|
1.4 1.2
|
||||||
|
2.0 0.7
|
||||||
|
3.0 0.7
|
||||||
|
|
||||||
|
Note that the values in a row which index into the table must be the same value
|
||||||
|
for each column of data, so the first column of numbers for each altitude are
|
||||||
|
seen to be equal, and there are the same number of values for each altitude.
|
||||||
|
|
||||||
|
See the header file FGCoefficient.h for the values of the identifiers.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/28/98 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGCoefficient;
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "FGFCS.h"
|
||||||
|
#include "FGAircraft.h"
|
||||||
|
#include "FGCoefficient.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
FGCoefficient::FGCoefficient(void)
|
||||||
|
{
|
||||||
|
rows = columns = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGCoefficient::FGCoefficient(char* fname)
|
||||||
|
{
|
||||||
|
int r, c;
|
||||||
|
float ftrashcan;
|
||||||
|
|
||||||
|
ifstream coeffDefFile(fname);
|
||||||
|
|
||||||
|
if (coeffDefFile) {
|
||||||
|
if (!coeffDefFile.fail()) {
|
||||||
|
coeffDefFile >> name;
|
||||||
|
coeffDefFile >> description;
|
||||||
|
coeffDefFile >> method;
|
||||||
|
|
||||||
|
if (strcmp(method,"EQUATION") == 0) type = 4;
|
||||||
|
else if (strcmp(method,"TABLE") == 0) type = 3;
|
||||||
|
else if (strcmp(method,"VECTOR") == 0) type = 2;
|
||||||
|
else if (strcmp(method,"VALUE") == 0) type = 1;
|
||||||
|
else type = 0;
|
||||||
|
|
||||||
|
if (type == 2 || type == 3) {
|
||||||
|
coeffDefFile >> rows;
|
||||||
|
if (type == 3) {
|
||||||
|
coeffDefFile >> columns;
|
||||||
|
}
|
||||||
|
coeffDefFile >> LookupR;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == 3) {
|
||||||
|
coeffDefFile >> LookupC;
|
||||||
|
}
|
||||||
|
|
||||||
|
coeffDefFile >> multipliers;
|
||||||
|
|
||||||
|
mult_count = 0;
|
||||||
|
if (multipliers & FG_QBAR) {
|
||||||
|
mult_idx[mult_count] = FG_QBAR;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_WINGAREA) {
|
||||||
|
mult_idx[mult_count] = FG_WINGAREA;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_WINGSPAN) {
|
||||||
|
mult_idx[mult_count] = FG_WINGSPAN;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_CBAR) {
|
||||||
|
mult_idx[mult_count] = FG_CBAR;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_ALPHA) {
|
||||||
|
mult_idx[mult_count] = FG_ALPHA;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_ALPHADOT) {
|
||||||
|
mult_idx[mult_count] = FG_ALPHADOT;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_BETA) {
|
||||||
|
mult_idx[mult_count] = FG_BETA;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_BETADOT) {
|
||||||
|
mult_idx[mult_count] = FG_BETADOT;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_PITCHRATE) {
|
||||||
|
mult_idx[mult_count] = FG_PITCHRATE;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_ROLLRATE) {
|
||||||
|
mult_idx[mult_count] = FG_ROLLRATE;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_YAWRATE) {
|
||||||
|
mult_idx[mult_count] = FG_YAWRATE;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_ELEVATOR) {
|
||||||
|
mult_idx[mult_count] = FG_ELEVATOR;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_AILERON) {
|
||||||
|
mult_idx[mult_count] = FG_AILERON;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_RUDDER) {
|
||||||
|
mult_idx[mult_count] = FG_RUDDER;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_MACH) {
|
||||||
|
mult_idx[mult_count] = FG_MACH;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
if (multipliers & FG_ALTITUDE) {
|
||||||
|
mult_idx[mult_count] = FG_ALTITUDE;
|
||||||
|
mult_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(type) {
|
||||||
|
case 1:
|
||||||
|
coeffDefFile >> StaticValue;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Allocate(rows,2);
|
||||||
|
|
||||||
|
for (r=1;r<=rows;r++) {
|
||||||
|
coeffDefFile >> Table3D[r][0];
|
||||||
|
coeffDefFile >> Table3D[r][1];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
Allocate(rows, columns);
|
||||||
|
|
||||||
|
for (c=1;c<=columns;c++) {
|
||||||
|
coeffDefFile >> Table3D[0][c];
|
||||||
|
for (r=1;r<=rows;r++) {
|
||||||
|
if ( c==1 ) coeffDefFile >> Table3D[r][0];
|
||||||
|
else coeffDefFile >> ftrashcan;
|
||||||
|
coeffDefFile >> Table3D[r][c];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cerr << "Empty file" << endl;
|
||||||
|
}
|
||||||
|
coeffDefFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGCoefficient::FGCoefficient(int r, int c)
|
||||||
|
{
|
||||||
|
rows = r;
|
||||||
|
columns = c;
|
||||||
|
Allocate(r,c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGCoefficient::FGCoefficient(int n)
|
||||||
|
{
|
||||||
|
rows = n;
|
||||||
|
columns = 0;
|
||||||
|
Allocate(n);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGCoefficient::~FGCoefficient(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGCoefficient::Allocate(int r, int c)
|
||||||
|
{
|
||||||
|
rows = r;
|
||||||
|
columns = c;
|
||||||
|
Table3D = new float*[r+1];
|
||||||
|
for (int i=0;i<=r;i++) Table3D[i] = new float[c+1];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGCoefficient::Allocate(int n)
|
||||||
|
{
|
||||||
|
rows = n;
|
||||||
|
columns = 0;
|
||||||
|
Table2D = new float[n+1];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float FGCoefficient::Value(float rVal, float cVal)
|
||||||
|
{
|
||||||
|
float rFactor, cFactor, col1temp, col2temp, Value;
|
||||||
|
int r, c, midx;
|
||||||
|
|
||||||
|
if (rows < 2 || columns < 2) return 0.0;
|
||||||
|
|
||||||
|
for (r=1;r<=rows;r++) if (Table3D[r][0] >= rVal) break;
|
||||||
|
for (c=1;c<=columns;c++) if (Table3D[0][c] >= cVal) break;
|
||||||
|
|
||||||
|
c = c < 2 ? 2 : (c > columns ? columns : c);
|
||||||
|
r = r < 2 ? 2 : (r > rows ? rows : r);
|
||||||
|
|
||||||
|
rFactor = (rVal - Table3D[r-1][0]) / (Table3D[r][0] - Table3D[r-1][0]);
|
||||||
|
cFactor = (cVal - Table3D[0][c-1]) / (Table3D[0][c] - Table3D[0][c-1]);
|
||||||
|
|
||||||
|
col1temp = rFactor*(Table3D[r][c-1] - Table3D[r-1][c-1]) + Table3D[r-1][c-1];
|
||||||
|
col2temp = rFactor*(Table3D[r][c] - Table3D[r-1][c]) + Table3D[r-1][c];
|
||||||
|
|
||||||
|
Value = col1temp + cFactor*(col2temp - col1temp);
|
||||||
|
|
||||||
|
for (midx=0;midx<mult_count;midx++) {
|
||||||
|
Value *= GetCoeffVal(mult_idx[midx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float FGCoefficient::Value(float Val)
|
||||||
|
{
|
||||||
|
float Factor, Value;
|
||||||
|
int r, midx;
|
||||||
|
|
||||||
|
if (rows < 2) return 0.0;
|
||||||
|
|
||||||
|
for (r=1;r<=rows;r++) if (Table3D[r][0] >= Val) break;
|
||||||
|
r = r < 2 ? 2 : (r > rows ? rows : r);
|
||||||
|
|
||||||
|
// make sure denominator below does not go to zero.
|
||||||
|
if (Table3D[r][0] != Table3D[r-1][0]) {
|
||||||
|
Factor = (Val - Table3D[r-1][0]) / (Table3D[r][0] - Table3D[r-1][0]);
|
||||||
|
} else {
|
||||||
|
Factor = 1.0;
|
||||||
|
}
|
||||||
|
Value = Factor*(Table3D[r][1] - Table3D[r-1][1]) + Table3D[r-1][1];
|
||||||
|
|
||||||
|
for (midx=0;midx<mult_count;midx++) {
|
||||||
|
Value *= GetCoeffVal(mult_idx[midx]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float FGCoefficient::Value()
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case 0:
|
||||||
|
return -1;
|
||||||
|
case 1:
|
||||||
|
return (StaticValue);
|
||||||
|
case 2:
|
||||||
|
return (Value(GetCoeffVal(LookupR)));
|
||||||
|
case 3:
|
||||||
|
return (Value(GetCoeffVal(LookupR),GetCoeffVal(LookupC)));
|
||||||
|
case 4:
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float FGCoefficient::GetCoeffVal(int val_idx)
|
||||||
|
{
|
||||||
|
switch(val_idx) {
|
||||||
|
case FG_QBAR:
|
||||||
|
return State->Getqbar();
|
||||||
|
case FG_WINGAREA:
|
||||||
|
return Aircraft->GetWingArea();
|
||||||
|
case FG_WINGSPAN:
|
||||||
|
return Aircraft->GetWingSpan();
|
||||||
|
case FG_CBAR:
|
||||||
|
return Aircraft->Getcbar();
|
||||||
|
case FG_ALPHA:
|
||||||
|
return State->Getalpha();
|
||||||
|
case FG_ALPHADOT:
|
||||||
|
return State->Getadot();
|
||||||
|
case FG_BETA:
|
||||||
|
return State->Getbeta();
|
||||||
|
case FG_BETADOT:
|
||||||
|
return State->Getbdot();
|
||||||
|
case FG_PITCHRATE:
|
||||||
|
return State->GetQ();
|
||||||
|
case FG_ROLLRATE:
|
||||||
|
return State->GetP();
|
||||||
|
case FG_YAWRATE:
|
||||||
|
return State->GetR();
|
||||||
|
case FG_ELEVATOR:
|
||||||
|
return FCS->GetDe();
|
||||||
|
case FG_AILERON:
|
||||||
|
return FCS->GetDa();
|
||||||
|
case FG_RUDDER:
|
||||||
|
return FCS->GetDr();
|
||||||
|
case FG_MACH:
|
||||||
|
return State->GetMach();
|
||||||
|
case FG_ALTITUDE:
|
||||||
|
return State->Geth();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
104
JSBsim/FGCoefficient.h
Normal file
104
JSBsim/FGCoefficient.h
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGCoefficient.h
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 12/28/98
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/28/98 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGCOEFFICIENT_H
|
||||||
|
#define FGCOEFFICIENT_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
#include <fstream.h>
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
DEFINES
|
||||||
|
*******************************************************************************/
|
||||||
|
#define FG_QBAR 1
|
||||||
|
#define FG_WINGAREA 2
|
||||||
|
#define FG_WINGSPAN 4
|
||||||
|
#define FG_CBAR 8
|
||||||
|
#define FG_ALPHA 16
|
||||||
|
#define FG_ALPHADOT 32
|
||||||
|
#define FG_BETA 64
|
||||||
|
#define FG_BETADOT 128
|
||||||
|
#define FG_PITCHRATE 256
|
||||||
|
#define FG_ROLLRATE 512
|
||||||
|
#define FG_YAWRATE 1024
|
||||||
|
#define FG_ELEVATOR 2048
|
||||||
|
#define FG_AILERON 4096
|
||||||
|
#define FG_RUDDER 8192
|
||||||
|
#define FG_MACH 16384
|
||||||
|
#define FG_ALTITUDE 32768L
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGCoefficient
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGCoefficient(void);
|
||||||
|
FGCoefficient(int, int);
|
||||||
|
FGCoefficient(int);
|
||||||
|
FGCoefficient(char*);
|
||||||
|
~FGCoefficient(void);
|
||||||
|
|
||||||
|
bool Allocate(int);
|
||||||
|
bool Allocate(int, int);
|
||||||
|
|
||||||
|
float Value(float, float);
|
||||||
|
float Value(float);
|
||||||
|
float Value(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
float StaticValue;
|
||||||
|
float *Table2D;
|
||||||
|
float **Table3D;
|
||||||
|
int rows, columns;
|
||||||
|
char filename[50];
|
||||||
|
char description[50];
|
||||||
|
char name[10];
|
||||||
|
int type;
|
||||||
|
char method[15];
|
||||||
|
int multipliers;
|
||||||
|
long int mult_idx[10];
|
||||||
|
int mult_count;
|
||||||
|
float LookupR, LookupC;
|
||||||
|
|
||||||
|
float GetCoeffVal(int);
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
152
JSBsim/FGEngine.cpp
Normal file
152
JSBsim/FGEngine.cpp
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGEngine.cpp
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 01/21/99
|
||||||
|
Called by: FGAircraft
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
See header file.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
01/21/99 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGEngine.h"
|
||||||
|
#include "FGState.h"
|
||||||
|
#include "FGFCS.h"
|
||||||
|
#include <fstream.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
FGEngine::FGEngine(char *engineName)
|
||||||
|
{
|
||||||
|
char fullpath[250];
|
||||||
|
char tag[220];
|
||||||
|
|
||||||
|
strcpy(Name, engineName);
|
||||||
|
sprintf(fullpath,"/h/curt/projects/FlightGear/Simulator/FDM/JSBsim/engine/%s.dat", engineName);
|
||||||
|
ifstream enginefile(fullpath);
|
||||||
|
|
||||||
|
if (enginefile) {
|
||||||
|
enginefile >> tag;
|
||||||
|
if (strstr(tag,"ROCKET")) Type = 0;
|
||||||
|
else if (strstr(tag,"PISTON")) Type = 1;
|
||||||
|
else if (strstr(tag,"TURBOPROP")) Type = 2;
|
||||||
|
else if (strstr(tag,"TURBOJET")) Type = 3;
|
||||||
|
else Type = 0;
|
||||||
|
enginefile >> X;
|
||||||
|
enginefile >> Y;
|
||||||
|
enginefile >> Z;
|
||||||
|
enginefile >> SLThrustMax;
|
||||||
|
enginefile >> VacThrustMax;
|
||||||
|
enginefile >> MaxThrottle;
|
||||||
|
enginefile >> MinThrottle;
|
||||||
|
enginefile >> SLFuelFlowMax;
|
||||||
|
if (Type == 0)
|
||||||
|
enginefile >> SLOxiFlowMax;
|
||||||
|
enginefile.close();
|
||||||
|
} else {
|
||||||
|
cerr << "Unable to open engine definition file " << engineName << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
Thrust = 0.0;
|
||||||
|
Starved = Flameout = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGEngine::~FGEngine(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float FGEngine::CalcRocketThrust(void)
|
||||||
|
{
|
||||||
|
float lastThrust;
|
||||||
|
|
||||||
|
Throttle = FCS->GetThrottle();
|
||||||
|
lastThrust = Thrust; // last actual thrust
|
||||||
|
|
||||||
|
if (Throttle < MinThrottle || Starved) {
|
||||||
|
PctPower = Thrust = 0.0; // desired thrust
|
||||||
|
Flameout = true;
|
||||||
|
} else {
|
||||||
|
PctPower = Throttle / MaxThrottle;
|
||||||
|
Thrust = PctPower*((1.0 - State->Getrho() / 0.002378)*(VacThrustMax - SLThrustMax) +
|
||||||
|
SLThrustMax); // desired thrust
|
||||||
|
Flameout = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Thrust += 0.8*(Thrust - lastThrust); // actual thrust
|
||||||
|
|
||||||
|
return Thrust;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float FGEngine::CalcPistonThrust(void)
|
||||||
|
{
|
||||||
|
return Thrust;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float FGEngine::CalcThrust(void)
|
||||||
|
{
|
||||||
|
switch(Type) {
|
||||||
|
case 0: // Rocket
|
||||||
|
return CalcRocketThrust();
|
||||||
|
break;
|
||||||
|
case 1: // Piston
|
||||||
|
return CalcPistonThrust();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return 9999.0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
float FGEngine::CalcFuelNeed() {
|
||||||
|
FuelNeed = SLFuelFlowMax*PctPower;
|
||||||
|
return FuelNeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float FGEngine::CalcOxidizerNeed() {
|
||||||
|
OxidizerNeed = SLOxiFlowMax*PctPower;
|
||||||
|
return OxidizerNeed;
|
||||||
|
}
|
||||||
|
|
103
JSBsim/FGEngine.h
Normal file
103
JSBsim/FGEngine.h
Normal file
|
@ -0,0 +1,103 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGEngine.h
|
||||||
|
Author: Jon S. Berndt
|
||||||
|
Date started: 01/21/99
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Based on Flightgear code, which is based on LaRCSim. This class simulates
|
||||||
|
a generic engine.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
01/21/99 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGEngine_H
|
||||||
|
#define FGEngine_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
DEFINES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGEngine
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGEngine(void);
|
||||||
|
FGEngine(char*);
|
||||||
|
~FGEngine(void);
|
||||||
|
|
||||||
|
float GetThrust(void) {return Thrust;}
|
||||||
|
bool GetStarved(void) {return Starved;}
|
||||||
|
bool GetFlameout(void) {return Flameout;}
|
||||||
|
float GetThrottle(void) {return Throttle;}
|
||||||
|
char* GetName() {return Name;}
|
||||||
|
|
||||||
|
void SetStarved(bool tt) {Starved = tt;}
|
||||||
|
void SetStarved(void) {Starved = true;}
|
||||||
|
|
||||||
|
int GetType(void) {return Type;}
|
||||||
|
|
||||||
|
float CalcThrust(void);
|
||||||
|
float CalcFuelNeed(void);
|
||||||
|
float CalcOxidizerNeed(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
char Name[30];
|
||||||
|
float X, Y, Z;
|
||||||
|
int Type;
|
||||||
|
float SLThrustMax;
|
||||||
|
float VacThrustMax;
|
||||||
|
float SLFuelFlowMax;
|
||||||
|
float SLOxiFlowMax;
|
||||||
|
float MaxThrottle;
|
||||||
|
float MinThrottle;
|
||||||
|
|
||||||
|
float Thrust;
|
||||||
|
float Throttle;
|
||||||
|
float FuelNeed, OxidizerNeed;
|
||||||
|
bool Starved;
|
||||||
|
bool Flameout;
|
||||||
|
float PctPower;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
float CalcRocketThrust(void);
|
||||||
|
float CalcPistonThrust(void);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
69
JSBsim/FGFCS.cpp
Normal file
69
JSBsim/FGFCS.cpp
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGFCS.cpp
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 12/12/98
|
||||||
|
Purpose: Model the flight controls
|
||||||
|
Called by: FDMExec
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
This class models the flight controls for a specific airplane
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/12/98 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGFCS.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
FGFCS::FGFCS(void) : FGModel()
|
||||||
|
{
|
||||||
|
strcpy(Name, "FGFCS");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGFCS::~FGFCS(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGFCS::Run(void)
|
||||||
|
{
|
||||||
|
if (!FGModel::Run()) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
85
JSBsim/FGFCS.h
Normal file
85
JSBsim/FGFCS.h
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGGFCS.h
|
||||||
|
Author: Jon S. Berndt
|
||||||
|
Date started: 12/12/98
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/12/98 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGFCS_H
|
||||||
|
#define FGFCS_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGModel.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
class FGFCS : public FGModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGFCS(void);
|
||||||
|
~FGFCS(void);
|
||||||
|
|
||||||
|
bool Run(void);
|
||||||
|
|
||||||
|
inline float GetDa(void) {return Da;}
|
||||||
|
inline float GetDe(void) {return De;}
|
||||||
|
inline float GetDr(void) {return Dr;}
|
||||||
|
inline float GetDf(void) {return Df;}
|
||||||
|
inline float GetDs(void) {return Ds;}
|
||||||
|
inline float GetThrottle(void) {return Throttle;}
|
||||||
|
|
||||||
|
inline void SetDa(float tt) {Da = tt;}
|
||||||
|
inline void SetDe(float tt) {De = tt;}
|
||||||
|
inline void SetDr(float tt) {Dr = tt;}
|
||||||
|
inline void SetDf(float tt) {Df = tt;}
|
||||||
|
inline void SetDs(float tt) {Ds = tt;}
|
||||||
|
inline void SetThrottle(float tt) {Throttle = tt;}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
float Da, De, Dr, Df, Ds;
|
||||||
|
float Throttle;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef FDM_MAIN
|
||||||
|
extern FGFCS* FCS;
|
||||||
|
#else
|
||||||
|
FGFCS* FCS;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
132
JSBsim/FGFDMExec.cpp
Normal file
132
JSBsim/FGFDMExec.cpp
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGFDMExec.cpp
|
||||||
|
Author: Jon S. Berndt
|
||||||
|
Date started: 11/17/98
|
||||||
|
Purpose: Schedules and runs the model routines.
|
||||||
|
Called by: The GUI.
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This class wraps up the simulation scheduling routines.
|
||||||
|
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
11/17/98 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGFDMExec.h"
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <iostream.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
|
||||||
|
FGFDMExec::FGFDMExec(void)
|
||||||
|
{
|
||||||
|
FirstModel = 0L;
|
||||||
|
|
||||||
|
State = new FGState();
|
||||||
|
Atmosphere = new FGAtmosphere();
|
||||||
|
FCS = new FGFCS();
|
||||||
|
Aircraft = new FGAircraft();
|
||||||
|
Translation = new FGTranslation();
|
||||||
|
Rotation = new FGRotation();
|
||||||
|
Position = new FGPosition();
|
||||||
|
Auxiliary = new FGAuxiliary();
|
||||||
|
Output = new FGOutput();
|
||||||
|
|
||||||
|
Schedule(Atmosphere, 5);
|
||||||
|
Schedule(FCS, 1);
|
||||||
|
Schedule(Aircraft, 1);
|
||||||
|
Schedule(Rotation, 1);
|
||||||
|
Schedule(Translation, 1);
|
||||||
|
Schedule(Position, 1);
|
||||||
|
Schedule(Auxiliary, 1);
|
||||||
|
Schedule(Output, 5);
|
||||||
|
|
||||||
|
terminate = false;
|
||||||
|
freeze = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGFDMExec::~FGFDMExec(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int FGFDMExec::Schedule(FGModel* model, int rate)
|
||||||
|
{
|
||||||
|
FGModel* model_iterator;
|
||||||
|
|
||||||
|
model_iterator = FirstModel;
|
||||||
|
|
||||||
|
if (model_iterator == 0L) { // this is the first model
|
||||||
|
|
||||||
|
FirstModel = model;
|
||||||
|
FirstModel->NextModel = 0L;
|
||||||
|
FirstModel->SetRate(rate);
|
||||||
|
|
||||||
|
} else { // subsequent model
|
||||||
|
|
||||||
|
while (model_iterator->NextModel != 0L) {
|
||||||
|
model_iterator = model_iterator->NextModel;
|
||||||
|
}
|
||||||
|
model_iterator->NextModel = model;
|
||||||
|
model_iterator->NextModel->SetRate(rate);
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGFDMExec::Run(void)
|
||||||
|
{
|
||||||
|
FGModel* model_iterator;
|
||||||
|
|
||||||
|
model_iterator = FirstModel;
|
||||||
|
if (model_iterator == 0L) return false;
|
||||||
|
|
||||||
|
while (!model_iterator->Run())
|
||||||
|
{
|
||||||
|
model_iterator = model_iterator->NextModel;
|
||||||
|
if (model_iterator == 0L) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
84
JSBsim/FGFDMExec.h
Normal file
84
JSBsim/FGFDMExec.h
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGFDMExec.h
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 11/17/98
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
11/17/98 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGFDMEXEC_HEADER_H
|
||||||
|
#define FGFDMEXEC_HEADER_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGModel.h"
|
||||||
|
#include "FGAtmosphere.h"
|
||||||
|
#include "FGFCS.h"
|
||||||
|
#include "FGAircraft.h"
|
||||||
|
#include "FGTranslation.h"
|
||||||
|
#include "FGRotation.h"
|
||||||
|
#include "FGPosition.h"
|
||||||
|
#include "FGAuxiliary.h"
|
||||||
|
#include "FGOutput.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGFDMExec
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGFDMExec::FGFDMExec(void);
|
||||||
|
FGFDMExec::~FGFDMExec(void);
|
||||||
|
|
||||||
|
FGModel* FirstModel;
|
||||||
|
|
||||||
|
bool Initialize(void);
|
||||||
|
int Schedule(FGModel* model, int rate);
|
||||||
|
bool Run(void);
|
||||||
|
bool Freeze(void);
|
||||||
|
bool Resume(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool freeze;
|
||||||
|
bool terminate;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef FDM_MAIN
|
||||||
|
extern FGFDMExec* FDMExec;
|
||||||
|
#else
|
||||||
|
FGFDMExec* FDMExec;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
32
JSBsim/FGMain.cpp
Normal file
32
JSBsim/FGMain.cpp
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
#define FDM_MAIN
|
||||||
|
#include "FGFDMExec.h"
|
||||||
|
#undef FDM_MAIN
|
||||||
|
|
||||||
|
#include <iostream.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
void main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
struct timespec short_wait = {0,100000000};
|
||||||
|
struct timespec no_wait = {0,100000000};
|
||||||
|
|
||||||
|
if (argc != 3) {
|
||||||
|
cout << endl
|
||||||
|
<< " You must enter the name of a registered aircraft and reset point:"
|
||||||
|
<< endl << endl << " FDM <aircraft name> <reset file>" << endl;
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
FDMExec = new FGFDMExec();
|
||||||
|
|
||||||
|
Aircraft->LoadAircraft(argv[1]);
|
||||||
|
State->Reset(argv[2]);
|
||||||
|
|
||||||
|
while (State->Setsim_time(State->Getsim_time() + 0.1) <= 25.0)
|
||||||
|
{
|
||||||
|
FDMExec->Run();
|
||||||
|
nanosleep(&short_wait,&no_wait);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete FDMExec;
|
||||||
|
}
|
74
JSBsim/FGModel.cpp
Normal file
74
JSBsim/FGModel.cpp
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGModel.cpp
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 11/11/98
|
||||||
|
Purpose: Base class for all models
|
||||||
|
Called by: FGSimExec, et. al.
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
This base class for the FGAero, FGRotational, etc. classes defines methods
|
||||||
|
common to all models.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGModel.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
FGModel::FGModel()
|
||||||
|
{
|
||||||
|
NextModel = 0L;
|
||||||
|
exe_ctr = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGModel::~FGModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGModel::Run()
|
||||||
|
{
|
||||||
|
if (exe_ctr == 1) {
|
||||||
|
if (exe_ctr++ >= rate) exe_ctr = 1;
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
if (exe_ctr++ >= rate) exe_ctr = 1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
75
JSBsim/FGModel.h
Normal file
75
JSBsim/FGModel.h
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGModel.h
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 11/21/98
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
11/22/98 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGMODEL_H
|
||||||
|
#define FGMODEL_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <iostream.h>
|
||||||
|
#include "FGState.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
DEFINES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGModel(void);
|
||||||
|
~FGModel(void);
|
||||||
|
|
||||||
|
FGModel* NextModel;
|
||||||
|
char Name[30];
|
||||||
|
virtual bool Run(void);
|
||||||
|
void SetRate(int tt) {rate = tt;};
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int exe_ctr;
|
||||||
|
int rate;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
219
JSBsim/FGOutput.cpp
Normal file
219
JSBsim/FGOutput.cpp
Normal file
|
@ -0,0 +1,219 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGOutput.cpp
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 12/02/98
|
||||||
|
Purpose: Manage output of sim parameters to file or stdout
|
||||||
|
Called by: FGSimExec
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
This is the place where you create output routines to dump data for perusal
|
||||||
|
later. Some machines may not support the ncurses console output. Borland is one
|
||||||
|
of those environments which does not, so the ncurses stuff is commented out.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/02/98 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*
|
||||||
|
#if !defined( __BORLANDC__ )
|
||||||
|
# define HAVE_NCURSES
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "FGOutput.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <iostream.h>
|
||||||
|
|
||||||
|
#ifndef HAVE_NCURSES
|
||||||
|
#include "FGPosition.h"
|
||||||
|
#else
|
||||||
|
#include <ncurses.h>
|
||||||
|
#include "FGPosition.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
FGOutput::FGOutput(void) : FGModel()
|
||||||
|
{
|
||||||
|
strcpy(Name, "FGOutput");
|
||||||
|
FirstPass = true;
|
||||||
|
#ifdef HAVE_NCURSES
|
||||||
|
initscr();
|
||||||
|
cbreak();
|
||||||
|
noecho();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGOutput::~FGOutput(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGOutput::Run(void)
|
||||||
|
{
|
||||||
|
if (!FGModel::Run()) {
|
||||||
|
DelimitedOutput();
|
||||||
|
// ConsoleOutput();
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGOutput::ConsoleOutput(void)
|
||||||
|
{
|
||||||
|
char buffer[20];
|
||||||
|
|
||||||
|
#ifdef HAVE_NCURSES
|
||||||
|
clear();
|
||||||
|
move(1,1); insstr("Quaternions");
|
||||||
|
move(2,5); insstr("Q0");
|
||||||
|
move(2,16); insstr("Q1");
|
||||||
|
move(2,27); insstr("Q2");
|
||||||
|
move(2,38); insstr("Q3");
|
||||||
|
|
||||||
|
move(3,1); sprintf(buffer,"%4.4f",State->GetQ0()); insstr(buffer);
|
||||||
|
move(3,12); sprintf(buffer,"%4.4f",State->GetQ1()); insstr(buffer);
|
||||||
|
move(3,23); sprintf(buffer,"%4.4f",State->GetQ2()); insstr(buffer);
|
||||||
|
move(3,34); sprintf(buffer,"%4.4f",State->GetQ3()); insstr(buffer);
|
||||||
|
|
||||||
|
move(0,0); insstr("Time: ");
|
||||||
|
move(0,6); insstr(gcvt(State->Getsim_time(),6,buffer));
|
||||||
|
|
||||||
|
move(2,46); insstr("Phi");
|
||||||
|
move(2,55); insstr("Tht");
|
||||||
|
move(2,64); insstr("Psi");
|
||||||
|
|
||||||
|
move(3,45); sprintf(buffer,"%3.3f",State->Getphi()); insstr(buffer);
|
||||||
|
move(3,54); sprintf(buffer,"%3.3f",State->Gettht()); insstr(buffer);
|
||||||
|
move(3,63); sprintf(buffer,"%3.3f",State->Getpsi()); insstr(buffer);
|
||||||
|
|
||||||
|
move(5,47); insstr("U");
|
||||||
|
move(5,56); insstr("V");
|
||||||
|
move(5,65); insstr("W");
|
||||||
|
|
||||||
|
move(6,45); sprintf(buffer,"%5.2f",State->GetU()); insstr(buffer);
|
||||||
|
move(6,54); sprintf(buffer,"%5.2f",State->GetV()); insstr(buffer);
|
||||||
|
move(6,63); sprintf(buffer,"%5.2f",State->GetW()); insstr(buffer);
|
||||||
|
|
||||||
|
move(8,47); insstr("Fx");
|
||||||
|
move(8,56); insstr("Fy");
|
||||||
|
move(8,65); insstr("Fz");
|
||||||
|
|
||||||
|
move(9,45); sprintf(buffer,"%5.2f",State->GetFx()); insstr(buffer);
|
||||||
|
move(9,54); sprintf(buffer,"%5.2f",State->GetFy()); insstr(buffer);
|
||||||
|
move(9,63); sprintf(buffer,"%5.2f",State->GetFz()); insstr(buffer);
|
||||||
|
|
||||||
|
move(11,47); insstr("Fn");
|
||||||
|
move(11,56); insstr("Fe");
|
||||||
|
move(11,65); insstr("Fd");
|
||||||
|
|
||||||
|
move(12,45); sprintf(buffer,"%5.2f",Position->GetFn()); insstr(buffer);
|
||||||
|
move(12,54); sprintf(buffer,"%5.2f",Position->GetFe()); insstr(buffer);
|
||||||
|
move(12,63); sprintf(buffer,"%5.2f",Position->GetFd()); insstr(buffer);
|
||||||
|
|
||||||
|
move(14,47); insstr("Latitude");
|
||||||
|
move(14,57); insstr("Longitude");
|
||||||
|
move(14,67); insstr("Altitude");
|
||||||
|
|
||||||
|
move(15,47); sprintf(buffer,"%5.2f",State->Getlatitude()); insstr(buffer);
|
||||||
|
move(15,57); sprintf(buffer,"%5.2f",State->Getlongitude()); insstr(buffer);
|
||||||
|
move(15,67); sprintf(buffer,"%5.2f",State->Geth()); insstr(buffer);
|
||||||
|
|
||||||
|
refresh();
|
||||||
|
|
||||||
|
move(LINES-1,1);
|
||||||
|
refresh();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGOutput::DelimitedOutput(void)
|
||||||
|
{
|
||||||
|
if (FirstPass) {
|
||||||
|
cout << "Time,";
|
||||||
|
cout << "Altitude,";
|
||||||
|
cout << "Phi,";
|
||||||
|
cout << "Tht,";
|
||||||
|
cout << "Psi,";
|
||||||
|
cout << "Rho,";
|
||||||
|
cout << "Vtotal,";
|
||||||
|
cout << "U,";
|
||||||
|
cout << "V,";
|
||||||
|
cout << "W,";
|
||||||
|
cout << "Vn,";
|
||||||
|
cout << "Ve,";
|
||||||
|
cout << "Vd,";
|
||||||
|
cout << "Udot,";
|
||||||
|
cout << "Vdot,";
|
||||||
|
cout << "Wdot,";
|
||||||
|
cout << "Fx,";
|
||||||
|
cout << "Fy,";
|
||||||
|
cout << "Fz,";
|
||||||
|
cout << "Latitude,";
|
||||||
|
cout << "Longitude,";
|
||||||
|
cout << "QBar,";
|
||||||
|
cout << "Alpha";
|
||||||
|
cout << endl;
|
||||||
|
FirstPass = false;
|
||||||
|
} else {
|
||||||
|
cout << State->Getsim_time() << ",";
|
||||||
|
cout << State->Geth() << ",";
|
||||||
|
cout << State->Getphi() << ",";
|
||||||
|
cout << State->Gettht() << ",";
|
||||||
|
cout << State->Getpsi() << ",";
|
||||||
|
cout << State->Getrho() << ",";
|
||||||
|
cout << State->GetVt() << ",";
|
||||||
|
cout << State->GetU() << ",";
|
||||||
|
cout << State->GetV() << ",";
|
||||||
|
cout << State->GetW() << ",";
|
||||||
|
cout << State->GetVn() << ",";
|
||||||
|
cout << State->GetVe() << ",";
|
||||||
|
cout << State->GetVd() << ",";
|
||||||
|
cout << State->GetUdot() << ",";
|
||||||
|
cout << State->GetVdot() << ",";
|
||||||
|
cout << State->GetWdot() << ",";
|
||||||
|
cout << State->GetFx() << ",";
|
||||||
|
cout << State->GetFy() << ",";
|
||||||
|
cout << State->GetFz() << ",";
|
||||||
|
cout << State->Getlatitude() << ",";
|
||||||
|
cout << State->Getlongitude() << ",";
|
||||||
|
cout << State->Getqbar() << ",";
|
||||||
|
cout << State->Getalpha() << "";
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
}
|
72
JSBsim/FGOutput.h
Normal file
72
JSBsim/FGOutput.h
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGOutput.h
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 12/2/98
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/02/98 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGOUTPUT_H
|
||||||
|
#define FGOUTPUT_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGModel.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGOutput : public FGModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGOutput(void);
|
||||||
|
~FGOutput(void);
|
||||||
|
bool Run(void);
|
||||||
|
void ConsoleOutput(void);
|
||||||
|
void DelimitedOutput(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool FirstPass;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef FDM_MAIN
|
||||||
|
extern FGOutput* Output;
|
||||||
|
#else
|
||||||
|
FGOutput* Output;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
||||||
|
|
183
JSBsim/FGPosition.cpp
Normal file
183
JSBsim/FGPosition.cpp
Normal file
|
@ -0,0 +1,183 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGPosition.cpp
|
||||||
|
Author: Jon S. Berndt
|
||||||
|
Date started: 01/05/99
|
||||||
|
Purpose: Integrate the EOM to determine instantaneous position
|
||||||
|
Called by: FGFDMExec
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
This class encapsulates the integration of rates and accelerations to get the
|
||||||
|
current position of the aircraft.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
None
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
01/05/99 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
COMMENTS, REFERENCES, and NOTES
|
||||||
|
********************************************************************************
|
||||||
|
[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
|
||||||
|
Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
|
||||||
|
School, January 1994
|
||||||
|
[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
|
||||||
|
JSC 12960, July 1977
|
||||||
|
[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
|
||||||
|
NASA-Ames", NASA CR-2497, January 1975
|
||||||
|
[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
|
||||||
|
Wiley & Sons, 1979 ISBN 0-471-03032-5
|
||||||
|
[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
|
||||||
|
1982 ISBN 0-471-08936-2
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGPosition.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
FGPosition::FGPosition(void) : FGModel()
|
||||||
|
{
|
||||||
|
strcpy(Name, "FGPosition");
|
||||||
|
EarthRad = 20898908.00; // feet
|
||||||
|
OmegaEarth = 7.2685E-3; // rad/sec
|
||||||
|
AccelN = AccelE = AccelD = 0.0;
|
||||||
|
LongitudeDot = LatitudeDot = RadiusDot = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGPosition::~FGPosition(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGPosition:: Run(void)
|
||||||
|
{
|
||||||
|
float tanLat, cosLat;
|
||||||
|
|
||||||
|
if (!FGModel::Run()) {
|
||||||
|
GetState();
|
||||||
|
T[1][1] = Q0*Q0 + Q1*Q1 - Q2*Q2 - Q3*Q3; // Page A-11
|
||||||
|
T[1][2] = 2*(Q1*Q2 + Q0*Q3); // From
|
||||||
|
T[1][3] = 2*(Q1*Q3 - Q0*Q2); // Reference [2]
|
||||||
|
T[2][1] = 2*(Q1*Q2 - Q0*Q3);
|
||||||
|
T[2][2] = Q0*Q0 - Q1*Q1 + Q2*Q2 - Q3*Q3;
|
||||||
|
T[2][3] = 2*(Q2*Q3 + Q0*Q1);
|
||||||
|
T[3][1] = 2*(Q1*Q3 + Q0*Q2);
|
||||||
|
T[3][2] = 2*(Q2*Q3 - Q0*Q1);
|
||||||
|
T[3][3] = Q0*Q0 - Q1*Q1 - Q2*Q2 + Q3*Q3;
|
||||||
|
|
||||||
|
Fn = T[1][1]*Fx + T[2][1]*Fy + T[3][1]*Fz; // Eqn. 3.5
|
||||||
|
Fe = T[1][2]*Fx + T[2][2]*Fy + T[3][2]*Fz; // From
|
||||||
|
Fd = T[1][3]*Fx + T[2][3]*Fy + T[3][3]*Fz; // Reference [3]
|
||||||
|
|
||||||
|
tanLat = tan(Latitude); // I made this up
|
||||||
|
cosLat = cos(Latitude);
|
||||||
|
|
||||||
|
lastAccelN = AccelN;
|
||||||
|
lastAccelE = AccelE;
|
||||||
|
lastAccelD = AccelD;
|
||||||
|
|
||||||
|
Vn = T[1][1]*U + T[2][1]*V + T[3][1]*W;
|
||||||
|
Ve = T[1][2]*U + T[2][2]*V + T[3][2]*W;
|
||||||
|
Vd = T[1][3]*U + T[2][3]*V + T[3][3]*W;
|
||||||
|
|
||||||
|
AccelN = invMass * Fn + invRadius * (Vn*Vd - Ve*Ve*tanLat); // Eqn. 3.6
|
||||||
|
AccelE = invMass * Fe + invRadius * (Ve*Vd + Vn*Ve*tanLat); // From
|
||||||
|
AccelD = invMass * Fd - invRadius * (Vn*Vn + Ve*Ve); // Reference [3]
|
||||||
|
|
||||||
|
Vn += 0.5*dt*(3.0*AccelN - lastAccelN); // Eqn. 3.7
|
||||||
|
Ve += 0.5*dt*(3.0*AccelE - lastAccelE); // From
|
||||||
|
Vd += 0.5*dt*(3.0*AccelD - lastAccelD); // Reference [3]
|
||||||
|
|
||||||
|
Vee = Ve - OmegaEarth * (Radius) * cosLat; // From Eq. 3.8
|
||||||
|
// Reference [3]
|
||||||
|
lastLatitudeDot = LatitudeDot;
|
||||||
|
lastLongitudeDot = LongitudeDot;
|
||||||
|
lastRadiusDot = RadiusDot;
|
||||||
|
|
||||||
|
if (cosLat != 0) LongitudeDot = Ve / (Radius * cosLat);
|
||||||
|
LatitudeDot = Vn * invRadius;
|
||||||
|
RadiusDot = -Vd;
|
||||||
|
|
||||||
|
Longitude += 0.5*dt*(LongitudeDot + lastLongitudeDot);
|
||||||
|
Latitude += 0.5*dt*(LatitudeDot + lastLatitudeDot);
|
||||||
|
Radius += 0.5*dt*(RadiusDot + lastRadiusDot);
|
||||||
|
|
||||||
|
PutState();
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGPosition::GetState(void)
|
||||||
|
{
|
||||||
|
Q0 = State->GetQ0();
|
||||||
|
Q1 = State->GetQ1();
|
||||||
|
Q2 = State->GetQ2();
|
||||||
|
Q3 = State->GetQ3();
|
||||||
|
|
||||||
|
Fx = State->GetFx();
|
||||||
|
Fy = State->GetFy();
|
||||||
|
Fz = State->GetFz();
|
||||||
|
|
||||||
|
U = State->GetU();
|
||||||
|
V = State->GetV();
|
||||||
|
W = State->GetW();
|
||||||
|
|
||||||
|
Latitude = State->Getlatitude();
|
||||||
|
Longitude = State->Getlongitude();
|
||||||
|
|
||||||
|
invMass = 1.0 / State->Getm();
|
||||||
|
invRadius = 1.0 / (State->Geth() + EarthRad);
|
||||||
|
Radius = State->Geth() + EarthRad;
|
||||||
|
dt = State->Getdt();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGPosition::PutState(void)
|
||||||
|
{
|
||||||
|
for (int r=1;r<=3;r++)
|
||||||
|
for (int c=1;c<=3;c++)
|
||||||
|
State->SetT(r,c,T[r][c]);
|
||||||
|
|
||||||
|
State->Setlatitude(Latitude);
|
||||||
|
State->Setlongitude(Longitude);
|
||||||
|
State->Seth(Radius - EarthRad);
|
||||||
|
|
||||||
|
State->SetVn(Vn); // remove after testing
|
||||||
|
State->SetVe(Ve); // remove after testing
|
||||||
|
State->SetVd(Vd); // remove after testing
|
||||||
|
}
|
||||||
|
|
91
JSBsim/FGPosition.h
Normal file
91
JSBsim/FGPosition.h
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGPosition.h
|
||||||
|
Author: Jon S. Berndt
|
||||||
|
Date started: 1/5/99
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
01/05/99 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
COMMENTS, REFERENCES, and NOTES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGPOSITION_H
|
||||||
|
#define FGPOSITION_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
#include "FGModel.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGPosition : public FGModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGPosition(void);
|
||||||
|
~FGPosition(void);
|
||||||
|
|
||||||
|
float GetFn() {return Fn;}
|
||||||
|
float GetFe() {return Fe;}
|
||||||
|
float GetFd() {return Fd;}
|
||||||
|
|
||||||
|
bool Run(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
float T[4][4];
|
||||||
|
float Q0, Q1, Q2, Q3;
|
||||||
|
float Fn, Fe, Fd;
|
||||||
|
float Fx, Fy, Fz;
|
||||||
|
float invMass, invRadius;
|
||||||
|
float EarthRad, OmegaEarth, Radius;
|
||||||
|
float AccelN, AccelE, AccelD;
|
||||||
|
float lastAccelN, lastAccelE, lastAccelD;
|
||||||
|
float LatitudeDot, LongitudeDot, RadiusDot;
|
||||||
|
float lastLatitudeDot, lastLongitudeDot, lastRadiusDot;
|
||||||
|
float Longitude, Latitude;
|
||||||
|
float U, V, W;
|
||||||
|
float Vn, Ve, Vd, Vee;
|
||||||
|
float dt;
|
||||||
|
|
||||||
|
void GetState(void);
|
||||||
|
void PutState(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef FDM_MAIN
|
||||||
|
extern FGPosition* Position;
|
||||||
|
#else
|
||||||
|
FGPosition* Position;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
191
JSBsim/FGRotation.cpp
Normal file
191
JSBsim/FGRotation.cpp
Normal file
|
@ -0,0 +1,191 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGRotation.cpp
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 12/02/98
|
||||||
|
Purpose: Integrates the rotational EOM
|
||||||
|
Called by: FGFDMExec
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
This class integrates the rotational EOM.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/02/98 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
COMMENTS, REFERENCES, and NOTES
|
||||||
|
********************************************************************************
|
||||||
|
[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
|
||||||
|
Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
|
||||||
|
School, January 1994
|
||||||
|
[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
|
||||||
|
JSC 12960, July 1977
|
||||||
|
[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
|
||||||
|
NASA-Ames", NASA CR-2497, January 1975
|
||||||
|
[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
|
||||||
|
Wiley & Sons, 1979 ISBN 0-471-03032-5
|
||||||
|
[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
|
||||||
|
1982 ISBN 0-471-08936-2
|
||||||
|
|
||||||
|
The order of rotations used in this class corresponds to a 3-2-1 sequence,
|
||||||
|
or Y-P-R, or Z-Y-X, if you prefer.
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGRotation.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
FGRotation::FGRotation(void) : FGModel()
|
||||||
|
{
|
||||||
|
strcpy(Name, "FGRotation");
|
||||||
|
Q0dot = Q1dot = Q2dot = Q3dot = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGRotation::~FGRotation(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGRotation::Run(void)
|
||||||
|
{
|
||||||
|
float L2, N1, iQtot, sum;
|
||||||
|
|
||||||
|
if (!FGModel::Run()) {
|
||||||
|
GetState();
|
||||||
|
|
||||||
|
lastPdot = Pdot;
|
||||||
|
lastQdot = Qdot;
|
||||||
|
lastRdot = Rdot;
|
||||||
|
|
||||||
|
L2 = L + Ixz*P*Q - (Izz-Iyy)*R*Q;
|
||||||
|
N1 = N - (Iyy-Ixx)*P*Q - Ixz*R*Q;
|
||||||
|
|
||||||
|
Pdot = (L2*Izz - N1*Ixz) / (Ixx*Izz - Ixz*Ixz);
|
||||||
|
Qdot = (M - (Ixx-Izz)*P*R - Ixz*(P*P - R*R))/Iyy;
|
||||||
|
Rdot = (N1*Ixx + L2*Ixz) / (Ixx*Izz - Ixz*Ixz);
|
||||||
|
|
||||||
|
P += dt*(lastPdot + Pdot)/2.0;
|
||||||
|
Q += dt*(lastQdot + Qdot)/2.0;
|
||||||
|
R += dt*(lastRdot + Rdot)/2.0;
|
||||||
|
|
||||||
|
lastQ0dot = Q0dot;
|
||||||
|
lastQ1dot = Q1dot;
|
||||||
|
lastQ2dot = Q2dot;
|
||||||
|
lastQ3dot = Q3dot;
|
||||||
|
|
||||||
|
Q0dot = -0.5*(Q1*P + Q2*Q + Q3*R);
|
||||||
|
Q1dot = 0.5*(Q0*P + Q2*R - Q3*Q);
|
||||||
|
Q2dot = 0.5*(Q0*Q + Q3*P - Q1*R);
|
||||||
|
Q3dot = 0.5*(Q0*R + Q1*Q - Q2*P);
|
||||||
|
|
||||||
|
Q0 += 0.5*dt*(lastQ0dot + Q0dot);
|
||||||
|
Q1 += 0.5*dt*(lastQ1dot + Q1dot);
|
||||||
|
Q2 += 0.5*dt*(lastQ2dot + Q2dot);
|
||||||
|
Q3 += 0.5*dt*(lastQ3dot + Q3dot);
|
||||||
|
|
||||||
|
sum = Q0*Q0 + Q1*Q1 + Q2*Q2 + Q3*Q3;
|
||||||
|
|
||||||
|
iQtot = 1.0 / sqrt(sum);
|
||||||
|
|
||||||
|
Q0 *= iQtot;
|
||||||
|
Q1 *= iQtot;
|
||||||
|
Q2 *= iQtot;
|
||||||
|
Q3 *= iQtot;
|
||||||
|
|
||||||
|
if (T[3][3] == 0)
|
||||||
|
phi = 0.0;
|
||||||
|
else
|
||||||
|
phi = atan2(T[2][3], T[3][3]);
|
||||||
|
|
||||||
|
tht = asin(-T[1][3]);
|
||||||
|
|
||||||
|
if (T[1][1] == 0.0)
|
||||||
|
psi = 0.0;
|
||||||
|
else
|
||||||
|
psi = atan2(T[1][2], T[1][1]);
|
||||||
|
|
||||||
|
if (psi < 0.0) psi += 2*M_PI;
|
||||||
|
|
||||||
|
PutState();
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGRotation::GetState(void)
|
||||||
|
{
|
||||||
|
dt = State->Getdt();
|
||||||
|
P = State->GetP();
|
||||||
|
Q = State->GetQ();
|
||||||
|
R = State->GetR();
|
||||||
|
|
||||||
|
Pdot = State->GetPdot();
|
||||||
|
Qdot = State->GetQdot();
|
||||||
|
Rdot = State->GetRdot();
|
||||||
|
|
||||||
|
L = State->GetL();
|
||||||
|
M = State->GetM();
|
||||||
|
N = State->GetN();
|
||||||
|
|
||||||
|
Ixx = State->GetIxx();
|
||||||
|
Iyy = State->GetIyy();
|
||||||
|
Izz = State->GetIzz();
|
||||||
|
Ixz = State->GetIxz();
|
||||||
|
|
||||||
|
Q0 = State->GetQ0();
|
||||||
|
Q1 = State->GetQ1();
|
||||||
|
Q2 = State->GetQ2();
|
||||||
|
Q3 = State->GetQ3();
|
||||||
|
|
||||||
|
for (int r=1;r<=3;r++)
|
||||||
|
for (int c=1;c<=3;c++)
|
||||||
|
T[r][c] = State->GetT(r,c);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGRotation::PutState(void)
|
||||||
|
{
|
||||||
|
State->SetP(P);
|
||||||
|
State->SetQ(Q);
|
||||||
|
State->SetR(R);
|
||||||
|
|
||||||
|
State->Setphi(phi);
|
||||||
|
State->Settht(tht);
|
||||||
|
State->Setpsi(psi);
|
||||||
|
|
||||||
|
State->SetQ0123(Q0, Q1, Q2, Q3);
|
||||||
|
}
|
||||||
|
|
101
JSBsim/FGRotation.h
Normal file
101
JSBsim/FGRotation.h
Normal file
|
@ -0,0 +1,101 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGRotation.h
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 12/02/98
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/02/98 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
COMMENTS, REFERENCES, and NOTES
|
||||||
|
********************************************************************************
|
||||||
|
[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
|
||||||
|
Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
|
||||||
|
School, January 1994
|
||||||
|
[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
|
||||||
|
JSC 12960, July 1977
|
||||||
|
[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
|
||||||
|
NASA-Ames", NASA CR-2497, January 1975
|
||||||
|
[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
|
||||||
|
Wiley & Sons, 1979 ISBN 0-471-03032-5
|
||||||
|
[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
|
||||||
|
1982 ISBN 0-471-08936-2
|
||||||
|
|
||||||
|
The order of rotations used in this class corresponds to a 3-2-1 sequence,
|
||||||
|
or Y-P-R, or Z-Y-X, if you prefer.
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGROTATION_H
|
||||||
|
#define FGROTATION_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGModel.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGRotation : public FGModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGRotation(void);
|
||||||
|
~FGRotation(void);
|
||||||
|
|
||||||
|
bool Run(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
float P, Q, R;
|
||||||
|
float L, M, N;
|
||||||
|
float Ixx, Iyy, Izz, Ixz;
|
||||||
|
float Q0, Q1, Q2, Q3;
|
||||||
|
float phi, tht, psi;
|
||||||
|
float Pdot, Qdot, Rdot;
|
||||||
|
float Q0dot, Q1dot, Q2dot, Q3dot;
|
||||||
|
float lastPdot, lastQdot, lastRdot;
|
||||||
|
float lastQ0dot, lastQ1dot, lastQ2dot, lastQ3dot;
|
||||||
|
float dt;
|
||||||
|
float T[4][4];
|
||||||
|
|
||||||
|
void GetState(void);
|
||||||
|
void PutState(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef FDM_MAIN
|
||||||
|
extern FGRotation* Rotation;
|
||||||
|
#else
|
||||||
|
FGRotation* Rotation;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
286
JSBsim/FGState.cpp
Normal file
286
JSBsim/FGState.cpp
Normal file
|
@ -0,0 +1,286 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGState.cpp
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 11/17/98
|
||||||
|
Called by: FGFDMExec and accessed by all models.
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
See header file.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
11/17/98 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGState.h"
|
||||||
|
#include "FGAircraft.h"
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
FGState::FGState(void)
|
||||||
|
{
|
||||||
|
U = V = W = Fx = Fy = Fz = 0.0;
|
||||||
|
P = Q = R = L = M = N = 0.0;
|
||||||
|
Q0 = Q1 = Q2 = Q3 = 0.0;
|
||||||
|
Ixx = Iyy = Izz = Ixz = 0.0;
|
||||||
|
Vt = 0.0;
|
||||||
|
latitude = longitude = 0.0;
|
||||||
|
alpha = beta = gamma = 0.0;
|
||||||
|
adot = bdot = 0.0;
|
||||||
|
phi = tht = psi = 0.0;
|
||||||
|
Udot = Vdot = Wdot = 0.0;
|
||||||
|
Pdot = Qdot = Rdot = 0.0;
|
||||||
|
h = 0.0;
|
||||||
|
a = 1000.0;
|
||||||
|
rho = qbar = 0.0;
|
||||||
|
sim_time = dt = 0.1;
|
||||||
|
m = 0.0;
|
||||||
|
g = 32.174;
|
||||||
|
|
||||||
|
const float EarthRad = 20925650.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGState::~FGState(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGState::Reset(char* fname)
|
||||||
|
{
|
||||||
|
char resetDef[200];
|
||||||
|
|
||||||
|
sprintf(resetDef, "/h/curt/projects/FlightGear/Simulator/FDM/JSBsim/aircraft/%s/%s", Aircraft->GetAircraftName(), fname);
|
||||||
|
|
||||||
|
ifstream resetfile(resetDef);
|
||||||
|
|
||||||
|
if (resetfile) {
|
||||||
|
resetfile >> U;
|
||||||
|
resetfile >> V;
|
||||||
|
resetfile >> W;
|
||||||
|
resetfile >> latitude;
|
||||||
|
resetfile >> longitude;
|
||||||
|
resetfile >> phi;
|
||||||
|
resetfile >> tht;
|
||||||
|
resetfile >> psi;
|
||||||
|
resetfile >> h;
|
||||||
|
resetfile.close();
|
||||||
|
|
||||||
|
// Change all angular measurements from degrees (as in config file) to radians
|
||||||
|
|
||||||
|
if (W != 0.0)
|
||||||
|
alpha = U*U > 0.0 ? atan2(W, U) : 0.0;
|
||||||
|
if (V != 0.0)
|
||||||
|
beta = U*U+W*W > 0.0 ? atan2(V, (fabs(U)/U)*sqrt(U*U + W*W)) : 0.0;
|
||||||
|
|
||||||
|
latitude *= M_PI / 180.0;
|
||||||
|
longitude *= M_PI / 180.0;
|
||||||
|
alpha *= M_PI / 180.0;
|
||||||
|
beta *= M_PI / 180.0;
|
||||||
|
gamma *= M_PI / 180.0;
|
||||||
|
phi *= M_PI / 180.0;
|
||||||
|
tht *= M_PI / 180.0;
|
||||||
|
psi *= M_PI / 180.0;
|
||||||
|
|
||||||
|
Vt = sqrt(U*U + V*V + W*W);
|
||||||
|
qbar = sqrt(U*U + V*V + W*W);
|
||||||
|
|
||||||
|
Q0 = sin(psi*0.5)*sin(tht*0.5)*sin(phi*0.5) + cos(psi*0.5)*cos(tht*0.5)*cos(phi*0.5);
|
||||||
|
Q1 = -sin(psi*0.5)*sin(tht*0.5)*cos(phi*0.5) + cos(psi*0.5)*cos(tht*0.5)*sin(phi*0.5);
|
||||||
|
Q2 = sin(psi*0.5)*cos(tht*0.5)*sin(phi*0.5) + cos(psi*0.5)*sin(tht*0.5)*cos(phi*0.5);
|
||||||
|
Q3 = sin(psi*0.5)*cos(tht*0.5)*cos(phi*0.5) - cos(psi*0.5)*sin(tht*0.5)*sin(phi*0.5);
|
||||||
|
|
||||||
|
T[1][1] = Q0*Q0 + Q1*Q1 - Q2*Q2 - Q3*Q3;
|
||||||
|
T[1][2] = 2*(Q1*Q2 + Q0*Q3);
|
||||||
|
T[1][3] = 2*(Q1*Q3 - Q0*Q2);
|
||||||
|
T[2][1] = 2*(Q1*Q2 - Q0*Q3);
|
||||||
|
T[2][2] = Q0*Q0 - Q1*Q1 + Q2*Q2 - Q3*Q3;
|
||||||
|
T[2][3] = 2*(Q2*Q3 + Q0*Q1);
|
||||||
|
T[3][1] = 2*(Q1*Q3 + Q0*Q2);
|
||||||
|
T[3][2] = 2*(Q2*Q3 - Q0*Q1);
|
||||||
|
T[3][3] = Q0*Q0 - Q1*Q1 - Q2*Q2 + Q3*Q3;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
cerr << "Unable to load reset file " << fname << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGState::StoreData(char* fname)
|
||||||
|
{
|
||||||
|
ofstream datafile(fname);
|
||||||
|
|
||||||
|
if (datafile) {
|
||||||
|
datafile << U;
|
||||||
|
datafile << V;
|
||||||
|
datafile << W;
|
||||||
|
datafile << Fx;
|
||||||
|
datafile << Fy;
|
||||||
|
datafile << Fz;
|
||||||
|
datafile << P;
|
||||||
|
datafile << Q;
|
||||||
|
datafile << R;
|
||||||
|
datafile << L;
|
||||||
|
datafile << M;
|
||||||
|
datafile << N;
|
||||||
|
datafile << latitude;
|
||||||
|
datafile << longitude;
|
||||||
|
datafile << alpha;
|
||||||
|
datafile << beta;
|
||||||
|
datafile << gamma;
|
||||||
|
datafile << phi;
|
||||||
|
datafile << tht;
|
||||||
|
datafile << psi;
|
||||||
|
datafile << Udot;
|
||||||
|
datafile << Vdot;
|
||||||
|
datafile << Wdot;
|
||||||
|
datafile << Pdot;
|
||||||
|
datafile << Qdot;
|
||||||
|
datafile << Rdot;
|
||||||
|
datafile << h;
|
||||||
|
datafile << a;
|
||||||
|
datafile << rho;
|
||||||
|
datafile << qbar;
|
||||||
|
datafile << sim_time;
|
||||||
|
datafile << dt;
|
||||||
|
datafile << g;
|
||||||
|
datafile.close();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
cerr << "Could not open dump file " << fname << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGState::DumpData(char* fname)
|
||||||
|
{
|
||||||
|
ofstream datafile(fname);
|
||||||
|
|
||||||
|
if (datafile) {
|
||||||
|
datafile << "U: " << U << endl;
|
||||||
|
datafile << "V: " << V << endl;
|
||||||
|
datafile << "W: " << W << endl;
|
||||||
|
datafile << "Fx: " << Fx << endl;
|
||||||
|
datafile << "Fy: " << Fy << endl;
|
||||||
|
datafile << "Fz: " << Fz << endl;
|
||||||
|
datafile << "P: " << P << endl;
|
||||||
|
datafile << "Q: " << Q << endl;
|
||||||
|
datafile << "R: " << R << endl;
|
||||||
|
datafile << "L: " << L << endl;
|
||||||
|
datafile << "M: " << M << endl;
|
||||||
|
datafile << "N: " << N << endl;
|
||||||
|
datafile << "latitude: " << latitude << endl;
|
||||||
|
datafile << "longitude: " << longitude << endl;
|
||||||
|
datafile << "alpha: " << alpha << endl;
|
||||||
|
datafile << "beta: " << beta << endl;
|
||||||
|
datafile << "gamma: " << gamma << endl;
|
||||||
|
datafile << "phi: " << phi << endl;
|
||||||
|
datafile << "tht: " << tht << endl;
|
||||||
|
datafile << "psi: " << psi << endl;
|
||||||
|
datafile << "Udot: " << Udot << endl;
|
||||||
|
datafile << "Vdot: " << Vdot << endl;
|
||||||
|
datafile << "Wdot: " << Wdot << endl;
|
||||||
|
datafile << "Pdot: " << Pdot << endl;
|
||||||
|
datafile << "Qdot: " << Qdot << endl;
|
||||||
|
datafile << "Rdot: " << Rdot << endl;
|
||||||
|
datafile << "h: " << h << endl;
|
||||||
|
datafile << "a: " << a << endl;
|
||||||
|
datafile << "rho: " << rho << endl;
|
||||||
|
datafile << "qbar: " << qbar << endl;
|
||||||
|
datafile << "sim_time: " << sim_time << endl;
|
||||||
|
datafile << "dt: " << dt << endl;
|
||||||
|
datafile << "g: " << g << endl;
|
||||||
|
datafile << "m: " << m << endl;
|
||||||
|
datafile << "Ixx: " << Ixx << endl;
|
||||||
|
datafile << "Iyy: " << Iyy << endl;
|
||||||
|
datafile << "Izz: " << Izz << endl;
|
||||||
|
datafile << "Ixz: " << Ixz << endl;
|
||||||
|
datafile.close();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGState::DisplayData(void)
|
||||||
|
{
|
||||||
|
cout << "U: " << U << endl;
|
||||||
|
cout << "V: " << V << endl;
|
||||||
|
cout << "W: " << W << endl;
|
||||||
|
cout << "Fx: " << Fx << endl;
|
||||||
|
cout << "Fy: " << Fy << endl;
|
||||||
|
cout << "Fz: " << Fz << endl;
|
||||||
|
cout << "P: " << P << endl;
|
||||||
|
cout << "Q: " << Q << endl;
|
||||||
|
cout << "R: " << R << endl;
|
||||||
|
cout << "L: " << L << endl;
|
||||||
|
cout << "M: " << M << endl;
|
||||||
|
cout << "N: " << N << endl;
|
||||||
|
cout << "Vt: " << Vt << endl;
|
||||||
|
cout << "latitude: " << latitude << endl;
|
||||||
|
cout << "longitude: " << longitude << endl;
|
||||||
|
cout << "alpha: " << alpha << endl;
|
||||||
|
cout << "beta: " << beta << endl;
|
||||||
|
cout << "gamma: " << gamma << endl;
|
||||||
|
cout << "phi: " << phi << endl;
|
||||||
|
cout << "tht: " << tht << endl;
|
||||||
|
cout << "psi: " << psi << endl;
|
||||||
|
cout << "Udot: " << Udot << endl;
|
||||||
|
cout << "Vdot: " << Vdot << endl;
|
||||||
|
cout << "Wdot: " << Wdot << endl;
|
||||||
|
cout << "Pdot: " << Pdot << endl;
|
||||||
|
cout << "Qdot: " << Qdot << endl;
|
||||||
|
cout << "Rdot: " << Rdot << endl;
|
||||||
|
cout << "h: " << h << endl;
|
||||||
|
cout << "a: " << a << endl;
|
||||||
|
cout << "rho: " << rho << endl;
|
||||||
|
cout << "qbar: " << qbar << endl;
|
||||||
|
cout << "sim_time: " << sim_time << endl;
|
||||||
|
cout << "dt: " << dt << endl;
|
||||||
|
cout << "g: " << g << endl;
|
||||||
|
cout << "m: " << m << endl;
|
||||||
|
cout << "Ixx: " << Ixx << endl;
|
||||||
|
cout << "Iyy: " << Iyy << endl;
|
||||||
|
cout << "Izz: " << Izz << endl;
|
||||||
|
cout << "Ixz: " << Ixz << endl;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
241
JSBsim/FGState.h
Normal file
241
JSBsim/FGState.h
Normal file
|
@ -0,0 +1,241 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGState.h
|
||||||
|
Author: Jon S. Berndt
|
||||||
|
Date started: 11/17/98
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Based on Flightgear code, which is based on LaRCSim. This class wraps all
|
||||||
|
global state variables (such as velocity, position, orientation, etc.).
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
11/17/98 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGSTATE_H
|
||||||
|
#define FGSTATE_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <fstream.h>
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
DEFINES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGState
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGState(void);
|
||||||
|
~FGState(void);
|
||||||
|
|
||||||
|
bool Reset(char*);
|
||||||
|
bool StoreData(char*);
|
||||||
|
bool DumpData(char*);
|
||||||
|
bool DisplayData(void);
|
||||||
|
|
||||||
|
inline float GetU(void) {return U;}
|
||||||
|
inline float GetV(void) {return V;}
|
||||||
|
inline float GetW(void) {return W;}
|
||||||
|
|
||||||
|
inline float GetVn(void) {return Vn;}
|
||||||
|
inline float GetVe(void) {return Ve;}
|
||||||
|
inline float GetVd(void) {return Vd;}
|
||||||
|
|
||||||
|
inline float GetVt(void) {return Vt;}
|
||||||
|
|
||||||
|
inline float GetFx(void) {return Fx;}
|
||||||
|
inline float GetFy(void) {return Fy;}
|
||||||
|
inline float GetFz(void) {return Fz;}
|
||||||
|
|
||||||
|
inline float GetP(void) {return P;}
|
||||||
|
inline float GetQ(void) {return Q;}
|
||||||
|
inline float GetR(void) {return R;}
|
||||||
|
|
||||||
|
inline float GetQ0(void) {return Q0;}
|
||||||
|
inline float GetQ1(void) {return Q1;}
|
||||||
|
inline float GetQ2(void) {return Q2;}
|
||||||
|
inline float GetQ3(void) {return Q3;}
|
||||||
|
|
||||||
|
inline float GetL(void) {return L;}
|
||||||
|
inline float GetM(void) {return M;}
|
||||||
|
inline float GetN(void) {return N;}
|
||||||
|
|
||||||
|
inline float GetIxx(void) const {return Ixx;}
|
||||||
|
inline float GetIyy(void) const {return Iyy;}
|
||||||
|
inline float GetIzz(void) const {return Izz;}
|
||||||
|
inline float GetIxz(void) const {return Ixz;}
|
||||||
|
|
||||||
|
inline float Getlatitude(void) {return latitude;}
|
||||||
|
inline float Getlongitude(void) {return longitude;}
|
||||||
|
inline float GetGeodeticLat(void) {return GeodeticLat;}
|
||||||
|
|
||||||
|
inline float Getalpha(void) {return alpha;}
|
||||||
|
inline float Getbeta(void) {return beta;}
|
||||||
|
inline float Getgamma(void) {return gamma;}
|
||||||
|
|
||||||
|
inline float Getadot(void) {return adot;}
|
||||||
|
inline float Getbdot(void) {return bdot;}
|
||||||
|
|
||||||
|
inline float GetUdot(void) {return Udot;}
|
||||||
|
inline float GetVdot(void) {return Vdot;}
|
||||||
|
inline float GetWdot(void) {return Wdot;}
|
||||||
|
|
||||||
|
inline float GetPdot(void) {return Pdot;}
|
||||||
|
inline float GetQdot(void) {return Qdot;}
|
||||||
|
inline float GetRdot(void) {return Rdot;}
|
||||||
|
|
||||||
|
inline float Geth(void) {return h;}
|
||||||
|
inline float Geta(void) {return a;}
|
||||||
|
inline float GetMach(void) {return Mach;}
|
||||||
|
|
||||||
|
inline float Getrho(void) {return rho;}
|
||||||
|
inline float Getsim_time(void) {return sim_time;}
|
||||||
|
inline float Getdt(void) {return dt;}
|
||||||
|
|
||||||
|
inline float Getphi(void) {return phi;}
|
||||||
|
inline float Gettht(void) {return tht;}
|
||||||
|
inline float Getpsi(void) {return psi;}
|
||||||
|
|
||||||
|
inline float Getg(void) {return g;}
|
||||||
|
inline float Getm(void) {return m;}
|
||||||
|
|
||||||
|
inline float Getqbar(void) {return qbar;}
|
||||||
|
inline float GetT(int r, int c) {return T[r][c];}
|
||||||
|
|
||||||
|
inline void SetU(float tt) {U = tt;}
|
||||||
|
inline void SetV(float tt) {V = tt;}
|
||||||
|
inline void SetW(float tt) {W = tt;}
|
||||||
|
|
||||||
|
inline void SetVt(float tt) {Vt = tt;}
|
||||||
|
|
||||||
|
inline void SetVn(float tt) {Vn = tt;}
|
||||||
|
inline void SetVe(float tt) {Ve = tt;}
|
||||||
|
inline void SetVd(float tt) {Vd = tt;}
|
||||||
|
|
||||||
|
inline void SetFx(float tt) {Fx = tt;}
|
||||||
|
inline void SetFy(float tt) {Fy = tt;}
|
||||||
|
inline void SetFz(float tt) {Fz = tt;}
|
||||||
|
|
||||||
|
inline void SetP(float tt) {P = tt;}
|
||||||
|
inline void SetQ(float tt) {Q = tt;}
|
||||||
|
inline void SetR(float tt) {R = tt;}
|
||||||
|
|
||||||
|
inline void SetL(float tt) {L = tt;}
|
||||||
|
inline void SetM(float tt) {M = tt;}
|
||||||
|
inline void SetN(float tt) {N = tt;}
|
||||||
|
|
||||||
|
inline void SetIxx(float tt) {Ixx = tt;}
|
||||||
|
inline void SetIyy(float tt) {Iyy = tt;}
|
||||||
|
inline void SetIzz(float tt) {Izz = tt;}
|
||||||
|
inline void SetIxz(float tt) {Ixz = tt;}
|
||||||
|
|
||||||
|
inline void Setlatitude(float tt) {latitude = tt;}
|
||||||
|
inline void Setlongitude(float tt) {longitude = tt;}
|
||||||
|
inline void SetGeodeticLat(float tt) {GeodeticLat = tt;}
|
||||||
|
|
||||||
|
inline void Setalpha(float tt) {alpha = tt;}
|
||||||
|
inline void Setbeta(float tt) {beta = tt;}
|
||||||
|
inline void Setgamma(float tt) {gamma = tt;}
|
||||||
|
|
||||||
|
inline void Setadot(float tt) {adot = tt;}
|
||||||
|
inline void Setbdot(float tt) {bdot = tt;}
|
||||||
|
|
||||||
|
inline void SetUdot(float tt) {Udot = tt;}
|
||||||
|
inline void SetVdot(float tt) {Vdot = tt;}
|
||||||
|
inline void SetWdot(float tt) {Wdot = tt;}
|
||||||
|
|
||||||
|
inline void SetPdot(float tt) {Pdot = tt;}
|
||||||
|
inline void SetQdot(float tt) {Qdot = tt;}
|
||||||
|
inline void SetRdot(float tt) {Rdot = tt;}
|
||||||
|
|
||||||
|
inline void Setphi(float tt) {phi = tt;}
|
||||||
|
inline void Settht(float tt) {tht = tt;}
|
||||||
|
inline void Setpsi(float tt) {psi = tt;}
|
||||||
|
|
||||||
|
inline void Setg(float tt) {g = tt;}
|
||||||
|
inline void Setm(float tt) {m = tt;}
|
||||||
|
inline void Setqbar(float tt) {qbar = tt;}
|
||||||
|
|
||||||
|
inline void Seth(float tt) {h = tt;}
|
||||||
|
inline void Seta(float tt) {a = tt;}
|
||||||
|
inline void SetMach(float tt) {Mach = tt;}
|
||||||
|
|
||||||
|
inline void Setrho(float tt) {rho = tt;}
|
||||||
|
inline float Setsim_time(float tt) {sim_time = tt; return sim_time;}
|
||||||
|
inline void Setdt(float tt) {dt = tt;}
|
||||||
|
inline void SetQ0123(float q0, float q1, float q2, float q3) {Q0=q0;Q1=q1;Q2=q2;Q3=q3;}
|
||||||
|
inline void SetT(int r, int c, float tt) {T[r][c] = tt;}
|
||||||
|
|
||||||
|
inline float IncrTime(void) {sim_time+=dt;return sim_time;}
|
||||||
|
|
||||||
|
const float EarthRad;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
float U, V, W, Fx, Fy, Fz; // A/C body axis velocities and forces
|
||||||
|
float P, Q, R, L, M, N; // A/C body axis rates and moments
|
||||||
|
float Q0, Q1, Q2, Q3; // Quaternion elements
|
||||||
|
float Ixx, Iyy, Izz, Ixz; // Moments of Inertia
|
||||||
|
float Vt; // Total velocity
|
||||||
|
float Vn, Ve, Vd; // North, East, and Down local velocities
|
||||||
|
float latitude, longitude; // position
|
||||||
|
float GeodeticLat; // Geodetic Latitude
|
||||||
|
float alpha, beta, gamma; // angle of attack, sideslip, and roll
|
||||||
|
float adot, bdot; // alpha dot and beta dot
|
||||||
|
float phi, tht, psi; // Euler angles
|
||||||
|
float Udot, Vdot, Wdot; // A/C body axis accelerations
|
||||||
|
float Pdot, Qdot, Rdot; // A/C body axis rotational accelerations
|
||||||
|
float h, a; // altitude above sea level, speed of sound
|
||||||
|
float rho, qbar; // density of air in lb/ft^3, dynamic pressure
|
||||||
|
float sim_time, dt;
|
||||||
|
float m, g; // mass and acceleration of gravity
|
||||||
|
float T[4][4]; // Local to Body transformation matrix
|
||||||
|
float Mach; // Mach number
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef FDM_MAIN
|
||||||
|
extern FGState* State;
|
||||||
|
#else
|
||||||
|
FGState* State;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
93
JSBsim/FGTank.cpp
Normal file
93
JSBsim/FGTank.cpp
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGTank.cpp
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 01/21/99
|
||||||
|
Called by: FGAircraft
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
See header file.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
01/21/99 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGTank.h"
|
||||||
|
#include <fstream.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
FGTank::FGTank(ifstream& acfile)
|
||||||
|
{
|
||||||
|
char type[20];
|
||||||
|
|
||||||
|
acfile >> type;
|
||||||
|
if (strstr(type,"FUEL")) Type = 0;
|
||||||
|
else if (strstr(type,"OXIDIZER")) Type = 1;
|
||||||
|
else Type = -1;
|
||||||
|
acfile >> X;
|
||||||
|
acfile >> Y;
|
||||||
|
acfile >> Z;
|
||||||
|
acfile >> Radius;
|
||||||
|
acfile >> Capacity;
|
||||||
|
acfile >> Contents;
|
||||||
|
Selected = true;
|
||||||
|
PctFull = 100.0*Contents/Capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGTank::~FGTank(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float FGTank::Reduce(float used)
|
||||||
|
{
|
||||||
|
float shortage;
|
||||||
|
|
||||||
|
if (used < Contents) {
|
||||||
|
Contents -= used;
|
||||||
|
PctFull = 100.0*Contents/Capacity;
|
||||||
|
return Contents;
|
||||||
|
} else {
|
||||||
|
shortage = Contents - used;
|
||||||
|
Contents = 0.0;
|
||||||
|
PctFull = 0.0;
|
||||||
|
Selected = false;
|
||||||
|
return shortage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
82
JSBsim/FGTank.h
Normal file
82
JSBsim/FGTank.h
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGTank.h
|
||||||
|
Author: Jon S. Berndt
|
||||||
|
Date started: 01/21/99
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Based on Flightgear code, which is based on LaRCSim. This class simulates
|
||||||
|
a generic Tank.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
01/21/99 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGTank_H
|
||||||
|
#define FGTank_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <fstream.h>
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
DEFINES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGTank
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGTank(ifstream&);
|
||||||
|
~FGTank(void);
|
||||||
|
|
||||||
|
float Reduce(float);
|
||||||
|
int GetType(void) {return Type;}
|
||||||
|
bool GetSelected(void) {return Selected;}
|
||||||
|
float GetPctFull(void) {return PctFull;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
float X, Y, Z;
|
||||||
|
float Capacity;
|
||||||
|
int Type;
|
||||||
|
float Radius;
|
||||||
|
float PctFull;
|
||||||
|
float Contents;
|
||||||
|
bool Selected;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
163
JSBsim/FGTranslation.cpp
Normal file
163
JSBsim/FGTranslation.cpp
Normal file
|
@ -0,0 +1,163 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGTranslation.cpp
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 12/02/98
|
||||||
|
Purpose: Integrates the translational EOM
|
||||||
|
Called by: FDMExec
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
This class integrates the translational EOM.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/02/98 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
COMMENTS, REFERENCES, and NOTES
|
||||||
|
********************************************************************************
|
||||||
|
[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
|
||||||
|
Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
|
||||||
|
School, January 1994
|
||||||
|
[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
|
||||||
|
JSC 12960, July 1977
|
||||||
|
[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
|
||||||
|
NASA-Ames", NASA CR-2497, January 1975
|
||||||
|
[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
|
||||||
|
Wiley & Sons, 1979 ISBN 0-471-03032-5
|
||||||
|
[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
|
||||||
|
1982 ISBN 0-471-08936-2
|
||||||
|
|
||||||
|
The order of rotations used in this class corresponds to a 3-2-1 sequence,
|
||||||
|
or Y-P-R, or Z-Y-X, if you prefer.
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGTranslation.h"
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
FGTranslation::FGTranslation(void) : FGModel()
|
||||||
|
{
|
||||||
|
strcpy(Name, "FGTranslation");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGTranslation::~FGTranslation(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FGTranslation::Run(void)
|
||||||
|
{
|
||||||
|
if (!FGModel::Run()) {
|
||||||
|
|
||||||
|
GetState();
|
||||||
|
|
||||||
|
lastUdot = Udot;
|
||||||
|
lastVdot = Vdot;
|
||||||
|
lastWdot = Wdot;
|
||||||
|
|
||||||
|
Udot = V*R - W*Q + Fx/m;
|
||||||
|
Vdot = W*P - U*R + Fy/m;
|
||||||
|
Wdot = U*Q - V*P + Fz/m;
|
||||||
|
|
||||||
|
U += 0.5*dt*(lastUdot + Udot);
|
||||||
|
V += 0.5*dt*(lastVdot + Vdot);
|
||||||
|
W += 0.5*dt*(lastWdot + Wdot);
|
||||||
|
|
||||||
|
Vt = U*U+V*V+W*W > 0.0 ? sqrt(U*U + V*V + W*W) : 0.0;
|
||||||
|
|
||||||
|
if (W != 0.0)
|
||||||
|
alpha = U*U > 0.0 ? atan2(W, U) : 0.0;
|
||||||
|
if (V != 0.0)
|
||||||
|
beta = U*U+W*W > 0.0 ? atan2(V, (fabs(U)/U)*sqrt(U*U + W*W)) : 0.0;
|
||||||
|
|
||||||
|
qbar = 0.5*rho*Vt*Vt;
|
||||||
|
|
||||||
|
PutState();
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGTranslation::GetState(void)
|
||||||
|
{
|
||||||
|
dt = State->Getdt();
|
||||||
|
|
||||||
|
P = State->GetP();
|
||||||
|
Q = State->GetQ();
|
||||||
|
R = State->GetR();
|
||||||
|
|
||||||
|
Fx = State->GetFx();
|
||||||
|
Fy = State->GetFy();
|
||||||
|
Fz = State->GetFz();
|
||||||
|
|
||||||
|
m = State->Getm();
|
||||||
|
g = State->Getg();
|
||||||
|
rho = State->Getrho();
|
||||||
|
|
||||||
|
phi = State->Getphi();
|
||||||
|
tht = State->Gettht();
|
||||||
|
psi = State->Getpsi();
|
||||||
|
|
||||||
|
U = State->GetU();
|
||||||
|
V = State->GetV();
|
||||||
|
W = State->GetW();
|
||||||
|
|
||||||
|
Udot = State->GetUdot();
|
||||||
|
Vdot = State->GetVdot();
|
||||||
|
Wdot = State->GetWdot();
|
||||||
|
|
||||||
|
alpha = State->Getalpha();
|
||||||
|
beta = State->Getbeta();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FGTranslation::PutState(void)
|
||||||
|
{
|
||||||
|
State->SetU(U);
|
||||||
|
State->SetV(V);
|
||||||
|
State->SetW(W);
|
||||||
|
|
||||||
|
State->SetVt(Vt);
|
||||||
|
State->Setqbar(qbar);
|
||||||
|
|
||||||
|
State->SetUdot(Udot);
|
||||||
|
State->SetVdot(Vdot);
|
||||||
|
State->SetWdot(Wdot);
|
||||||
|
|
||||||
|
State->Setalpha(alpha);
|
||||||
|
State->Setbeta(beta);
|
||||||
|
}
|
||||||
|
|
100
JSBsim/FGTranslation.h
Normal file
100
JSBsim/FGTranslation.h
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGTranslation.h
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 12/02/98
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
12/02/98 JSB Created
|
||||||
|
|
||||||
|
********************************************************************************
|
||||||
|
COMMENTS, REFERENCES, and NOTES
|
||||||
|
********************************************************************************
|
||||||
|
[1] Cooke, Zyda, Pratt, and McGhee, "NPSNET: Flight Simulation Dynamic Modeling
|
||||||
|
Using Quaternions", Presence, Vol. 1, No. 4, pp. 404-420 Naval Postgraduate
|
||||||
|
School, January 1994
|
||||||
|
[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
|
||||||
|
JSC 12960, July 1977
|
||||||
|
[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
|
||||||
|
NASA-Ames", NASA CR-2497, January 1975
|
||||||
|
[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
|
||||||
|
Wiley & Sons, 1979 ISBN 0-471-03032-5
|
||||||
|
[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
|
||||||
|
1982 ISBN 0-471-08936-2
|
||||||
|
|
||||||
|
The order of rotations used in this class corresponds to a 3-2-1 sequence,
|
||||||
|
or Y-P-R, or Z-Y-X, if you prefer.
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGTRANSLATION_H
|
||||||
|
#define FGTRANSLATION_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGModel.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGTranslation : public FGModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGTranslation(void);
|
||||||
|
~FGTranslation(void);
|
||||||
|
|
||||||
|
bool Run(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
float U, V, W;
|
||||||
|
float P, Q, R;
|
||||||
|
float Vt, qbar;
|
||||||
|
float Udot, Vdot, Wdot;
|
||||||
|
float lastUdot, lastVdot, lastWdot;
|
||||||
|
float phi, tht, psi;
|
||||||
|
float Fx, Fy, Fz;
|
||||||
|
float m, g, dt;
|
||||||
|
float alpha, beta;
|
||||||
|
float rho;
|
||||||
|
|
||||||
|
void GetState(void);
|
||||||
|
void PutState(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef FDM_MAIN
|
||||||
|
extern FGTranslation* Translation;
|
||||||
|
#else
|
||||||
|
FGTranslation* Translation;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
134
JSBsim/FGUtility.cpp
Normal file
134
JSBsim/FGUtility.cpp
Normal file
|
@ -0,0 +1,134 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Module: FGUtility.cpp
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 01/09/99
|
||||||
|
Purpose: Contains utility classes for the FG FDM
|
||||||
|
Called by: FGPosition, et. al.
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
FUNCTIONAL DESCRIPTION
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
This class is a container for all utility classes used by the flight dynamics
|
||||||
|
model.
|
||||||
|
|
||||||
|
ARGUMENTS
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
01/09/99 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
DEFINES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/********************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include "FGUtility.h"
|
||||||
|
#include "FGState.h"
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#ifndef __BORLANDC__
|
||||||
|
#include <ncurses.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
************************************ CODE **************************************
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
const float EarthRadSqrd = 437882827922500.0;
|
||||||
|
const float OneSecond = 4.848136811E-6;
|
||||||
|
const float Eccentricity = 0.996647186;
|
||||||
|
const float EccentSqrd = Eccentricity*Eccentricity;
|
||||||
|
const float EPS = 0.081819221;
|
||||||
|
|
||||||
|
FGUtility::FGUtility()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FGUtility::~FGUtility()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float FGUtility::ToGeodetic()
|
||||||
|
{
|
||||||
|
float GeodeticLat, Latitude, Radius, Altitude, SeaLevelR;
|
||||||
|
float tanLat, xAlpha, muAlpha, sinmuAlpha, denom, rhoAlpha, dMu;
|
||||||
|
float lPoint, lambdaSL, sinlambdaSL, dLambda, rAlpha;
|
||||||
|
|
||||||
|
Latitude = State->Getlatitude();
|
||||||
|
Radius = State->Geth() + State->EarthRad;
|
||||||
|
|
||||||
|
if (( M_PI_2 - Latitude < OneSecond) ||
|
||||||
|
( M_PI_2 + Latitude < OneSecond)) { // Near a pole
|
||||||
|
GeodeticLat = Latitude;
|
||||||
|
SeaLevelR = State->EarthRad * Eccentricity;
|
||||||
|
Altitude = Radius - SeaLevelR;
|
||||||
|
} else {
|
||||||
|
tanLat = tan(Latitude);
|
||||||
|
xAlpha = Eccentricity*State->EarthRad /
|
||||||
|
sqrt(tanLat*tanLat + EccentSqrd);
|
||||||
|
muAlpha = atan2(sqrt(EarthRadSqrd - xAlpha*xAlpha), Eccentricity*xAlpha);
|
||||||
|
|
||||||
|
if (Latitude < 0.0) muAlpha = -muAlpha;
|
||||||
|
|
||||||
|
sinmuAlpha = sin(muAlpha);
|
||||||
|
dLambda = muAlpha - Latitude;
|
||||||
|
rAlpha = xAlpha / cos(Latitude);
|
||||||
|
lPoint = Radius - rAlpha;
|
||||||
|
Altitude = lPoint*cos(dLambda);
|
||||||
|
denom = sqrt(1-EPS*EPS*sinmuAlpha*sinmuAlpha);
|
||||||
|
rhoAlpha = State->EarthRad*(1.0 - EPS) / (denom*denom*denom);
|
||||||
|
dMu = atan2(lPoint*sin(dLambda),rhoAlpha + Altitude);
|
||||||
|
State->SetGeodeticLat(muAlpha - dMu);
|
||||||
|
lambdaSL = atan(EccentSqrd*tan(GeodeticLat));
|
||||||
|
sinlambdaSL = sin(lambdaSL);
|
||||||
|
SeaLevelR = sqrt(EarthRadSqrd / (1 + (1/EccentSqrd - 1.0)* sinlambdaSL*sinlambdaSL));
|
||||||
|
}
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
float FGUtility:: FromGeodetic()
|
||||||
|
{
|
||||||
|
float lambdaSL, sinlambdaSL, coslambdaSL, sinMu, cosMu, py, px;
|
||||||
|
float Altitude, SeaLevelR;
|
||||||
|
|
||||||
|
lambdaSL = atan(EccentSqrd*tan(State->GetGeodeticLat()));
|
||||||
|
sinlambdaSL = sin(lambdaSL);
|
||||||
|
coslambdaSL = cos(lambdaSL);
|
||||||
|
sinMu = sin(State->GetGeodeticLat());
|
||||||
|
cosMu = cos(State->GetGeodeticLat());
|
||||||
|
SeaLevelR = sqrt(EarthRadSqrd /
|
||||||
|
(1 + ((1/EccentSqrd)-1)*sinlambdaSL*sinlambdaSL));
|
||||||
|
px = SeaLevelR*coslambdaSL + Altitude*cosMu;
|
||||||
|
py = SeaLevelR*sinlambdaSL + Altitude*sinMu;
|
||||||
|
State->Setlatitude(atan2(py,px));
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
66
JSBsim/FGUtility.h
Normal file
66
JSBsim/FGUtility.h
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
|
||||||
|
Header: FGUtility.h
|
||||||
|
Author: Jon Berndt
|
||||||
|
Date started: 01/09/99
|
||||||
|
|
||||||
|
------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free Software
|
||||||
|
Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along with
|
||||||
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||||
|
Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
Further information about the GNU General Public License can also be found on
|
||||||
|
the world wide web at http://www.gnu.org.
|
||||||
|
|
||||||
|
HISTORY
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
01/09/99 JSB Created
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
SENTRY
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef FGUTILITY_H
|
||||||
|
#define FGUTILITY_H
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
INCLUDES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
DEFINES
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
CLASS DECLARATION
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
class FGUtility
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
FGUtility(void);
|
||||||
|
~FGUtility(void);
|
||||||
|
|
||||||
|
float ToGeodetic(void);
|
||||||
|
float FromGeodetic(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
#endif
|
19
JSBsim/Makefile.am
Normal file
19
JSBsim/Makefile.am
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
noinst_LIBRARIES = libJSBsim.a
|
||||||
|
|
||||||
|
EXTRA_DIST = aircraft engine
|
||||||
|
|
||||||
|
libJSBsim_a_SOURCES = FGAircraft.cpp FGAircraft.h \
|
||||||
|
FGAtmosphere.cpp FGAtmosphere.h \
|
||||||
|
FGAuxiliary.cpp FGAuxiliary.h \
|
||||||
|
FGCoefficient.cpp FGCoefficient.h \
|
||||||
|
FGFCS.cpp FGFCS.h \
|
||||||
|
FGFDMExec.cpp FGFDMExec.h \
|
||||||
|
FGModel.cpp FGModel.h \
|
||||||
|
FGOutput.cpp FGOutput.h \
|
||||||
|
FGPosition.cpp FGPosition.h \
|
||||||
|
FGRotation.cpp FGRotation.h \
|
||||||
|
FGState.cpp FGState.h \
|
||||||
|
FGTranslation.cpp FGTranslation.h \
|
||||||
|
FGUtility.cpp FGUtility.h \
|
||||||
|
FGEngine.cpp FGEngine.h \
|
||||||
|
FGTank.cpp FGTank.h
|
Loading…
Add table
Reference in a new issue