Integrated Jon's next version of JSBsim.
// (Log is kept at end of this file)
+#include <Include/compiler.h>
+
+#include STL_STRING
+
+#include <Aircraft/aircraft.hxx>
+#include <Controls/controls.hxx>
+#include <Debug/logstream.hxx>
+#include <Include/fg_constants.h>
+#include <Main/options.hxx>
+#include <Math/fg_geodesy.hxx>
+
#include <FDM/JSBsim/FGFDMExec.h>
#include <FDM/JSBsim/FGAircraft.h>
#include <FDM/JSBsim/FGFCS.h>
#include "JSBsim.hxx"
-#include <Aircraft/aircraft.hxx>
-#include <Controls/controls.hxx>
-#include <Debug/logstream.hxx>
-#include <Include/fg_constants.h>
-#include <Math/fg_geodesy.hxx>
-
// The default aircraft
FGFDMExec FDMExec;
FG_LOG( FG_FLIGHT, FG_INFO, " created FDMExec" );
- FDMExec.GetAircraft()->LoadAircraft("X15");
+ string aircraft_path = current_options.get_fg_root() + "/Aircraft";
+ string engine_path = current_options.get_fg_root() + "/Engine";
+
+ FDMExec.GetAircraft()->LoadAircraft(aircraft_path, engine_path, "X15");
FG_LOG( FG_FLIGHT, FG_INFO, " loaded aircraft" );
- FDMExec.GetState()->Reset("reset00");
+ FDMExec.GetState()->Reset(aircraft_path, "Reset00");
FG_LOG( FG_FLIGHT, FG_INFO, " loaded initial conditions" );
FDMExec.GetState()->Setdt(dt);
/* FDMExec.GetState()->Setsim_time(State->Getsim_time()
+ State->Getdt() * multiloop); */
- FDMExec.Run();
+
+ for ( int i = 0; i < multiloop; i++ ) {
+ FDMExec.Run();
+ }
// printf("%d FG_Altitude = %.2f\n", i, FG_Altitude * 0.3048);
// printf("%d Altitude = %.2f\n", i, Altitude * 0.3048);
// ***FIXME*** f.set_Geocentric_Rates( Latitude_dot, Longitude_dot, Radius_dot );
// Positions
- double lat = FDMExec.GetState()->Getlatitude();
+ double lat_geoc = FDMExec.GetState()->Getlatitude();
double lon = FDMExec.GetState()->Getlongitude();
double alt = FDMExec.GetState()->Geth();
- double lat_geoc, sl_radius;
- fgGeodToGeoc( lat, alt * FEET_TO_METER, &sl_radius, &lat_geoc );
+ double lat_geod, tmp_alt, sl_radius1, sl_radius2, tmp_lat_geoc;
+ fgGeocToGeod( lat_geoc, EQUATORIAL_RADIUS_M + alt * FEET_TO_METER,
+ &lat_geod, &tmp_alt, &sl_radius1 );
+ fgGeodToGeoc( lat_geod, alt * FEET_TO_METER, &sl_radius2, &tmp_lat_geoc );
- FG_LOG( FG_FLIGHT, FG_DEBUG, "lon = " << lon << " lat = " << lat
+ FG_LOG( FG_FLIGHT, FG_DEBUG, "lon = " << lon << " lat_geod = " << lat_geod
<< " lat_geoc = " << lat_geoc
- << " alt = " << alt
- << " sl_radius = " << sl_radius * METER_TO_FEET);
+ << " alt = " << alt << " tmp_alt = " << tmp_alt * METER_TO_FEET
+ << " sl_radius1 = " << sl_radius1 * METER_TO_FEET
+ << " sl_radius2 = " << sl_radius2 * METER_TO_FEET
+ << " Equator = " << EQUATORIAL_RADIUS_FT );
- f.set_Geocentric_Position( lat_geoc, lon, sl_radius * METER_TO_FEET + alt );
- f.set_Geodetic_Position( lat, lon, alt );
+ f.set_Geocentric_Position( lat_geoc, lon,
+ sl_radius2 * METER_TO_FEET + alt );
+ f.set_Geodetic_Position( lat_geod, lon, alt );
f.set_Euler_Angles( FDMExec.GetRotation()->Getphi(),
FDMExec.GetRotation()->Gettht(),
FDMExec.GetRotation()->Getpsi() );
// f.set_Static_temperature( Static_temperature );
// f.set_Total_temperature( Total_temperature );
- /* **FIXME*** */ f.set_Sea_level_radius( sl_radius * METER_TO_FEET );
+ /* **FIXME*** */ f.set_Sea_level_radius( sl_radius2 * METER_TO_FEET );
/* **FIXME*** */ f.set_Earth_position_angle( 0.0 );
/* ***FIXME*** */ f.set_Runway_altitude( 0.0 );
// $Log$
+// Revision 1.3 1999/02/26 22:09:10 curt
+// Added initial support for native SGI compilers.
+// Integrated Jon's next version of JSBsim.
+//
// Revision 1.2 1999/02/11 21:09:40 curt
// Interface with Jon's submitted JSBsim changes.
//
LaRCsim.cxx LaRCsim.hxx
INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib -I$(top_builddir)/Simulator
+
+DEFS += -DFGFS
#include <stdio.h>
-#include "flight.hxx"
-#include "JSBsim.hxx"
-#include "LaRCsim.hxx"
-
#include <Debug/logstream.hxx>
#include <FDM/External/external.hxx>
#include <FDM/LaRCsim/ls_interface.h>
#include <Math/fg_geodesy.hxx>
#include <Time/timestamp.hxx>
+#include "flight.hxx"
+#include "JSBsim.hxx"
+#include "LaRCsim.hxx"
+
// base_fdm_state is the internal state that is updated in integer
// multiples of "dt". This leads to "jitter" with respect to the real
// $Log$
+// Revision 1.16 1999/02/26 22:09:12 curt
+// Added initial support for native SGI compilers.
+// Integrated Jon's next version of JSBsim.
+//
// Revision 1.15 1999/02/05 21:29:01 curt
// Modifications to incorporate Jon S. Berndts flight model code.
//
-/** *****************************************************************************
+/*******************************************************************************
Module: FGAircraft.cpp
Author: Jon S. Berndt
********************************************************************************
INCLUDES
*******************************************************************************/
-#include <stdlib.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/types.h>
-#include <math.h>
+
+#ifdef FGFS
+# include <Include/compiler.h>
+# ifdef FG_HAVE_STD_INCLUDES
+# include <cmath>
+# else
+# include <math.h>
+# endif
+#else
+# include <cmath>
+#endif
#include "FGAircraft.h"
#include "FGTranslation.h"
{
int i;
- strcpy(Name,"FGAircraft");
+ 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");
+ Axis[LiftCoeff] = "CLIFT";
+ Axis[DragCoeff] = "CDRAG";
+ Axis[SideCoeff] = "CSIDE";
+ Axis[RollCoeff] = "CROLL";
+ Axis[PitchCoeff] = "CPITCH";
+ Axis[YawCoeff] = "CYAW";
}
}
-bool FGAircraft::LoadAircraft(char* fname)
+bool FGAircraft::LoadAircraft(string aircraft_path, string engine_path,
+ string fname)
{
- char path[256];
- char fullpath[256];
- char filename[256];
- char aircraftDef[256];
- char tag[256];
+ string path;
+ string fullpath;
+ string filename;
+ string aircraftDef;
+ string tag;
DIR* dir;
DIR* coeffdir;
struct dirent* dirEntry;
struct stat st2;
ifstream coeffInFile;
- sprintf(aircraftDef, "/h/curt/projects/FlightGear/Simulator/FDM/JSBsim/aircraft/%s/%s.dat", fname, fname);
- ifstream aircraftfile(aircraftDef);
+ aircraftDef = aircraft_path + "/" + fname + "/" + fname + ".dat";
+ ifstream aircraftfile(aircraftDef.c_str());
if (aircraftfile) {
aircraftfile >> AircraftName; // String with no embedded spaces
numTanks = numEngines = 0;
numSelectedOxiTanks = numSelectedFuelTanks = 0;
- while (strstr(tag,"EOF") == 0) {
- if (strstr(tag,"CGLOC")) {
+ while ( !(tag == "EOF") ) {
+ if (tag == "CGLOC") {
aircraftfile >> Xcg; // inches
aircraftfile >> Ycg; // inches
aircraftfile >> Zcg; // inches
- } else if (strstr(tag,"EYEPOINTLOC")) {
+ } else if (tag == "EYEPOINTLOC") {
aircraftfile >> Xep; // inches
aircraftfile >> Yep; // inches
aircraftfile >> Zep; // inches
- } else if (strstr(tag,"TANK")) {
+ } else if (tag == "TANK") {
Tank[numTanks] = new FGTank(aircraftfile);
switch(Tank[numTanks]->GetType()) {
- case 0:
- numSelectedOxiTanks++;
- break;
- case 1:
+ case FGTank::ttFUEL:
numSelectedFuelTanks++;
break;
+ case FGTank::ttOXIDIZER:
+ numSelectedOxiTanks++;
+ break;
}
numTanks++;
- } else if (strstr(tag,"ENGINE")) {
+ } else if (tag == "ENGINE") {
aircraftfile >> tag;
- Engine[numEngines] = new FGEngine(FDMExec, tag, numEngines);
+ Engine[numEngines] = new FGEngine(FDMExec, engine_path, tag,
+ numEngines);
numEngines++;
}
aircraftfile >> tag;
// 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)) {
+ path = aircraft_path + "/" + AircraftName + "/";
+ if (dir = opendir(path.c_str())) {
while (dirEntry = readdir(dir)) {
- sprintf(fullpath,"%s%s",path,dirEntry->d_name);
- stat(fullpath,&st);
+ fullpath = path + dirEntry->d_name;
+ stat(fullpath.c_str(),&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)) {
+ if (dirEntry->d_name == Axis[axis_ctr]) {
+ if (coeffdir = opendir(fullpath.c_str())) {
while (coeffdirEntry = readdir(coeffdir)) {
if (coeffdirEntry->d_name[0] != '.') {
- sprintf(filename,"%s%s/%s",path,Axis[axis_ctr],coeffdirEntry->d_name);
- stat(filename,&st2);
+ filename = path + Axis[axis_ctr] + "/" + coeffdirEntry->d_name;
+ stat(filename.c_str(),&st2);
if (st2.st_size > 6) {
Coeff[axis_ctr][coeff_ctr[axis_ctr]] = new FGCoefficient(FDMExec, filename);
coeff_ctr[axis_ctr]++;
Fshortage = Oshortage = 0.0;
for (int t=0; t<numTanks; t++) {
switch(Engine[e]->GetType()) {
- case 0: // Rocket
+ case FGEngine::etRocket:
+
switch(Tank[t]->GetType()) {
- case 0: // Fuel
+ case FGTank::ttFUEL:
if (Tank[t]->GetSelected()) {
Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/
numSelectedFuelTanks)*(dt*rate) + Fshortage);
}
break;
- case 1: // Oxidizer
+ case FGTank::ttOXIDIZER:
if (Tank[t]->GetSelected()) {
Oshortage = Tank[t]->Reduce((Engine[e]->CalcOxidizerNeed()/
numSelectedOxiTanks)*(dt*rate) + Oshortage);
break;
}
break;
- default: // piston, turbojet, turbofan, etc.
+
+ case FGEngine::etPiston:
+ case FGEngine::etTurboJet:
+ case FGEngine::etTurboProp:
+
if (Tank[t]->GetSelected()) {
Fshortage = Tank[t]->Reduce((Engine[e]->CalcFuelNeed()/
numSelectedFuelTanks)*(dt*rate) + Fshortage);
/*******************************************************************************
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
+*******************************************************************************/
+/**
+The aerodynamic coefficients used in this model typically are:
+<PRE>
+<b>Longitudinal</b>
CL0 - Reference lift at zero alpha
CD0 - Reference drag at zero alpha
CDM - Drag due to Mach
CLM - Lift due to Mach
CLadt - Lift due to alpha rate
- Cmadt - Moment due to alpha rate
- Cm0 - Reference moment at zero alpha
+ 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 - Moment due to Mach
+ CmM - Pitch Moment due to Mach
-Lateral
+<b>Lateral</b>
Cyb - Side force due to sideslip
Cyr - Side force due to yaw rate
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
+<b>Control</b>
+ CLDe - Lift due to elevator
+ CDDe - Drag due to elevator
CyDr - Side force due to rudder
CyDa - Side force due to aileron
ClDr - Roll moment due to rudder
CnDr - Yaw moment due to rudder
CnDa - Yaw moment due to aileron
+</PRE>
+This class expects to be run in a directory which contains the subdirectory
+structure shown below (where example aircraft X-15 is shown):
+
+<PRE>
+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
+ ...
+</PRE>
+
+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.
+@author Jon S. Berndt
+@memo Encompasses all aircraft functionality and objects
+@see <ll>
+<li>[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</li>
+<li>[2] D. M. Henderson, "Euler Angles, Quaternions, and Transformation Matrices",
+ JSC 12960, July 1977</li>
+<li>[3] Richard E. McFarland, "A Standard Kinematic Model for Flight Simulation at
+ NASA-Ames", NASA CR-2497, January 1975</li>
+<li>[4] Barnes W. McCormick, "Aerodynamics, Aeronautics, and Flight Mechanics",
+ Wiley & Sons, 1979 ISBN 0-471-03032-5</li>
+<li>[5] Bernard Etkin, "Dynamics of Flight, Stability and Control", Wiley & Sons,
+ 1982 ISBN 0-471-08936-2</li>
+</ll>
+*/
-********************************************************************************
+/*******************************************************************************
INCLUDES
*******************************************************************************/
-
-#include <stdio.h>
-#include <fstream.h>
+#ifdef FGFS
+# include <Include/compiler.h>
+# ifdef FG_HAVE_STD_INCLUDES
+# include <fstream>
+# else
+# include <fstream.h>
+# endif
+#else
+# include <fstream>
+#endif
#include "FGModel.h"
#include "FGCoefficient.h"
CLASS DECLARATION
*******************************************************************************/
-
class FGAircraft : public FGModel
{
public:
+ // ***************************************************************************
+ /** @memo Constructor
+ @param FGFDMExec* - a pointer to the "owning" FDM Executive
+ */
FGAircraft(FGFDMExec*);
+
+ // ***************************************************************************
+ /** Destructor */
~FGAircraft(void);
+ // ***************************************************************************
+ /** This must be called for each dt to execute the model algorithm */
bool Run(void);
- bool LoadAircraft(char*);
-
- inline char* GetAircraftName(void) {return AircraftName;}
-
+ // ***************************************************************************
+ /** This function must be called with the name of an aircraft which
+ has an associated .dat file in the appropriate subdirectory. The
+ appropriate subdirectory is underneath the main fgfs binary directory
+ called "aircraft/{<i>aircraft</i>}/, where {<i>aircraft</i>} is the name of
+ specific aircraft you want to simulate.
+ @memo Loads the given aircraft.
+ @param string Path to the Aircraft files
+ @param string Path to the Engine files
+ @param string The name of the aircraft to be loaded, e.g. "X15".
+ @return True - if successful
+ */
+ bool LoadAircraft(string, string, string);
+
+ // ***************************************************************************
+ /** @memo Gets the aircraft name as defined in the aircraft config file.
+ @param
+ @return string Aircraft name.
+ */
+ inline string GetAircraftName(void) {return AircraftName;}
+
+ // ***************************************************************************
+ /** @memo Sets the GearUp flag
+ @param boolean true or false
+ @return
+ */
inline void SetGearUp(bool tt) {GearUp = tt;}
+
+ // ***************************************************************************
+ /** @memo Returns the state of the GearUp flag
+ @param
+ @return boolean true or false
+ */
inline bool GetGearUp(void) {return GearUp;}
+
+ // ***************************************************************************
+ /** @memo Returns the area of the wing
+ @param
+ @return float wing area S, in square feet
+ */
inline float GetWingArea(void) {return WingArea;}
+
+ // ***************************************************************************
+ /** @memo Returns the wing span
+ @param
+ @return float wing span in feet
+ */
inline float GetWingSpan(void) {return WingSpan;}
+
+ // ***************************************************************************
+ /** @memo Returns the average wing chord
+ @param
+ @return float wing chord in feet
+ */
inline float Getcbar(void) {return cbar;}
+
+ // ***************************************************************************
+ /** @memo Returns an engine object
+ @param int The engine number
+ @return FGEengine* The pointer to the requested engine object.
+ */
inline FGEngine* GetEngine(int tt) {return Engine[tt];}
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline FGTank* GetTank(int tt) {return Tank[tt];}
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetWeight(void) {return Weight;}
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetMass(void) {return Mass;}
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetL(void) {return Moments[0];}
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetM(void) {return Moments[1];}
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetN(void) {return Moments[2];}
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetFx(void) {return Forces[0];}
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetFy(void) {return Forces[1];}
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetFz(void) {return Forces[2];}
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetIxx(void) {return Ixx;}
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetIyy(void) {return Iyy;}
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetIzz(void) {return Izz;}
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
inline float GetIxz(void) {return Ixz;}
private:
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
void GetState(void);
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
void PutState(void);
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
void FAero(void);
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
void FGear(void);
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
void FMass(void);
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
void FProp(void);
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
void MAero(void);
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
void MGear(void);
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
void MMass(void);
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
void MProp(void);
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
void MassChange(void);
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
float Moments[3];
+
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
float Forces[3];
- char AircraftName[50];
+ // ***************************************************************************
+ /** @memo
+ @param
+ @return
+ */
+ string AircraftName;
+
+ // ***************************************************************************
+ ///
float Ixx, Iyy, Izz, Ixz, EmptyMass, Mass;
+ ///
float Xcg, Ycg, Zcg;
+ ///
float Xep, Yep, Zep;
+ ///
float rho, qbar, Vt;
+ ///
float alpha, beta;
+ ///
float WingArea, WingSpan, cbar;
+ ///
float phi, tht, psi;
+ ///
float Weight, EmptyWeight;
+ ///
float dt;
+ ///
int numTanks;
+ ///
int numEngines;
+ ///
int numSelectedOxiTanks;
+ ///
int numSelectedFuelTanks;
+ ///
FGTank* Tank[MAX_TANKS];
+ ///
FGEngine *Engine[MAX_ENGINES];
+ ///
FGCoefficient *Coeff[6][10];
+ ///
int coeff_ctr[6];
+ ///
bool GearUp;
+ ///
enum Param {LiftCoeff,
DragCoeff,
SideCoeff,
YawCoeff,
numCoeffs};
- char* Axis[6];
+ ///
+ string Axis[6];
protected:
FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) : FGModel(fdmex)
{
- strcpy(Name,"FGAtmosphere");
+ Name = "FGAtmosphere";
}
FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex)
{
- strcpy(Name, "FGAuxiliary");
+ Name = "FGAuxiliary";
}
INCLUDES
*******************************************************************************/
-#include <stdio.h>
-#include <stdlib.h>
#include "FGCoefficient.h"
-
#include "FGAtmosphere.h"
#include "FGState.h"
#include "FGFDMExec.h"
}
-FGCoefficient::FGCoefficient(FGFDMExec* fdex, char* fname)
+FGCoefficient::FGCoefficient(FGFDMExec* fdex, string fname)
{
int r, c;
float ftrashcan;
Auxiliary = FDMExec->GetAuxiliary();
Output = FDMExec->GetOutput();
- ifstream coeffDefFile(fname);
+ ifstream coeffDefFile(fname.c_str());
if (coeffDefFile) {
if (!coeffDefFile.fail()) {
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 (method == "EQUATION") type = 4;
+ else if (method == "TABLE") type = 3;
+ else if (method == "VECTOR") type = 2;
+ else if (method == "VALUE") type = 1;
+ else type = 0;
if (type == 2 || type == 3) {
coeffDefFile >> rows;
/*******************************************************************************
INCLUDES
*******************************************************************************/
-#include <fstream.h>
+#ifdef FGFS
+# include <Include/compiler.h>
+# include STL_STRING
+# ifdef FG_HAVE_STD_INCLUDES
+# include <fstream>
+# else
+# include <fstream.h>
+# endif
+ FG_USING_STD(string);
+# ifdef FG_HAVE_NATIVE_SGI_COMPILERS
+ FG_USING_NAMESPACE(std);
+# endif
+#else
+# include <string>
+# include <fstream>
+#endif
/*******************************************************************************
DEFINES
FGCoefficient(FGFDMExec*);
FGCoefficient(FGFDMExec*, int, int);
FGCoefficient(FGFDMExec*, int);
- FGCoefficient(FGFDMExec*, char*);
+ FGCoefficient(FGFDMExec*, string);
~FGCoefficient(void);
bool Allocate(int);
protected:
private:
+ string filename;
+ string description;
+ string name;
+ string method;
float StaticValue;
float *Table2D;
float **Table3D;
+ float LookupR, LookupC;
+ long int mult_idx[10];
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);
HISTORY
--------------------------------------------------------------------------------
-
01/21/99 JSB Created
********************************************************************************
*******************************************************************************/
#include <fstream.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include "FGEngine.h"
#include "FGState.h"
*******************************************************************************/
-FGEngine::FGEngine(FGFDMExec* fdex, char *engineName, int num)
+FGEngine::FGEngine(FGFDMExec* fdex, string enginePath, string engineName,
+ int num)
{
- char fullpath[256];
- char tag[256];
+ string fullpath;
+ string tag;
FDMExec = fdex;
Auxiliary = FDMExec->GetAuxiliary();
Output = FDMExec->GetOutput();
- strcpy(Name, engineName);
- sprintf(fullpath,"/h/curt/projects/FlightGear/Simulator/FDM/JSBsim/engine/%s.dat", engineName);
- ifstream enginefile(fullpath);
+ Name = engineName;
+ fullpath = enginePath + "/" + engineName + ".dat";
+ ifstream enginefile(fullpath.c_str());
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;
+
+ if (tag == "ROCKET") Type = etRocket;
+ else if (tag == "PISTON") Type = etPiston;
+ else if (tag == "TURBOPROP") Type = etTurboProp;
+ else if (tag == "TURBOJET") Type = etTurboJet;
+ else Type = etUnknown;
+
enginefile >> X;
enginefile >> Y;
enginefile >> Z;
enginefile >> MaxThrottle;
enginefile >> MinThrottle;
enginefile >> SLFuelFlowMax;
- if (Type == 0)
+ if (Type == 1)
enginefile >> SLOxiFlowMax;
enginefile.close();
} else {
Flameout = false;
}
- Thrust += 0.8*(Thrust - lastThrust); // actual thrust
+ Thrust += 0.8*(Thrust - lastThrust); // actual thrust
return Thrust;
}
float FGEngine::CalcThrust(void)
{
switch(Type) {
- case 0: // Rocket
+ case etRocket:
return CalcRocketThrust();
// break;
- case 1: // Piston
+ case etPiston:
return CalcPistonThrust();
// break;
default:
INCLUDES
*******************************************************************************/
+#ifdef FGFS
+# include <Include/compiler.h>
+# include STL_STRING
+ FG_USING_STD(string);
+# ifdef FG_HAVE_NATIVE_SGI_COMPILERS
+ FG_USING_NAMESPACE(std);
+# endif
+#else
+# include <string>
+#endif
+
/*******************************************************************************
DEFINES
*******************************************************************************/
class FGEngine
{
public:
- FGEngine(FGFDMExec*, char*, int);
+ FGEngine(FGFDMExec*, string, string, int);
~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;}
+ enum EngineType {etUnknown, etRocket, etPiston, etTurboProp, etTurboJet};
+
+ float GetThrottle(void) {return Throttle;}
+ float GetThrust(void) {return Thrust;}
+ bool GetStarved(void) {return Starved;}
+ bool GetFlameout(void) {return Flameout;}
+ int GetType(void) {return Type;}
+ string 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];
+ string Name;
+ EngineType Type;
float X, Y, Z;
- int Type;
float SLThrustMax;
float VacThrustMax;
float SLFuelFlowMax;
FGPosition* Position;
FGAuxiliary* Auxiliary;
FGOutput* Output;
-
+
protected:
float CalcRocketThrust(void);
float CalcPistonThrust(void);
};
/******************************************************************************/
-#endif
\ No newline at end of file
+#endif
FGFCS::FGFCS(FGFDMExec* fdmex) : FGModel(fdmex)
{
- strcpy(Name, "FGFCS");
+ Name = "FGFCS";
}
INCLUDES
*******************************************************************************/
-#include <stdio.h>
-#include <stdlib.h>
-#include <iostream.h>
-#include <time.h>
+#ifdef FGFS
+# include <Include/compiler.h>
+# ifdef FG_HAVE_STD_INCLUDES
+# include <iostream>
+# include <ctime>
+# else
+# include <iostream.h>
+# include <time.h>
+# endif
+#else
+# include <iostream>
+# include <ctime>
+#endif
#include "FGFDMExec.h"
#include "FGState.h"
-
#include "FGAtmosphere.h"
#include "FGFCS.h"
#include "FGAircraft.h"
#include "FGAuxiliary.h"
#include "FGOutput.h"
-#include <iostream.h>
-#include <time.h>
+#include <iostream>
+#include <ctime>
void main(int argc, char** argv)
{
+ FGFDMExec* FDMExec;
+
struct timespec short_wait = {0,100000000};
struct timespec no_wait = {0,100000000};
FDMExec = new FGFDMExec();
- FDMExec->GetAircraft()->LoadAircraft(argv[1]);
- FDMExec->GetState()->Reset(argv[2]);
+ FDMExec->GetAircraft()->LoadAircraft(string(argv[1]));
+ FDMExec->GetState()->Reset(string(argv[2]));
while (FDMExec->GetState()->Getsim_time() <= 25.0)
{
*******************************************************************************/
#include "FGDefs.h"
-#include <stdio.h>
-#include <string.h>
-#include <iostream.h>
+
+#ifdef FGFS
+# include <Include/compiler.h>
+# include STL_STRING
+# ifdef FG_HAVE_STD_INCLUDES
+# include <cstring>
+# include <iostream>
+# else
+# include <string.h>
+# include <iostream.h>
+# endif
+ FG_USING_STD(string);
+# ifdef FG_HAVE_NATIVE_SGI_COMPILERS
+ FG_USING_NAMESPACE(std);
+# endif
+#else
+# include <string>
+# include <cstring>
+# include <iostream>
+#endif
+
/*******************************************************************************
DEFINES
~FGModel(void);
FGModel* NextModel;
- char Name[30];
+ string Name;
virtual bool Run(void);
virtual bool InitModel(void);
void SetRate(int tt) {rate = tt;};
INCLUDES
*******************************************************************************/
-#include <stdio.h>
-#include <stdlib.h>
-#include <iostream.h>
+#ifdef FGFS
+# include <Include/compiler.h>
+# ifdef FG_HAVE_STD_INCLUDES
+# include <iostream>
+# else
+# include <iostream.h>
+# endif
+#else
+# include <iostream>
+#endif
#ifdef HAVE_CURSES
- #include <ncurses.h>
+# include <ncurses.h>
#endif
#include "FGOutput.h"
FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
{
- strcpy(Name, "FGOutput");
+ Name = "FGOutput";
FirstPass = true;
#ifdef HAVE_CURSES
initscr();
void FGOutput::ConsoleOutput(void)
{
#ifdef HAVE_CURSES
- char buffer[20];
+ string buffer;
clear();
move(1,1); insstr("Quaternions");
move(2,27); insstr("Q2");
move(2,38); insstr("Q3");
- move(3,1); sprintf(buffer,"%4.4f",Rotation->GetQ0()); insstr(buffer);
- move(3,12); sprintf(buffer,"%4.4f",Rotation->GetQ1()); insstr(buffer);
- move(3,23); sprintf(buffer,"%4.4f",Rotation->GetQ2()); insstr(buffer);
- move(3,34); sprintf(buffer,"%4.4f",Rotation->GetQ3()); insstr(buffer);
+ move(3,1); buffer = Rotation->GetQ0(); insstr(buffer.c_str());
+ move(3,12); buffer = Rotation->GetQ1(); insstr(buffer.c_str());
+ move(3,23); buffer = Rotation->GetQ2(); insstr(buffer.c_str());
+ move(3,34); buffer = Rotation->GetQ3(); insstr(buffer.c_str());
move(0,0); insstr("Time: ");
move(0,6); insstr(gcvt(State->Getsim_time(),6,buffer));
move(2,55); insstr("Tht");
move(2,64); insstr("Psi");
- move(3,45); sprintf(buffer,"%3.3f",Rotation->Getphi()); insstr(buffer);
- move(3,54); sprintf(buffer,"%3.3f",Rotation->Gettht()); insstr(buffer);
- move(3,63); sprintf(buffer,"%3.3f",Rotation->Getpsi()); insstr(buffer);
+ move(3,45); buffer = Rotation->Getphi(); insstr(buffer.c_str());
+ move(3,54); buffer = Rotation->Gettht(); insstr(buffer.c_str());
+ move(3,63); buffer = Rotation->Getpsi(); insstr(buffer.c_str());
move(5,47); insstr("U");
move(5,56); insstr("V");
move(5,65); insstr("W");
- move(6,45); sprintf(buffer,"%5.2f",Translation->GetU()); insstr(buffer);
- move(6,54); sprintf(buffer,"%5.2f",Translation->GetV()); insstr(buffer);
- move(6,63); sprintf(buffer,"%5.2f",Translation->GetW()); insstr(buffer);
+ move(6,45); buffer = Translation->GetU(); insstr(buffer.c_str());
+ move(6,54); buffer = Translation->GetV(); insstr(buffer.c_str());
+ move(6,63); buffer = Translation->GetW(); insstr(buffer.c_str());
move(8,47); insstr("Fx");
move(8,56); insstr("Fy");
move(8,65); insstr("Fz");
- move(9,45); sprintf(buffer,"%5.2f",Aircraft->GetFx()); insstr(buffer);
- move(9,54); sprintf(buffer,"%5.2f",Aircraft->GetFy()); insstr(buffer);
- move(9,63); sprintf(buffer,"%5.2f",Aircraft->GetFz()); insstr(buffer);
+ move(9,45); buffer = Aircraft->GetFx(); insstr(buffer.c_str());
+ move(9,54); buffer = Aircraft->GetFy(); insstr(buffer.c_str());
+ move(9,63); buffer = Aircraft->GetFz(); insstr(buffer.c_str());
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(12,45); buffer = Position->GetFn(); insstr(buffer.c_str());
+ move(12,54); buffer = Position->GetFe(); insstr(buffer.c_str());
+ move(12,63); buffer = Position->GetFd(); insstr(buffer.c_str());
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);
+ move(15,47); buffer = State->Getlatitude(); insstr(buffer.c_str());
+ move(15,57); buffer = State->Getlongitude(); insstr(buffer.c_str());
+ move(15,67); buffer = State->Geth(); insstr(buffer.c_str());
refresh();
INCLUDES
*******************************************************************************/
-#include <math.h>
+#ifdef FGFS
+# include <Include/compiler.h>
+# ifdef FG_HAVE_STD_INCLUDES
+# include <cmath>
+# else
+# include <math.h>
+# endif
+#else
+# include <cmath>
+#endif
#include "FGPosition.h"
#include "FGAtmosphere.h"
#include "FGState.h"
FGPosition::FGPosition(FGFDMExec* fdmex) : FGModel(fdmex)
{
- strcpy(Name, "FGPosition");
+ Name = "FGPosition";
AccelN = AccelE = AccelD = 0.0;
LongitudeDot = LatitudeDot = RadiusDot = 0.0;
}
FGRotation::FGRotation(FGFDMExec* fdmex) : FGModel(fdmex)
{
- strcpy(Name, "FGRotation");
+ Name = "FGRotation";
Q0dot = Q1dot = Q2dot = Q3dot = 0.0;
Pdot = Qdot = Rdot = 0.0;
}
INCLUDES
*******************************************************************************/
-#include <math.h>
+#ifdef FGFS
+# include <Include/compiler.h>
+# ifdef FG_HAVE_STD_INCLUDES
+# include <cmath>
+# else
+# include <math.h>
+# endif
+#else
+# include <cmath>
+#endif
+
#include "FGModel.h"
/*******************************************************************************
INCLUDES
*******************************************************************************/
-#include <math.h>
-
-#include <string>
+#ifdef FGFS
+# include <Include/compiler.h>
+# ifdef FG_HAVE_STD_INCLUDES
+# include <cmath>
+# else
+# include <math.h>
+# endif
+#else
+# include <cmath>
+#endif
#include "FGState.h"
#include "FGFDMExec.h"
}
-bool FGState::Reset(const string& path, const string& fname)
+bool FGState::Reset(string path, string fname)
{
string resetDef;
float U, V, W;
float Q0, Q1, Q2, Q3;
float T[4][4];
- resetDef = path;
- resetDef += "/";
- resetDef += FDMExec->GetAircraft()->GetAircraftName();
- resetDef += "/" + fname;
+ resetDef = path + "/" + FDMExec->GetAircraft()->GetAircraftName() +
+ "/" + fname;
- ifstream resetfile( resetDef.c_str() );
+ ifstream resetfile(resetDef.c_str());
if (resetfile) {
resetfile >> U;
}
-bool FGState::StoreData(char* fname)
+bool FGState::StoreData(string fname)
{
- ofstream datafile(fname);
+ ofstream datafile(fname.c_str());
if (datafile) {
datafile << FDMExec->GetTranslation()->GetU();
}
-bool FGState::DumpData(char* fname)
+bool FGState::DumpData(string fname)
{
- ofstream datafile(fname);
+ ofstream datafile(fname.c_str());
if (datafile) {
datafile << "U: " << FDMExec->GetTranslation()->GetU() << endl;
INCLUDES
*******************************************************************************/
-#include <stdio.h>
-#include <fstream.h>
-#include <string>
+#ifdef FGFS
+# include <Include/compiler.h>
+# include STL_STRING
+# ifdef FG_HAVE_STD_INCLUDES
+# include <fstream>
+# else
+# include <fstream.h>
+# endif
+ FG_USING_STD(string);
+# ifdef FG_HAVE_NATIVE_SGI_COMPILERS
+ FG_USING_NAMESPACE(std);
+# endif
+#else
+# include <string>
+# include <fstream>
+#endif
+
#include "FGDefs.h"
/*******************************************************************************
FGState(FGFDMExec*);
~FGState(void);
- bool FGState::Reset(const string& path, const string& fname);
- bool StoreData(char*);
- bool DumpData(char*);
+ bool Reset(string, string);
+ bool StoreData(string);
+ bool DumpData(string);
bool DisplayData(void);
inline float GetVt(void) {return Vt;}
********************************************************************************
INCLUDES
*******************************************************************************/
+#ifdef FGFS
+# include <Include/compiler.h>
+# ifdef FG_HAVE_STD_INCLUDES
+# include <fstream>
+# else
+# include <fstream.h>
+# endif
+#else
+# include <fstream>
+#endif
#include "FGTank.h"
-#include <fstream.h>
-#include <string.h>
/*******************************************************************************
************************************ CODE **************************************
FGTank::FGTank(ifstream& acfile)
{
- char type[20];
+ string type;
- acfile >> type; // Type = 0: rocket, 1: piston
- if (strstr(type,"FUEL")) Type = 0;
- else if (strstr(type,"OXIDIZER")) Type = 1;
- else Type = -1;
+ acfile >> type; // Type = 0: fuel, 1: oxidizer
+ if (type == "FUEL") Type = ttFUEL;
+ else if (type == "OXIDIZER") Type = ttOXIDIZER;
+ else Type = ttUNKNOWN;
acfile >> X; // inches
acfile >> Y; // "
acfile >> Z; // "
/*******************************************************************************
INCLUDES
*******************************************************************************/
-
-#include <fstream.h>
+#ifdef FGFS
+# include <Include/compiler.h>
+# include STL_STRING
+# ifdef FG_HAVE_STD_INCLUDES
+# include <fstream>
+# else
+# include <fstream.h>
+# endif
+ FG_USING_STD(string);
+# ifdef FG_HAVE_NATIVE_SGI_COMPILERS
+ FG_USING_NAMESPACE(std);
+# endif
+#else
+# include <string>
+# include <fstream>
+#endif
/*******************************************************************************
DEFINES
bool GetSelected(void) {return Selected;}
float GetPctFull(void) {return PctFull;}
float GetContents(void) {return Contents;}
+
+ enum TankType {ttUNKNOWN, ttFUEL, ttOXIDIZER};
private:
+ TankType Type;
float X, Y, Z;
float Capacity;
- int Type;
float Radius;
float PctFull;
float Contents;
};
/******************************************************************************/
-#endif
\ No newline at end of file
+#endif
FGTranslation::FGTranslation(FGFDMExec* fdmex) : FGModel(fdmex)
{
- strcpy(Name, "FGTranslation");
+ Name = "FGTranslation";
Udot = Vdot = Wdot = 0.0;
}
INCLUDES
*******************************************************************************/
-#include <math.h>
+#ifdef FGFS
+# include <Include/compiler.h>
+# ifdef FG_HAVE_STD_INCLUDES
+# include <cmath>
+# else
+# include <math.h>
+# endif
+#else
+# include <cmath>
+#endif
+
#include "FGModel.h"
/*******************************************************************************
INCLUDES
*******************************************************************************/
+#ifdef FGFS
+# include <Include/compiler.h>
+# ifdef FG_HAVE_STD_INCLUDES
+# include <cmath>
+# else
+# include <math.h>
+# endif
+#else
+# include <cmath>
+#endif
+
#include "FGUtility.h"
#include "FGState.h"
#include "FGFDMExec.h"
-#include <math.h>
/*******************************************************************************
************************************ CODE **************************************
FGAtmosphere.cpp FGAtmosphere.h \
FGAuxiliary.cpp FGAuxiliary.h \
FGCoefficient.cpp FGCoefficient.h \
+ FGDefs.h \
FGFCS.cpp FGFCS.h \
FGFDMExec.cpp FGFDMExec.h \
FGModel.cpp FGModel.h \
FGUtility.cpp FGUtility.h \
FGEngine.cpp FGEngine.h \
FGTank.cpp FGTank.h
+
+INCLUDES += -I$(top_builddir)
+
+DEFS += -DFGFS