]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGOutput.cpp
builddir -> srcdir so builds can be done outside the master source directory.
[flightgear.git] / src / FDM / JSBSim / FGOutput.cpp
index 9628d5309d265fde3e654622f1a205f6a5191056..a9fc0cac1bc3015f9ed1b032d305e992db5a3651 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
 --------------------------------------------------------------------------------
@@ -59,226 +58,359 @@ FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
   Name = "FGOutput";
   sFirstPass = dFirstPass = true;
   socket = 0;
+  Type = otNone;
+  Filename = "JSBSim.out";
+  SubSystems = 0;
+  
 #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()) {
-//    SocketOutput();
-//    DelimitedOutput("JSBSimData.csv");
-//    DelimitedOutput();
+
+    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::SetType(string type)
+{
+  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;
+  }
+}
+
+/******************************************************************************/
 
 void FGOutput::DelimitedOutput(void)
 {
   if (dFirstPass) {
-    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 << "P,";
-    cout << "Q,";
-    cout << "R,";
-    cout << "PDot,";
-    cout << "QDot,";
-    cout << "RDot,";
-    cout << "Fx,";
-    cout << "Fy,";
-    cout << "Fz,";
-    cout << "Latitude,";
-    cout << "Longitude,";
-    cout << "QBar,";
-    cout << "Alpha,";
-    cout << "L,";
-    cout << "M,";
-    cout << "N,";
-    cout << "Throttle,";
-    cout << "Aileron,";
-    cout << "Elevator,";
-    cout << "Rudder,";
-    cout << "Ixx,";
-    cout << "Iyy,";
-    cout << "Izz,";
-    cout << "Ixz,";
-    cout << "Mass,";
-    cout << "X CG";
+    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();
+    }
+
     cout << endl;
     dFirstPass = false;
   }
 
-  cout << State->Getsim_time() << ",";
-  cout << State->Geth() << ",";
-  cout << Rotation->Getphi() << ",";
-  cout << Rotation->Gettht() << ",";
-  cout << Rotation->Getpsi() << ",";
-  cout << Atmosphere->GetDensity() << ",";
-  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 << Rotation->GetP() << ",";
-  cout << Rotation->GetQ() << ",";
-  cout << Rotation->GetR() << ",";
-  cout << Rotation->GetPdot() << ",";
-  cout << Rotation->GetQdot() << ",";
-  cout << Rotation->GetRdot() << ",";
-  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 << FCS->GetThrottle(0) << ",";
-  cout << FCS->GetDa() << ",";
-  cout << FCS->GetDe() << ",";
-  cout << FCS->GetDr() << ",";
-  cout << Aircraft->GetIxx() << ",";
-  cout << Aircraft->GetIyy() << ",";
-  cout << Aircraft->GetIzz() << ",";
-  cout << Aircraft->GetIxz() << ",";
-  cout << Aircraft->GetMass() << ",";
-  cout << Aircraft->GetXcg() << "";
+  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;
-
 }
 
+/******************************************************************************/
 
 void FGOutput::DelimitedOutput(string fname)
 {
   if (sFirstPass) {
     datafile.open(fname.c_str());
-    datafile << "Time,";
-    datafile << "Altitude,";
-    datafile << "Phi,";
-    datafile << "Tht,";
-    datafile << "Psi,";
-    datafile << "Rho,";
-    datafile << "Vtotal,";
-    datafile << "U,";
-    datafile << "V,";
-    datafile << "W,";
-    datafile << "Vn,";
-    datafile << "Ve,";
-    datafile << "Vd,";
-    datafile << "Udot,";
-    datafile << "Vdot,";
-    datafile << "Wdot,";
-    datafile << "P,";
-    datafile << "Q,";
-    datafile << "R,";
-    datafile << "PDot,";
-    datafile << "QDot,";
-    datafile << "RDot,";
-    datafile << "Fx,";
-    datafile << "Fy,";
-    datafile << "Fz,";
-    datafile << "Latitude,";
-    datafile << "Longitude,";
-    datafile << "QBar,";
-    datafile << "Alpha,";
-    datafile << "L,";
-    datafile << "M,";
-    datafile << "N,";
-    datafile << "Throttle,";
-    datafile << "Aileron,";
-    datafile << "Elevator,";
-    datafile << "Rudder,";
-    datafile << "Ixx,";
-    datafile << "Iyy,";
-    datafile << "Izz,";
-    datafile << "Ixz,";
-    datafile << "Mass,";
-    datafile << "X CG";
+    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;
   }
 
-  datafile << State->Getsim_time() << ",";
-  datafile << State->Geth() << ",";
-  datafile << Rotation->Getphi() << ",";
-  datafile << Rotation->Gettht() << ",";
-  datafile << Rotation->Getpsi() << ",";
-  datafile << Atmosphere->GetDensity() << ",";
-  datafile << State->GetVt() << ",";
-  datafile << Translation->GetU() << ",";
-  datafile << Translation->GetV() << ",";
-  datafile << Translation->GetW() << ",";
-  datafile << Position->GetVn() << ",";
-  datafile << Position->GetVe() << ",";
-  datafile << Position->GetVd() << ",";
-  datafile << Translation->GetUdot() << ",";
-  datafile << Translation->GetVdot() << ",";
-  datafile << Translation->GetWdot() << ",";
-  datafile << Rotation->GetP() << ",";
-  datafile << Rotation->GetQ() << ",";
-  datafile << Rotation->GetR() << ",";
-  datafile << Rotation->GetPdot() << ",";
-  datafile << Rotation->GetQdot() << ",";
-  datafile << Rotation->GetRdot() << ",";
-  datafile << Aircraft->GetFx() << ",";
-  datafile << Aircraft->GetFy() << ",";
-  datafile << Aircraft->GetFz() << ",";
-  datafile << State->Getlatitude() << ",";
-  datafile << State->Getlongitude() << ",";
-  datafile << State->Getqbar() << ",";
-  datafile << Translation->Getalpha() << ",";
-  datafile << Aircraft->GetL() << ",";
-  datafile << Aircraft->GetM() << ",";
-  datafile << Aircraft->GetN() << ",";
-  datafile << FCS->GetThrottle(0) << ",";
-  datafile << FCS->GetDa() << ",";
-  datafile << FCS->GetDe() << ",";
-  datafile << FCS->GetDr() << ",";
-  datafile << Aircraft->GetIxx() << ",";
-  datafile << Aircraft->GetIyy() << ",";
-  datafile << Aircraft->GetIzz() << ",";
-  datafile << Aircraft->GetIxz() << ",";
-  datafile << Aircraft->GetMass() << ",";
-  datafile << Aircraft->GetXcg() << "";
+  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();
 }
 
+/******************************************************************************/
+
 void FGOutput::SocketOutput(void)
 {
   string asciiData;
-
+  /*
   if (socket <= 0) return;
 
   socket->Clear();
@@ -326,12 +458,12 @@ void FGOutput::SocketOutput(void)
 
   socket->Clear();
   socket->Append(State->Getsim_time());
-  socket->Append(State->Geth());
+  socket->Append(Position->Geth());
   socket->Append(Rotation->Getphi());
   socket->Append(Rotation->Gettht());
   socket->Append(Rotation->Getpsi());
   socket->Append(Atmosphere->GetDensity());
-  socket->Append(State->GetVt());
+  socket->Append(Translation->GetVt());
   socket->Append(Translation->GetU());
   socket->Append(Translation->GetV());
   socket->Append(Translation->GetW());
@@ -350,9 +482,9 @@ void FGOutput::SocketOutput(void)
   socket->Append(Aircraft->GetFx());
   socket->Append(Aircraft->GetFy());
   socket->Append(Aircraft->GetFz());
-  socket->Append(State->Getlatitude());
-  socket->Append(State->Getlongitude());
-  socket->Append(State->Getqbar());
+  socket->Append(Position->GetLatitude());
+  socket->Append(Position->GetLongitude());
+  socket->Append(Translation->Getqbar());
   socket->Append(Translation->Getalpha());
   socket->Append(Aircraft->GetL());
   socket->Append(Aircraft->GetM());
@@ -361,9 +493,10 @@ void FGOutput::SocketOutput(void)
   socket->Append(FCS->GetDa());
   socket->Append(FCS->GetDe());
   socket->Append(FCS->GetDr());
-  socket->Send();
+  socket->Send(); */
 }
 
+/******************************************************************************/
 
 void FGOutput::SocketStatusOutput(string out_str)
 {
@@ -377,3 +510,5 @@ void FGOutput::SocketStatusOutput(string out_str)
   socket->Send();
 }
 
+/******************************************************************************/
+