--------------------------------------------------------------------------------
See header file.
-ARGUMENTS
---------------------------------------------------------------------------------
-
-
HISTORY
--------------------------------------------------------------------------------
-
01/21/99 JSB Created
********************************************************************************
INCLUDES
*******************************************************************************/
+#include <fstream.h>
+
#include "FGEngine.h"
#include "FGState.h"
+#include "FGFDMExec.h"
+#include "FGAtmosphere.h"
#include "FGFCS.h"
-#include <fstream.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "FGAircraft.h"
+#include "FGTranslation.h"
+#include "FGRotation.h"
+#include "FGPosition.h"
+#include "FGAuxiliary.h"
+#include "FGOutput.h"
/*******************************************************************************
************************************ CODE **************************************
*******************************************************************************/
-FGEngine::FGEngine(char *engineName)
+FGEngine::FGEngine(FGFDMExec* fdex, string enginePath, string engineName,
+ int num)
{
- char fullpath[250];
- char tag[220];
+ string fullpath;
+ string tag;
+
+ FDMExec = fdex;
+
+ State = FDMExec->GetState();
+ Atmosphere = FDMExec->GetAtmosphere();
+ FCS = FDMExec->GetFCS();
+ Aircraft = FDMExec->GetAircraft();
+ Translation = FDMExec->GetTranslation();
+ Rotation = FDMExec->GetRotation();
+ Position = FDMExec->GetPosition();
+ 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 {
cerr << "Unable to open engine definition file " << engineName << endl;
}
+ EngineNumber = num;
Thrust = 0.0;
Starved = Flameout = false;
}
{
float lastThrust;
- Throttle = FCS->GetThrottle();
+ Throttle = FCS->GetThrottle(EngineNumber);
lastThrust = Thrust; // last actual thrust
if (Throttle < MinThrottle || Starved) {
Flameout = true;
} else {
PctPower = Throttle / MaxThrottle;
- Thrust = PctPower*((1.0 - State->Getrho() / 0.002378)*(VacThrustMax - SLThrustMax) +
+ Thrust = PctPower*((1.0 - Atmosphere->Getrho() / 0.002378)*(VacThrustMax - SLThrustMax) +
SLThrustMax); // desired thrust
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
+ // break;
+ case etPiston:
return CalcPistonThrust();
- break;
+ // break;
default:
return 9999.0;
- break;
+ // break;
}
}