]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGOutput.cpp
Check return value of FDM::init().
[flightgear.git] / src / FDM / JSBSim / FGOutput.cpp
index e7aa254c61601bb1d54d0739d4d51dc3b2c56b52..e61bf5a408d5260242364efff456a63b6a812ca1 100644 (file)
@@ -28,8 +28,7 @@
 FUNCTIONAL DESCRIPTION
 --------------------------------------------------------------------------------
 This is the place where you create output routines to dump data for perusal
-later. Some machines may not support the ncurses console output. Borland is one
-of those environments which does not, so the ncurses stuff is commented out.
+later. 
 
 HISTORY
 --------------------------------------------------------------------------------
@@ -39,21 +38,6 @@ HISTORY
 INCLUDES
 *******************************************************************************/
 
-#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>
-#endif
-
 #include "FGOutput.h"
 #include "FGState.h"
 #include "FGFDMExec.h"
@@ -65,6 +49,9 @@ INCLUDES
 #include "FGPosition.h"
 #include "FGAuxiliary.h"
 
+static const char *IdSrc = "$Header$";
+static const char *IdHdr = ID_OUTPUT;
+
 /*******************************************************************************
 ************************************ CODE **************************************
 *******************************************************************************/
@@ -72,157 +59,461 @@ INCLUDES
 FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
 {
   Name = "FGOutput";
-  FirstPass = true;
-#ifdef HAVE_CURSES
-  initscr();
-  cbreak();
-  noecho();
+  sFirstPass = dFirstPass = true;
+  socket = 0;
+  Type = otNone;
+  Filename = "JSBSim.out";
+  SubSystems = 0;
+  enabled = true;
+  
+#ifdef FG_WITH_JSBSIM_SOCKET
+  socket = new FGfdmSocket("localhost",1138);
 #endif
 }
 
+/******************************************************************************/
 
 FGOutput::~FGOutput(void)
 {
+  if (socket) delete socket;
 }
 
+/******************************************************************************/
 
 bool FGOutput::Run(void)
 {
-  if (!FGModel::Run()) {
-    DelimitedOutput();
-//    ConsoleOutput();
-  } else {
+  if (enabled) {
+    if (!FGModel::Run()) {
+
+      if (Type == otSocket) {
+        SocketOutput();
+      } else if (Type == otCSV) {
+        if (Filename != "COUT" && Filename != "cout" && Filename.size() > 0) {
+          DelimitedOutput(Filename);
+        } else {
+          DelimitedOutput();
+        }
+      } else if (Type == otTerminal) {
+        // Not done yet
+      } else if (Type == otNone) {
+        // Do nothing
+      } else {
+        // Not a valid type of output
+      }
+
+    } else {
+    }
   }
   return false;
 }
 
+/******************************************************************************/
 
-void FGOutput::ConsoleOutput(void)
+void FGOutput::SetType(string type)
 {
-#ifdef HAVE_CURSES
-  string buffer;
-
-  clear();
-  move(1,1);  insstr("Quaternions");
-  move(2,5);  insstr("Q0");
-  move(2,16); insstr("Q1");
-  move(2,27); insstr("Q2");
-  move(2,38); insstr("Q3");
+  if (type == "CSV") {
+    Type = otCSV;
+  } else if (type == "TABULAR") {
+    Type = otTab;
+  } else if (type == "SOCKET") {
+    Type = otSocket;
+  } else if (type == "TERMINAL") {
+    Type = otTerminal;
+  } else if (type != "NONE"){
+    Type = otUnknown;
+    cerr << "Unknown type of output specified in config file" << endl;
+  }
+}
 
-  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));
+void FGOutput::DelimitedOutput(void)
+{
+  if (dFirstPass) {
+    cout << "Time";
+    if (SubSystems & FGAircraft::ssSimulation) {
+      // Nothing here, yet
+    }
+    if (SubSystems & FGAircraft::ssAerosurfaces) {
+      cout << ", ";
+      cout << "Throttle, ";
+      cout << "Aileron Cmd, ";
+      cout << "Elevator Cmd, ";
+      cout << "Rudder Cmd, ";
+      cout << "Aileron Pos, ";
+      cout << "Elevator Pos, ";
+      cout << "Rudder Pos";
+    }
+    if (SubSystems & FGAircraft::ssRates) {
+      cout << ", ";
+      cout << "P, Q, R";
+    }
+    if (SubSystems & FGAircraft::ssVelocities) {
+      cout << ", ";
+      cout << "QBar, ";
+      cout << "Vtotal, ";
+      cout << "U, V, W, ";
+      cout << "Vn, Ve, Vd";
+    }
+    if (SubSystems & FGAircraft::ssForces) {
+      cout << ", ";
+      cout << "XsForce, YsForce, ZsForce, ";
+      cout << "Xforce, Yforce, Zforce";
+    }
+    if (SubSystems & FGAircraft::ssMoments) {
+      cout << ", ";
+      cout << "L, M, N";
+    }
+    if (SubSystems & FGAircraft::ssAtmosphere) {
+      cout << ", ";
+      cout << "Rho";
+    }
+    if (SubSystems & FGAircraft::ssMassProps) {
+      cout << ", ";
+      cout << "Ixx, ";
+      cout << "Iyy, ";
+      cout << "Izz, ";
+      cout << "Ixz, ";
+      cout << "Mass, ";
+      cout << "Xcg, Ycg, Zcg";
+    }
+    if (SubSystems & FGAircraft::ssPosition) {
+      cout << ", ";
+      cout << "Altitude, ";
+      cout << "Phi, Tht, Psi, ";
+      cout << "Alpha, ";
+      cout << "Latitude, ";
+      cout << "Longitude, ";
+      cout << "Distance AGL, ";
+      cout << "Runway Radius";
+    }
+    if (SubSystems & FGAircraft::ssCoefficients) {
+      cout << ", ";
+      cout << Aircraft->GetCoefficientStrings();
+    }
+    if (SubSystems & FGAircraft::ssGroundReactions) {
+      cout << ", ";
+      cout << Aircraft->GetGroundReactionStrings();
+    }
 
-  move(2,46); insstr("Phi");
-  move(2,55); insstr("Tht");
-  move(2,64); insstr("Psi");
+    cout << endl;
+    dFirstPass = false;
+  }
 
-  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());
+  cout << State->Getsim_time();
+  if (SubSystems & FGAircraft::ssSimulation) {
+  }
+  if (SubSystems & FGAircraft::ssAerosurfaces) {
+    cout << ", ";
+    cout << FCS->GetThrottlePos(0) << ", ";
+    cout << FCS->GetDaCmd() << ", ";
+    cout << FCS->GetDeCmd() << ", ";
+    cout << FCS->GetDrCmd() << ", ";
+    cout << FCS->GetDaPos() << ", ";
+    cout << FCS->GetDePos() << ", ";
+    cout << FCS->GetDrPos();
+  }
+  if (SubSystems & FGAircraft::ssRates) {
+    cout << ", ";
+    cout << Rotation->GetPQR();
+  }
+  if (SubSystems & FGAircraft::ssVelocities) {
+    cout << ", ";
+    cout << Translation->Getqbar() << ", ";
+    cout << Translation->GetVt() << ", ";
+    cout << Translation->GetUVW() << ", ";
+    cout << Position->GetVel();
+  }
+  if (SubSystems & FGAircraft::ssForces) {
+    cout << ", ";
+    cout << Aircraft->GetvFs() << ", ";
+    cout << Aircraft->GetForces();
+  }
+  if (SubSystems & FGAircraft::ssMoments) {
+    cout << ", ";
+    cout << Aircraft->GetMoments();
+  }
+  if (SubSystems & FGAircraft::ssAtmosphere) {
+    cout << ", ";
+    cout << Atmosphere->GetDensity();
+  }
+  if (SubSystems & FGAircraft::ssMassProps) {
+    cout << ", ";
+    cout << Aircraft->GetIxx() << ", ";
+    cout << Aircraft->GetIyy() << ", ";
+    cout << Aircraft->GetIzz() << ", ";
+    cout << Aircraft->GetIxz() << ", ";
+    cout << Aircraft->GetMass() << ", ";
+    cout << Aircraft->GetXYZcg();
+  }
+  if (SubSystems & FGAircraft::ssPosition) {
+    cout << ", ";
+    cout << Position->Geth() << ", ";
+    cout << Rotation->GetEuler() << ", ";
+    cout << Translation->Getalpha() << ", ";
+    cout << Position->GetLatitude() << ", ";
+    cout << Position->GetLongitude() << ", ";
+    cout << Position->GetDistanceAGL() << ", ";
+    cout << Position->GetRunwayRadius();
+  }
+  if (SubSystems & FGAircraft::ssCoefficients) {
+    cout << ", ";
+    cout << Aircraft->GetCoefficientValues();
+  }
+  if (SubSystems & FGAircraft::ssGroundReactions) {
+    cout << ", ";
+    cout << Aircraft->GetGroundReactionValues();
+  }
+  cout << endl;
+}
 
-  move(5,47); insstr("U");
-  move(5,56); insstr("V");
-  move(5,65); insstr("W");
+/******************************************************************************/
 
-  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());
+void FGOutput::DelimitedOutput(string fname)
+{
+  if (sFirstPass) {
+    datafile.open(fname.c_str());
+    datafile << "Time";
+    if (SubSystems & FGAircraft::ssSimulation) {
+      // Nothing here, yet
+    }
+    if (SubSystems & FGAircraft::ssAerosurfaces) {
+      datafile << ", ";
+      datafile << "Throttle, ";
+      datafile << "Aileron Cmd, ";
+      datafile << "Elevator Cmd, ";
+      datafile << "Rudder Cmd, ";
+      datafile << "Aileron Pos, ";
+      datafile << "Elevator Pos, ";
+      datafile << "Rudder Pos";
+    }
+    if (SubSystems & FGAircraft::ssRates) {
+      datafile << ", ";
+      datafile << "P, Q, R";
+    }
+    if (SubSystems & FGAircraft::ssVelocities) {
+      datafile << ", ";
+      datafile << "QBar, ";
+      datafile << "Vtotal, ";
+      datafile << "U, V, W, ";
+      datafile << "Vn, Ve, Vd";
+    }
+    if (SubSystems & FGAircraft::ssForces) {
+      datafile << ", ";
+      datafile << "XsForce, YsForce, ZsForce, ";
+      datafile << "Xforce, Yforce, Zforce";
+    }
+    if (SubSystems & FGAircraft::ssMoments) {
+      datafile << ", ";
+      datafile << "L, M, N";
+    }
+    if (SubSystems & FGAircraft::ssAtmosphere) {
+      datafile << ", ";
+      datafile << "Rho";
+    }
+    if (SubSystems & FGAircraft::ssMassProps) {
+      datafile << ", ";
+      datafile << "Ixx, ";
+      datafile << "Iyy, ";
+      datafile << "Izz, ";
+      datafile << "Ixz, ";
+      datafile << "Mass, ";
+      datafile << "Xcg, Ycg, Zcg";
+    }
+    if (SubSystems & FGAircraft::ssPosition) {
+      datafile << ", ";
+      datafile << "Altitude, ";
+      datafile << "Phi, Tht, Psi, ";
+      datafile << "Alpha, ";
+      datafile << "Latitude, ";
+      datafile << "Longitude, ";
+      datafile << "Distance AGL, ";
+      datafile << "Runway Radius";
+    }
+    if (SubSystems & FGAircraft::ssCoefficients) {
+      datafile << ", ";
+      datafile << Aircraft->GetCoefficientStrings();
+    }
+    if (SubSystems & FGAircraft::ssGroundReactions) {
+      datafile << ", ";
+      datafile << Aircraft->GetGroundReactionStrings();
+    }
+    datafile << endl;
+    sFirstPass = false;
+  }
 
-  move(8,47); insstr("Fx");
-  move(8,56); insstr("Fy");
-  move(8,65); insstr("Fz");
+  datafile << State->Getsim_time();
+  if (SubSystems & FGAircraft::ssSimulation) {
+  }
+  if (SubSystems & FGAircraft::ssAerosurfaces) {
+    datafile << ", ";
+    datafile << FCS->GetThrottlePos(0) << ", ";
+    datafile << FCS->GetDaCmd() << ", ";
+    datafile << FCS->GetDeCmd() << ", ";
+    datafile << FCS->GetDrCmd() << ", ";
+    datafile << FCS->GetDaPos() << ", ";
+    datafile << FCS->GetDePos() << ", ";
+    datafile << FCS->GetDrPos();
+  }
+  if (SubSystems & FGAircraft::ssRates) {
+    datafile << ", ";
+    datafile << Rotation->GetPQR();
+  }
+  if (SubSystems & FGAircraft::ssVelocities) {
+    datafile << ", ";
+    datafile << Translation->Getqbar() << ", ";
+    datafile << Translation->GetVt() << ", ";
+    datafile << Translation->GetUVW() << ", ";
+    datafile << Position->GetVel();
+  }
+  if (SubSystems & FGAircraft::ssForces) {
+    datafile << ", ";
+    datafile << Aircraft->GetvFs() << ", ";
+    datafile << Aircraft->GetForces();
+  }
+  if (SubSystems & FGAircraft::ssMoments) {
+    datafile << ", ";
+    datafile << Aircraft->GetMoments();
+  }
+  if (SubSystems & FGAircraft::ssAtmosphere) {
+    datafile << ", ";
+    datafile << Atmosphere->GetDensity();
+  }
+  if (SubSystems & FGAircraft::ssMassProps) {
+    datafile << ", ";
+    datafile << Aircraft->GetIxx() << ", ";
+    datafile << Aircraft->GetIyy() << ", ";
+    datafile << Aircraft->GetIzz() << ", ";
+    datafile << Aircraft->GetIxz() << ", ";
+    datafile << Aircraft->GetMass() << ", ";
+    datafile << Aircraft->GetXYZcg();
+  }
+  if (SubSystems & FGAircraft::ssPosition) {
+    datafile << ", ";
+    datafile << Position->Geth() << ", ";
+    datafile << Rotation->GetEuler() << ", ";
+    datafile << Translation->Getalpha() << ", ";
+    datafile << Position->GetLatitude() << ", ";
+    datafile << Position->GetLongitude() << ", ";
+    datafile << Position->GetDistanceAGL() << ", ";
+    datafile << Position->GetRunwayRadius();
+  }
+  if (SubSystems & FGAircraft::ssCoefficients) {
+    datafile << ", ";
+    datafile << Aircraft->GetCoefficientValues();
+  }
+  if (SubSystems & FGAircraft::ssGroundReactions) {
+    datafile << ", ";
+    datafile << Aircraft->GetGroundReactionValues();
+  }
+  datafile << endl;
+  datafile.flush();
+}
 
-  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");
+void FGOutput::SocketOutput(void)
+{
+  string asciiData;
+  /*
+  if (socket == NULL) return;
+
+  socket->Clear();
+  if (sFirstPass) {
+    socket->Append("<LABELS>");
+    socket->Append("Time");
+    socket->Append("Altitude");
+    socket->Append("Phi");
+    socket->Append("Tht");
+    socket->Append("Psi");
+    socket->Append("Rho");
+    socket->Append("Vtotal");
+    socket->Append("U");
+    socket->Append("V");
+    socket->Append("W");
+    socket->Append("Vn");
+    socket->Append("Ve");
+    socket->Append("Vd");
+    socket->Append("Udot");
+    socket->Append("Vdot");
+    socket->Append("Wdot");
+    socket->Append("P");
+    socket->Append("Q");
+    socket->Append("R");
+    socket->Append("PDot");
+    socket->Append("QDot");
+    socket->Append("RDot");
+    socket->Append("Fx");
+    socket->Append("Fy");
+    socket->Append("Fz");
+    socket->Append("Latitude");
+    socket->Append("Longitude");
+    socket->Append("QBar");
+    socket->Append("Alpha");
+    socket->Append("L");
+    socket->Append("M");
+    socket->Append("N");
+    socket->Append("Throttle");
+    socket->Append("Aileron");
+    socket->Append("Elevator");
+    socket->Append("Rudder");
+    sFirstPass = false;
+    socket->Send();
+  }
 
-  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());
+  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(Atmosphere->GetDensity());
+  socket->Append(Translation->GetVt());
+  socket->Append(Translation->GetU());
+  socket->Append(Translation->GetV());
+  socket->Append(Translation->GetW());
+  socket->Append(Position->GetVn());
+  socket->Append(Position->GetVe());
+  socket->Append(Position->GetVd());
+  socket->Append(Translation->GetUdot());
+  socket->Append(Translation->GetVdot());
+  socket->Append(Translation->GetWdot());
+  socket->Append(Rotation->GetP());
+  socket->Append(Rotation->GetQ());
+  socket->Append(Rotation->GetR());
+  socket->Append(Rotation->GetPdot());
+  socket->Append(Rotation->GetQdot());
+  socket->Append(Rotation->GetRdot());
+  socket->Append(Aircraft->GetFx());
+  socket->Append(Aircraft->GetFy());
+  socket->Append(Aircraft->GetFz());
+  socket->Append(Position->GetLatitude());
+  socket->Append(Position->GetLongitude());
+  socket->Append(Translation->Getqbar());
+  socket->Append(Translation->Getalpha());
+  socket->Append(Aircraft->GetL());
+  socket->Append(Aircraft->GetM());
+  socket->Append(Aircraft->GetN());
+  socket->Append(FCS->GetThrottle(0));
+  socket->Append(FCS->GetDa());
+  socket->Append(FCS->GetDe());
+  socket->Append(FCS->GetDr());
+  socket->Send(); */
+}
 
-  move(14,47); insstr("Latitude");
-  move(14,57); insstr("Longitude");
-  move(14,67); insstr("Altitude");
+/******************************************************************************/
 
-  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());
+void FGOutput::SocketStatusOutput(string out_str)
+{
+  string asciiData;
 
-  refresh();
+  if (socket == NULL) return;
 
-  move(LINES-1,1);
-  refresh();
-#endif
+  socket->Clear();
+  asciiData = string("<STATUS>") + out_str;
+  socket->Append(asciiData.c_str());
+  socket->Send();
 }
 
+/******************************************************************************/
 
-void FGOutput::DelimitedOutput(void)
-{
-  if (FirstPass) {
-    cout << "Time,";
-    cout << "Altitude,";
-    cout << "Phi,";
-    cout << "Tht,";
-    cout << "Psi,";
-    cout << "Rho,";
-    cout << "Vtotal,";
-    cout << "U,";
-    cout << "V,";
-    cout << "W,";
-    cout << "Vn,";
-    cout << "Ve,";
-    cout << "Vd,";
-    cout << "Udot,";
-    cout << "Vdot,";
-    cout << "Wdot,";
-    cout << "Fx,";
-    cout << "Fy,";
-    cout << "Fz,";
-    cout << "Latitude,";
-    cout << "Longitude,";
-    cout << "QBar,";
-    cout << "Alpha";
-    cout << "L";
-    cout << "M";
-    cout << "N";
-    cout << endl;
-    FirstPass = false;
-  } else {
-    cout << State->Getsim_time() << ",";
-    cout << State->Geth() << ",";
-    cout << Rotation->Getphi() << ",";
-    cout << Rotation->Gettht() << ",";
-    cout << Rotation->Getpsi() << ",";
-    cout << Atmosphere->Getrho() << ",";
-    cout << State->GetVt() << ",";
-    cout << Translation->GetU() << ",";
-    cout << Translation->GetV() << ",";
-    cout << Translation->GetW() << ",";
-    cout << Position->GetVn() << ",";
-    cout << Position->GetVe() << ",";
-    cout << Position->GetVd() << ",";
-    cout << Translation->GetUdot() << ",";
-    cout << Translation->GetVdot() << ",";
-    cout << Translation->GetWdot() << ",";
-    cout << Aircraft->GetFx() << ",";
-    cout << Aircraft->GetFy() << ",";
-    cout << Aircraft->GetFz() << ",";
-    cout << State->Getlatitude() << ",";
-    cout << State->Getlongitude() << ",";
-    cout << State->Getqbar() << ",";
-    cout << Translation->Getalpha() << ",";
-               cout << Aircraft->GetL() << ",";
-               cout << Aircraft->GetM() << ",";
-               cout << Aircraft->GetN() << "";
-    cout << endl;
-  }
-}