]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/JSBSim.cpp
Updated to latest JSBSim, including preliminary support for
[flightgear.git] / src / FDM / JSBSim / JSBSim.cpp
index a41a51e275680ca849508461c7f00686a9dc4069..e79d96fc78c212208482d3a64cc857af6f641831 100644 (file)
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
  Module:       JSBSim.cpp
  Author:       Jon S. Berndt
@@ -35,61 +35,9 @@ HISTORY
 --------------------------------------------------------------------------------
 08/17/99   JSB   Created
 
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 INCLUDES
-*******************************************************************************/
-
-#if __BCPLUSPLUS__  == 0x0540   // If compiling under Borland C++Builder
-#pragma hdrstop
-#include <condefs.h>
-USEUNIT("FGUtility.cpp");
-USEUNIT("FGAtmosphere.cpp");
-USEUNIT("FGAuxiliary.cpp");
-USEUNIT("FGCoefficient.cpp");
-USEUNIT("FGConfigFile.cpp");
-USEUNIT("FGControls.cpp");
-USEUNIT("FGEngine.cpp");
-USEUNIT("FGFCS.cpp");
-USEUNIT("FGFDMExec.cpp");
-USEUNIT("FGfdmSocket.cpp");
-USEUNIT("FGInitialCondition.cpp");
-USEUNIT("FGLGear.cpp");
-USEUNIT("FGMatrix.cpp");
-USEUNIT("FGModel.cpp");
-USEUNIT("FGOutput.cpp");
-USEUNIT("FGPosition.cpp");
-USEUNIT("FGRotation.cpp");
-USEUNIT("FGState.cpp");
-USEUNIT("FGTank.cpp");
-USEUNIT("FGTranslation.cpp");
-USEUNIT("FGAircraft.cpp");
-USERES("JSBSim.res");
-USEUNIT("filtersjb\FGfcsComponent.cpp");
-USEUNIT("filtersjb\FGSwitch.cpp");
-USEUNIT("filtersjb\FGFilter.cpp");
-USEUNIT("filtersjb\FGGain.cpp");
-USEUNIT("filtersjb\FGGradient.cpp");
-USEUNIT("filtersjb\FGSummer.cpp");
-USEUNIT("filtersjb\FGDeadBand.cpp");
-USEUNIT("filtersjb\FGFlaps.cpp");
-USEFILE("JSBSim.cxx");
-USEUNIT("FGForce.cpp");
-USEUNIT("FGInertial.cpp");
-USEUNIT("FGNozzle.cpp");
-USEUNIT("FGPropeller.cpp");
-USEUNIT("FGRotor.cpp");
-USEUNIT("FGThruster.cpp");
-USEUNIT("FGMassBalance.cpp");
-USEUNIT("FGRocket.cpp");
-USEUNIT("FGTurboJet.cpp");
-USEUNIT("FGPiston.cpp");
-USEUNIT("FGTurboShaft.cpp");
-USEUNIT("FGPropulsion.cpp");
-USEUNIT("FGGroundReactions.cpp");
-USEUNIT("FGAerodynamics.cpp");
-//---------------------------------------------------------------------------
-#pragma argsused
-#endif
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
 #include "FGFDMExec.h"
 #include "FGRotation.h"
@@ -101,98 +49,132 @@ USEUNIT("FGAerodynamics.cpp");
 #include "FGPosition.h"
 #include "FGAuxiliary.h"
 #include "FGOutput.h"
-#include "FGInitialCondition.h"
+#include "FGConfigFile.h"
+#include "FGScript.h"
 
 #ifdef FGFS
 #include <simgear/compiler.h>
 #include STL_IOSTREAM
-#  ifdef FG_HAVE_STD_INCLUDES
-#    include <ctime>
+#else
+#  if defined(sgi) && !defined(__GNUC__)
+#    include <iostream.h>
 #  else
-#    include <time.h>
+#    include <iostream>
 #  endif
-#else
-#include <iostream>
-#include <ctime>
 #endif
 
-static const char *IdSrc = "$Header$";
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+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;
   bool result = false;
+  bool Scripted = false;
+  FGScript* Script;
 
-  if (argc != 3) {
-    cout << endl
+  if (argc != 3 && argc != 2) {
+    cerr << endl
          << "  You must enter the name of a registered aircraft and reset point:"
          << endl << endl << "  FDM <aircraft name> <reset file>" << endl;
+    cerr << endl << "  Alternatively, you may specify only the name of a script file:"
+         << endl << endl << "  FDM <script file>" << endl << endl;
     exit(0);
   }
 
   FDMExec = new FGFDMExec();
 
-  result = FDMExec->LoadModel("/home/tony/FlightGear/Aircraft", 
-                                "/home/tony/FlightGear/Engine", 
-                                  string(argv[1]));
-  
-  if (!result) {
-       cerr << "Aircraft file " << argv[1] << " was not found" << endl;
-         exit(-1);
+  if (argc == 2) { // SCRIPTED CASE
+
+    Script = new FGScript(FDMExec);
+    result = Script->LoadScript(argv[1]);
+
+    if (!result) {
+      cerr << "Script file " << argv[1] << " was not successfully loaded" << endl;
+      exit(-1);
+    }
+
+    Scripted = true;
+
+  } else {        // form jsbsim <acname> <resetfile>
+
+    if ( ! FDMExec->LoadModel("aircraft", "engine", string(argv[1]))) {
+       cerr << "  JSBSim could not be started" << endl << endl;
+      exit(-1);
+    }                   
+
+    FGInitialCondition IC(FDMExec);
+    if ( ! IC.Load("aircraft",string(argv[1]),string(argv[2]))) {
+       cerr << "Initialization unsuccessful" << endl;
+      exit(-1);
+    }
   }
-  
-  if ( ! FDMExec->GetState()->Reset("/home/tony/FlightGear/Aircraft", 
-                                       string(argv[1]), string(argv[2])))
-    FDMExec->GetState()->Initialize(2000,0,0,0,0,0,0.5,0.5,40000);
-  
-  FGInitialCondition *fgic= new FGInitialCondition(FDMExec);
-  fgic->SetUBodyFpsIC(170);
-  fgic->SetTrueHeadingDegIC(275);
-  FDMExec->RunIC(fgic);
-  cout << "FDMExec->GetTranslation()->GetVt(): " << FDMExec->GetTranslation()->GetVt() << endl;
-  cout << "FDMExec->GetPosition()->GetVn(): " << FDMExec->GetPosition()->GetVn() << endl;
-  cout << "FDMExec->GetPosition()->GetVe(): " << FDMExec->GetPosition()->GetVe() << endl;
-  cout << "FDMExec->GetAuxiliary()->GetVcalibratedKTS(): " << FDMExec->GetAuxiliary()->GetVcalibratedKTS() << endl; 
-  fgic->SetVnorthFpsIC(170);
-  cout << "fgic->GetUBodyFpsIC(): " << fgic->GetUBodyFpsIC() << endl;
-  cout << "fgic->GetVBodyFpsIC(): " << fgic->GetVBodyFpsIC() << endl;
-  cout << "fgic->GetWBodyFpsIC(): " << fgic->GetWBodyFpsIC() << endl;
-  FDMExec->RunIC(fgic);
-  cout << "FDMExec->GetTranslation()->GetVt(): " << FDMExec->GetTranslation()->GetVt() << endl;
-  cout << "FDMExec->GetPosition()->GetVn(): " << FDMExec->GetPosition()->GetVn() << endl;
-  cout << "FDMExec->GetPosition()->GetVe(): " << FDMExec->GetPosition()->GetVe() << endl;
-  cout << "FDMExec->GetAuxiliary()->GetVcalibratedKTS(): " << FDMExec->GetAuxiliary()->GetVcalibratedKTS() << endl; 
-  
-  /* float cmd = 0.0;
-
-  while (FDMExec->GetState()->Getsim_time() <= 10.0)
-  {
-    // Fake an elevator ramp here after 1 second, hold for one second, ramp down
-    
-    if (FDMExec->GetState()->Getsim_time() >= 1.00 &&
-        FDMExec->GetState()->Getsim_time() < 2.0)
-    {
-      cmd = -(FDMExec->GetState()->Getsim_time() - 1.00)/2.0;
-    } else if (FDMExec->GetState()->Getsim_time() >= 2.00 &&
-        FDMExec->GetState()->Getsim_time() < 6.0)
-    {
-      cmd = -1.00/2.0;
-    } else if (FDMExec->GetState()->Getsim_time() >= 6.00 &&
-        FDMExec->GetState()->Getsim_time() < 7.0)
-    {
-      cmd = -(7.0 - FDMExec->GetState()->Getsim_time())/2.0;
-    } else {
-      cmd = 0.00;
+
+//
+// RUN loop. MESSAGES are read inside the Run() loop and output as necessary.
+//
+
+  FGJSBBase::Message* msg;
+  result = FDMExec->Run();
+  while (result) {
+    while (FDMExec->ReadMessage()) {
+      msg = FDMExec->ProcessMessage();
+      switch (msg->type) {
+      case FGJSBBase::Message::eText:
+        cout << msg->messageId << ": " << msg->text << endl;
+        break;
+      case FGJSBBase::Message::eBool:
+        cout << msg->messageId << ": " << msg->text << " " << msg->bVal << endl;
+        break;
+      case FGJSBBase::Message::eInteger:
+        cout << msg->messageId << ": " << msg->text << " " << msg->iVal << endl;
+        break;
+      case FGJSBBase::Message::eDouble:
+        cout << msg->messageId << ": " << msg->text << " " << msg->dVal << endl;
+        break;
+      default:
+        cerr << "Unrecognized message type." << endl;
+             break;
+      }
     }
-    FDMExec->GetFCS()->SetDeCmd(cmd);    // input between -1 and 1
-    
-    FDMExec->Run();
+
+    if (Scripted) {
+      if (!Script->RunScript()) break;
+    }
+
+    result = FDMExec->Run();
   }
- */
 
   delete FDMExec;
 
   return 0;
 }
-
-