]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGOutput.cpp
Frederic Bouvier:
[flightgear.git] / src / FDM / JSBSim / FGOutput.cpp
index c15d2f188656a7bb610fa219aba87856b81529df..794f8c48937c5e5a4f55a094ac2903a2d34bb88c 100644 (file)
@@ -28,7 +28,7 @@
 FUNCTIONAL DESCRIPTION
 --------------------------------------------------------------------------------
 This is the place where you create output routines to dump data for perusal
-later. 
+later.
 
 HISTORY
 --------------------------------------------------------------------------------
@@ -47,10 +47,11 @@ INCLUDES
 #include "FGGroundReactions.h"
 #include "FGAircraft.h"
 #include "FGMassBalance.h"
-#include "FGTranslation.h"
-#include "FGRotation.h"
-#include "FGPosition.h"
+#include "FGPropagate.h"
 #include "FGAuxiliary.h"
+#include "FGInertial.h"
+
+#include <iomanip>
 
 namespace JSBSim {
 
@@ -71,7 +72,7 @@ FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
   SubSystems = 0;
   enabled = true;
   outputInFileName = "";
-  
+
   Debug(0);
 }
 
@@ -80,7 +81,7 @@ FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
 FGOutput::~FGOutput()
 {
   if (socket) delete socket;
-  for (int i=0; i<OutputProperties.size(); i++) delete OutputProperties[i];
+  for (unsigned int i=0; i<OutputProperties.size(); i++) delete OutputProperties[i];
 
   Debug(1);
 }
@@ -90,22 +91,17 @@ FGOutput::~FGOutput()
 bool FGOutput::Run(void)
 {
   if (enabled) {
-    if (!FGModel::Run()) {
-
-      if (Type == otSocket) {
-        SocketOutput();
-      } else if (Type == otCSV) {
-        DelimitedOutput(Filename);
-      } else if (Type == otTerminal) {
-        // Not done yet
-      } else if (Type == otNone) {
-        // Do nothing
-      } else {
-        // Not a valid type of output
-      }
-         return false;
+    if (FGModel::Run()) return true;
+    if (Type == otSocket) {
+      SocketOutput();
+    } else if (Type == otCSV) {
+      DelimitedOutput(Filename);
+    } else if (Type == otTerminal) {
+      // Not done yet
+    } else if (Type == otNone) {
+      // Do nothing
     } else {
-         return true;
+      // Not a valid type of output
     }
   }
   return false;
@@ -134,6 +130,7 @@ void FGOutput::SetType(string type)
 void FGOutput::DelimitedOutput(string fname)
 {
   streambuf* buffer;
+  string scratch = "";
 
   if (fname == "COUT" || fname == "cout") {
     buffer = cout.rdbuf();
@@ -159,7 +156,7 @@ void FGOutput::DelimitedOutput(string fname)
       outstream << "Right Aileron Pos, ";
       outstream << "Elevator Pos, ";
       outstream << "Rudder Pos, ";
-      outstream << "Flap Pos"; 
+      outstream << "Flap Pos";
     }
     if (SubSystems & ssRates) {
       outstream << ", ";
@@ -178,10 +175,7 @@ void FGOutput::DelimitedOutput(string fname)
       outstream << ", ";
       outstream << "Drag, Side, Lift, ";
       outstream << "L/D, ";
-      outstream << "Xforce, Yforce, Zforce, ";
-      outstream << "xGravity, yGravity, zGravity, ";
-      outstream << "xCoriolis, yCoriolis, zCoriolis, ";
-      outstream << "xCentrifugal, yCentrifugal, zCentrifugal";
+      outstream << "Xforce, Yforce, Zforce";
     }
     if (SubSystems & ssMoments) {
       outstream << ", ";
@@ -195,30 +189,35 @@ void FGOutput::DelimitedOutput(string fname)
     if (SubSystems & ssMassProps) {
       outstream << ", ";
       outstream << "Ixx, ";
+      outstream << "Ixy, ";
+      outstream << "Ixz, ";
+      outstream << "Iyx, ";
       outstream << "Iyy, ";
+      outstream << "Iyz, ";
+      outstream << "Izx, ";
+      outstream << "Izy, ";
       outstream << "Izz, ";
-      outstream << "Ixz, ";
       outstream << "Mass, ";
       outstream << "Xcg, Ycg, Zcg";
     }
-    if (SubSystems & ssPosition) {
+    if (SubSystems & ssPropagate) {
       outstream << ", ";
       outstream << "Altitude, ";
       outstream << "Phi, Tht, Psi, ";
       outstream << "Alpha, ";
       outstream << "Beta, ";
-      outstream << "Latitude, ";
-      outstream << "Longitude, ";
+      outstream << "Latitude (Deg), ";
+      outstream << "Longitude (Deg), ";
       outstream << "Distance AGL, ";
       outstream << "Runway Radius";
     }
     if (SubSystems & ssCoefficients) {
-      outstream << ", ";
-      outstream << Aerodynamics->GetCoefficientStrings();
+      scratch = Aerodynamics->GetCoefficientStrings();
+      if (scratch.length() != 0) outstream << ", " << scratch;
     }
     if (SubSystems & ssFCS) {
-      outstream << ", ";
-      outstream << FCS->GetComponentStrings();
+      scratch = FCS->GetComponentStrings();
+      if (scratch.length() != 0) outstream << ", " << scratch;
     }
     if (SubSystems & ssGroundReactions) {
       outstream << ", ";
@@ -229,7 +228,7 @@ void FGOutput::DelimitedOutput(string fname)
       outstream << Propulsion->GetPropulsionStrings();
     }
     if (OutputProperties.size() > 0) {
-      for (int i=0;i<OutputProperties.size();i++) {
+      for (unsigned int i=0;i<OutputProperties.size();i++) {
         outstream << ", " << OutputProperties[i]->GetName();
       }
     }
@@ -255,25 +254,22 @@ void FGOutput::DelimitedOutput(string fname)
   }
   if (SubSystems & ssRates) {
     outstream << ", ";
-    outstream << Rotation->GetPQR() << ", ";
-    outstream << Rotation->GetPQRdot();
+    outstream << Propagate->GetPQR() << ", ";
+    outstream << Propagate->GetPQRdot();
   }
   if (SubSystems & ssVelocities) {
     outstream << ", ";
-    outstream << Translation->Getqbar() << ", ";
-    outstream << Translation->GetVt() << ", ";
-    outstream << Translation->GetUVW() << ", ";
-    outstream << Translation->GetAeroUVW() << ", ";
-    outstream << Position->GetVel();
+    outstream << Auxiliary->Getqbar() << ", ";
+    outstream << setprecision(12) << Auxiliary->GetVt() << ", ";
+    outstream << setprecision(12) << Propagate->GetUVW() << ", ";
+    outstream << Auxiliary->GetAeroUVW() << ", ";
+    outstream << Propagate->GetVel();
   }
   if (SubSystems & ssForces) {
     outstream << ", ";
     outstream << Aerodynamics->GetvFs() << ", ";
     outstream << Aerodynamics->GetLoD() << ", ";
-    outstream << Aircraft->GetForces() << ", ";
-    outstream << Inertial->GetGravity() << ", ";
-    outstream << Inertial->GetCoriolis() << ", ";
-    outstream << Inertial->GetCentrifugal();
+    outstream << Aircraft->GetForces();
   }
   if (SubSystems & ssMoments) {
     outstream << ", ";
@@ -286,31 +282,28 @@ void FGOutput::DelimitedOutput(string fname)
   }
   if (SubSystems & ssMassProps) {
     outstream << ", ";
-    outstream << MassBalance->GetIxx() << ", ";
-    outstream << MassBalance->GetIyy() << ", ";
-    outstream << MassBalance->GetIzz() << ", ";
-    outstream << MassBalance->GetIxz() << ", ";
+    outstream << MassBalance->GetJ() << ", ";
     outstream << MassBalance->GetMass() << ", ";
     outstream << MassBalance->GetXYZcg();
   }
-  if (SubSystems & ssPosition) {
+  if (SubSystems & ssPropagate) {
     outstream << ", ";
-    outstream << Position->Geth() << ", ";
-    outstream << Rotation->GetEuler() << ", ";
-    outstream << Translation->Getalpha() << ", ";
-    outstream << Translation->Getbeta() << ", ";
-    outstream << Position->GetLatitude() << ", ";
-    outstream << Position->GetLongitude() << ", ";
-    outstream << Position->GetDistanceAGL() << ", ";
-    outstream << Position->GetRunwayRadius();
+    outstream << Propagate->Geth() << ", ";
+    outstream << Propagate->GetEuler() << ", ";
+    outstream << Auxiliary->Getalpha(inDegrees) << ", ";
+    outstream << Auxiliary->Getbeta(inDegrees) << ", ";
+    outstream << Propagate->GetLocation().GetLatitudeDeg() << ", ";
+    outstream << Propagate->GetLocation().GetLongitudeDeg() << ", ";
+    outstream << Propagate->GetDistanceAGL() << ", ";
+    outstream << Propagate->GetRunwayRadius();
   }
   if (SubSystems & ssCoefficients) {
-    outstream << ", ";
-    outstream << Aerodynamics->GetCoefficientValues();
+    scratch = Aerodynamics->GetCoefficientValues();
+    if (scratch.length() != 0) outstream << ", " << scratch;
   }
   if (SubSystems & ssFCS) {
-    outstream << ", ";
-    outstream << FCS->GetComponentValues();
+    scratch = FCS->GetComponentValues();
+    if (scratch.length() != 0) outstream << ", " << scratch;
   }
   if (SubSystems & ssGroundReactions) {
     outstream << ", ";
@@ -321,7 +314,7 @@ void FGOutput::DelimitedOutput(string fname)
     outstream << Propulsion->GetPropulsionValues();
   }
 
-  for (int i=0;i<OutputProperties.size();i++) {
+  for (unsigned int i=0;i<OutputProperties.size();i++) {
     outstream << ", " << OutputProperties[i]->getDoubleValue();
   }
 
@@ -369,8 +362,8 @@ void FGOutput::SocketOutput(void)
     socket->Append("Fx");
     socket->Append("Fy");
     socket->Append("Fz");
-    socket->Append("Latitude");
-    socket->Append("Longitude");
+    socket->Append("Latitude (Deg)");
+    socket->Append("Longitude (Deg)");
     socket->Append("QBar");
     socket->Append("Alpha");
     socket->Append("L");
@@ -387,37 +380,37 @@ void FGOutput::SocketOutput(void)
 
   socket->Clear();
   socket->Append(State->Getsim_time());
-  socket->Append(Position->Geth());
-  socket->Append(Rotation->Getphi());
-  socket->Append(Rotation->Gettht());
-  socket->Append(Rotation->Getpsi());
+  socket->Append(Propagate->Geth());
+  socket->Append(Propagate->Getphi());
+  socket->Append(Propagate->Gettht());
+  socket->Append(Propagate->Getpsi());
   socket->Append(Atmosphere->GetDensity());
-  socket->Append(Translation->GetVt());
-  socket->Append(Translation->GetUVW(eU));
-  socket->Append(Translation->GetUVW(eV));
-  socket->Append(Translation->GetUVW(eW));
-  socket->Append(Translation->GetAeroUVW(eU));
-  socket->Append(Translation->GetAeroUVW(eV));
-  socket->Append(Translation->GetAeroUVW(eW));
-  socket->Append(Position->GetVn());
-  socket->Append(Position->GetVe());
-  socket->Append(Position->GetVd());
-  socket->Append(Translation->GetUVWdot(eU));
-  socket->Append(Translation->GetUVWdot(eV));
-  socket->Append(Translation->GetUVWdot(eW));
-  socket->Append(Rotation->GetPQR(eP));
-  socket->Append(Rotation->GetPQR(eQ));
-  socket->Append(Rotation->GetPQR(eR));
-  socket->Append(Rotation->GetPQRdot(eP));
-  socket->Append(Rotation->GetPQRdot(eQ));
-  socket->Append(Rotation->GetPQRdot(eR));
+  socket->Append(Auxiliary->GetVt());
+  socket->Append(Propagate->GetUVW(eU));
+  socket->Append(Propagate->GetUVW(eV));
+  socket->Append(Propagate->GetUVW(eW));
+  socket->Append(Auxiliary->GetAeroUVW(eU));
+  socket->Append(Auxiliary->GetAeroUVW(eV));
+  socket->Append(Auxiliary->GetAeroUVW(eW));
+  socket->Append(Propagate->GetVel(eNorth));
+  socket->Append(Propagate->GetVel(eEast));
+  socket->Append(Propagate->GetVel(eDown));
+  socket->Append(Propagate->GetUVWdot(eU));
+  socket->Append(Propagate->GetUVWdot(eV));
+  socket->Append(Propagate->GetUVWdot(eW));
+  socket->Append(Propagate->GetPQR(eP));
+  socket->Append(Propagate->GetPQR(eQ));
+  socket->Append(Propagate->GetPQR(eR));
+  socket->Append(Propagate->GetPQRdot(eP));
+  socket->Append(Propagate->GetPQRdot(eQ));
+  socket->Append(Propagate->GetPQRdot(eR));
   socket->Append(Aircraft->GetForces(eX));
   socket->Append(Aircraft->GetForces(eY));
   socket->Append(Aircraft->GetForces(eZ));
-  socket->Append(Position->GetLatitude());
-  socket->Append(Position->GetLongitude());
-  socket->Append(Translation->Getqbar());
-  socket->Append(Translation->Getalpha());
+  socket->Append(Propagate->GetLocation().GetLatitudeDeg());
+  socket->Append(Propagate->GetLocation().GetLongitudeDeg());
+  socket->Append(Auxiliary->Getqbar());
+  socket->Append(Auxiliary->Getalpha(inDegrees));
   socket->Append(Aircraft->GetMoments(eL));
   socket->Append(Aircraft->GetMoments(eM));
   socket->Append(Aircraft->GetMoments(eN));
@@ -452,6 +445,7 @@ bool FGOutput::Load(FGConfigFile* AC_cfg)
   int OutRate = 0;
   FGConfigFile* Output_cfg;
   string property;
+  unsigned int port;
 
 # ifndef macintosh
     separator = "/";
@@ -462,13 +456,13 @@ bool FGOutput::Load(FGConfigFile* AC_cfg)
   name = AC_cfg->GetValue("NAME");
   fname = AC_cfg->GetValue("FILE");
   token = AC_cfg->GetValue("TYPE");
+  port = atoi(AC_cfg->GetValue("PORT").c_str());
+
   Output->SetType(token);
 
-#if defined( FG_WITH_JSBSIM_SOCKET ) || !defined( FGFS )
   if (token == "SOCKET") {
-    socket = new FGfdmSocket("localhost",1138);
+    socket = new FGfdmSocket(name,port);
   }
-#endif
 
   if (!fname.empty()) {
     outputInFileName = FDMExec->GetAircraftPath() + separator
@@ -522,7 +516,7 @@ bool FGOutput::Load(FGConfigFile* AC_cfg)
     }
     if (parameter == "POSITION") {
       *Output_cfg >> parameter;
-      if (parameter == "ON") SubSystems += ssPosition;
+      if (parameter == "ON") SubSystems += ssPropagate;
     }
     if (parameter == "COEFFICIENTS") {
       *Output_cfg >> parameter;
@@ -604,7 +598,7 @@ void FGOutput::Debug(int from)
         cout << "  No log output" << endl;
         break;
       }
-      
+
       if (SubSystems & ssSimulation)      cout << "    Simulation parameters logged" << endl;
       if (SubSystems & ssAerosurfaces)    cout << "    Aerosurface parameters logged" << endl;
       if (SubSystems & ssRates)           cout << "    Rate parameters logged" << endl;
@@ -614,10 +608,14 @@ void FGOutput::Debug(int from)
       if (SubSystems & ssAtmosphere)      cout << "    Atmosphere parameters logged" << endl;
       if (SubSystems & ssMassProps)       cout << "    Mass parameters logged" << endl;
       if (SubSystems & ssCoefficients)    cout << "    Coefficient parameters logged" << endl;
-      if (SubSystems & ssPosition)        cout << "    Position parameters logged" << endl;
+      if (SubSystems & ssPropagate)       cout << "    Propagate parameters logged" << endl;
       if (SubSystems & ssGroundReactions) cout << "    Ground parameters logged" << endl;
       if (SubSystems & ssFCS)             cout << "    FCS parameters logged" << endl;
       if (SubSystems & ssPropulsion)      cout << "    Propulsion parameters logged" << endl;
+      if (OutputProperties.size() > 0)    cout << "    Properties logged:" << endl;
+      for (unsigned int i=0;i<OutputProperties.size();i++) {
+        cout << "      - " << OutputProperties[i]->GetName() << endl;
+      }
     }
   }
   if (debug_lvl & 2 ) { // Instantiation/Destruction notification