]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/JSBSim.cpp
JSBSim tweaks.
[flightgear.git] / src / FDM / JSBSim / JSBSim.cpp
index 72fe75dc37bcdd713c9ed399455e893c4f52799b..400b6088b63ea20f2e47e9170d9874eb303e2735 100644 (file)
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
  Module:       JSBSim.cpp
  Author:       Jon S. Berndt
@@ -35,36 +35,9 @@ HISTORY
 --------------------------------------------------------------------------------
 08/17/99   JSB   Created
 
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 INCLUDES
-*******************************************************************************/
-
-#if __BCPLUSPLUS__     >= 0x0540   // If compiling under Borland C++Builder
-//---------------------------------------------------------------------------
-#pragma hdrstop
-#include <condefs.h>
-USEUNIT("FGAircraft.cpp");
-USEUNIT("FGAtmosphere.cpp");
-USEUNIT("FGAuxiliary.cpp");
-USEUNIT("FGCoefficient.cpp");
-USEUNIT("FGEngine.cpp");
-USEUNIT("FGFCS.cpp");
-USEUNIT("FGFDMExec.cpp");
-USEUNIT("FGInitialCondition.cpp");
-USEUNIT("FGModel.cpp");
-USEUNIT("FGOutput.cpp");
-USEUNIT("FGPosition.cpp");
-USEUNIT("FGRotation.cpp");
-USEUNIT("FGState.cpp");
-USEUNIT("FGTank.cpp");
-USEUNIT("FGTranslation.cpp");
-USEUNIT("FGUtility.cpp");
-USERES("JSBSim.res");
-USEUNIT("FGLGear.cpp");
-USEUNIT("FGfdmSocket.cpp");
-//---------------------------------------------------------------------------
-#pragma argsused
-#endif
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGFDMExec.h"
 #include "FGRotation.h"
@@ -76,11 +49,12 @@ USEUNIT("FGfdmSocket.cpp");
 #include "FGPosition.h"
 #include "FGAuxiliary.h"
 #include "FGOutput.h"
+#include "FGConfigFile.h"
 
 #ifdef FGFS
-#include <Include/compiler.h>
+#include <simgear/compiler.h>
 #include STL_IOSTREAM
-#  ifdef FG_HAVE_STD_INCLUDES
+#  ifdef SG_HAVE_STD_INCLUDES
 #    include <ctime>
 #  else
 #    include <time.h>
@@ -90,47 +64,140 @@ USEUNIT("FGfdmSocket.cpp");
 #include <ctime>
 #endif
 
+#if __BORLANDC__ > 0x540
+#include <condefs.h>
+USEUNIT("FGUtility.cpp");
+USEUNIT("FGAircraft.cpp");
+USEUNIT("FGAtmosphere.cpp");
+USEUNIT("FGAuxiliary.cpp");
+USEUNIT("FGCoefficient.cpp");
+USEUNIT("FGConfigFile.cpp");
+USEUNIT("FGEngine.cpp");
+USEUNIT("FGFCS.cpp");
+USEUNIT("FGFDMExec.cpp");
+USEUNIT("FGfdmSocket.cpp");
+USEUNIT("FGForce.cpp");
+USEUNIT("FGGroundReactions.cpp");
+USEUNIT("FGInertial.cpp");
+USEUNIT("FGInitialCondition.cpp");
+USEUNIT("FGLGear.cpp");
+USEUNIT("FGMassBalance.cpp");
+USEUNIT("FGMatrix.cpp");
+USEUNIT("FGModel.cpp");
+USEUNIT("FGNozzle.cpp");
+USEUNIT("FGOutput.cpp");
+USEUNIT("FGPiston.cpp");
+USEUNIT("FGPosition.cpp");
+USEUNIT("FGPropeller.cpp");
+USEUNIT("FGPropulsion.cpp");
+USEUNIT("FGRocket.cpp");
+USEUNIT("FGRotation.cpp");
+USEUNIT("FGRotor.cpp");
+USEUNIT("FGState.cpp");
+USEUNIT("FGTable.cpp");
+USEUNIT("FGTank.cpp");
+USEUNIT("FGThruster.cpp");
+USEUNIT("FGTranslation.cpp");
+USEUNIT("FGTrim.cpp");
+USEUNIT("FGTrimAxis.cpp");
+USEUNIT("FGTurboJet.cpp");
+USEUNIT("FGTurboProp.cpp");
+USEUNIT("FGTurboShaft.cpp");
+USEUNIT("FGAerodynamics.cpp");
+USEUNIT("filtersjb\FGSwitch.cpp");
+USEUNIT("filtersjb\FGFCSComponent.cpp");
+USEUNIT("filtersjb\FGFilter.cpp");
+USEUNIT("filtersjb\FGFlaps.cpp");
+USEUNIT("filtersjb\FGGain.cpp");
+USEUNIT("filtersjb\FGGradient.cpp");
+USEUNIT("filtersjb\FGSummer.cpp");
+USEUNIT("filtersjb\FGDeadBand.cpp");
+//---------------------------------------------------------------------------
+#endif
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+DEFINITIONS
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+GLOBAL DATA
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+static const char *IdSrc = "$Id$";
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+DOCUMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
+/** Standalone JSBSim main program
+    This is the wrapper program used to instantiate the JSBSim system and control
+    it. Use this program to build a version of JSBSim that can be run from the
+    command line. To get any use out of this, you will have to create a script
+    to run a test case and specify what kind of output you would like.
+    @author Jon S. Berndt
+    @version $Id$
+    @see -
+*/
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+IMPLEMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
+
 int main(int argc, char** argv)
 {
-       FGFDMExec* FDMExec;
+  FGFDMExec* FDMExec;
+  float cmd = 0.0;
+  bool result = false;
+  bool scripted = false;
 
-  if (argc != 3) {
+  if (argc == 2) {
+    FGConfigFile testFile(argv[1]);
+
+    if (!testFile.IsOpen()) {
+      cout << "Script file not opened" << endl;
+      exit(-1); 
+    }
+
+    testFile.GetNextConfigLine();
+    if (testFile.GetValue("runscript").length() <= 0) {
+      cout << "File: " << argv[1] << " is not a script file" << endl;
+      exit(-1); 
+    }
+    scripted = true;
+  } else 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;
+    cout << endl << "  Alternatively, you may specify only the name of a script file:"
+         << endl << endl << "  FDM <script file>" << endl << endl;
     exit(0);
   }
 
   FDMExec = new FGFDMExec();
 
-  FDMExec->GetAircraft()->LoadAircraft("aircraft", "engine", string(argv[1]));
-  FDMExec->GetState()->Reset("aircraft", string(argv[2]));
-
-  while (FDMExec->GetState()->Getsim_time() <= 25.0)
-  {
-    //
-    // Fake an elevator kick here after 5 seconds
-    //
-
-               if (FDMExec->GetState()->Getsim_time() > 5.0 &&
-        FDMExec->GetState()->Getsim_time() < 6.0)
-    {
-                       FDMExec->GetFCS()->SetDe(0.05);
-               } else {
-                       FDMExec->GetFCS()->SetDe(0.00);
+  if (scripted) {
+    result = FDMExec->LoadScript(argv[1]);
+    if (!result) {
+      cerr << "Script file " << argv[1] << " was not successfully loaded" << endl;
+      exit(-1);
     }
-
-    FDMExec->Run();
+  } else {
+    result = FDMExec->LoadModel("aircraft", "engine", string(argv[1]));
+    if (!result) {
+       cerr << "Aircraft file " << argv[1] << " was not found" << endl;
+           exit(-1);
+    }
+    if ( ! FDMExec->GetState()->Reset("aircraft", string(argv[1]), string(argv[2])))
+                   FDMExec->GetState()->Initialize(2000,0,0,0,0,0,0.5,0.5,40000);
   }
 
+  while (FDMExec->Run()) {}
+
   delete FDMExec;
-  
-  return 0;
-}
 
-#ifndef FGFS
-int WinMain()
-{
   return 0;
 }
-#endif