X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FFDM%2FJSBSim%2Fmodels%2FFGOutput.cpp;h=f6cbcd366737989e2e527bdf45804f6f42deb935;hb=642735ab18421db87a07d6841dd720fd4615bfff;hp=4b3a95f8811c35222adf6bdf0b192a5c11afb1b6;hpb=157eb857ef36636a316947fe1eb3d9a8bea1959b;p=flightgear.git diff --git a/src/FDM/JSBSim/models/FGOutput.cpp b/src/FDM/JSBSim/models/FGOutput.cpp index 4b3a95f88..f6cbcd366 100644 --- a/src/FDM/JSBSim/models/FGOutput.cpp +++ b/src/FDM/JSBSim/models/FGOutput.cpp @@ -6,7 +6,7 @@ Purpose: Manage output of sim parameters to file or stdout Called by: FGSimExec - ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- + ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) ------------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -39,25 +39,30 @@ HISTORY INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +#include +#include +#include +#include + #include "FGOutput.h" -#include "FGState.h" #include "FGFDMExec.h" #include "FGAtmosphere.h" +#include "FGAccelerations.h" +#include "atmosphere/FGWinds.h" #include "FGFCS.h" #include "FGAerodynamics.h" #include "FGGroundReactions.h" +#include "FGExternalReactions.h" +#include "FGBuoyantForces.h" #include "FGAircraft.h" #include "FGMassBalance.h" #include "FGPropagate.h" #include "FGAuxiliary.h" #include "FGInertial.h" -#include "FGPropulsion.h" //access to FGEngine, FGTank +#include "FGPropulsion.h" +#include "models/propulsion/FGEngine.h" +#include "models/propulsion/FGTank.h" #include "models/propulsion/FGPiston.h" -#include -#include -#include - -#include "input_output/net_fdm.hxx" #if defined(WIN32) && !defined(__CYGWIN__) # include @@ -68,9 +73,11 @@ INCLUDES static const int endianTest = 1; #define isLittleEndian (*((char *) &endianTest ) != 0) +using namespace std; + namespace JSBSim { -static const char *IdSrc = "$Id$"; +static const char *IdSrc = "$Id: FGOutput.cpp,v 1.67 2012/04/27 12:14:56 jberndt Exp $"; static const char *IdHdr = ID_OUTPUT; // (stolen from FGFS native_fdm.cxx) @@ -125,12 +132,13 @@ FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex) Name = "FGOutput"; sFirstPass = dFirstPass = true; socket = 0; - flightGearSocket = 0; + runID_postfix = 0; Type = otNone; SubSystems = 0; enabled = true; + StartNewFile = false; delimeter = ", "; - Filename = ""; + BaseFilename = Filename = ""; DirectivesFile = ""; output_file_name = ""; @@ -144,7 +152,6 @@ FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex) FGOutput::~FGOutput() { delete socket; - delete flightGearSocket; OutputProperties.clear(); Debug(1); } @@ -153,42 +160,63 @@ FGOutput::~FGOutput() bool FGOutput::InitModel(void) { - if (!FGModel::InitModel()) return false; + if (Filename.size() > 0 && StartNewFile) { + ostringstream buf; + string::size_type dot = BaseFilename.find_last_of('.'); + if (dot != string::npos) { + buf << BaseFilename.substr(0, dot) << '_' << runID_postfix++ << BaseFilename.substr(dot); + } else { + buf << BaseFilename << '_' << runID_postfix++; + } + Filename = buf.str(); + datafile.close(); + StartNewFile = false; + dFirstPass = true; + } return true; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -bool FGOutput::Run(void) +bool FGOutput::Run(bool Holding) { - if (FGModel::Run()) return true; - - if (enabled && !State->IntegrationSuspended()&& !FDMExec->Holding()) { - if (Type == otSocket) { - SocketOutput(); - } else if (Type == otFlightGear) { - FlightGearSocketOutput(); - } else if (Type == otCSV || Type == otTab) { - DelimitedOutput(Filename); - } else if (Type == otTerminal) { - // Not done yet - } else if (Type == otNone) { - // Do nothing - } else { - // Not a valid type of output - } + if (FGModel::Run(Holding)) return true; + + if (enabled && !FDMExec->IntegrationSuspended() && !Holding) { + RunPreFunctions(); + Print(); + RunPostFunctions(); } return false; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGOutput::SetType(string type) +void FGOutput::Print(void) +{ + if (Type == otSocket) { + SocketOutput(); + } else if (Type == otFlightGear) { + FlightGearSocketOutput(); + } else if (Type == otCSV || Type == otTab) { + DelimitedOutput(Filename); + } else if (Type == otTerminal) { + // Not done yet + } else if (Type == otNone) { + // Do nothing + } else { + // Not a valid type of output + } +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGOutput::SetType(const string& type) { if (type == "CSV") { Type = otCSV; - delimeter = ", "; + delimeter = ","; } else if (type == "TABULAR") { Type = otTab; delimeter = "\t"; @@ -206,15 +234,38 @@ void FGOutput::SetType(string type) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGOutput::DelimitedOutput(string fname) +void FGOutput::SetProtocol(const string& protocol) { + if (protocol == "UDP") Protocol = FGfdmSocket::ptUDP; + else if (protocol == "TCP") Protocol = FGfdmSocket::ptTCP; + else Protocol = FGfdmSocket::ptTCP; // Default to TCP +} + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGOutput::DelimitedOutput(const string& fname) +{ + const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics(); + const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary(); + const FGAircraft* Aircraft = FDMExec->GetAircraft(); + const FGAtmosphere* Atmosphere = FDMExec->GetAtmosphere(); + const FGWinds* Winds = FDMExec->GetWinds(); + const FGPropulsion* Propulsion = FDMExec->GetPropulsion(); + const FGMassBalance* MassBalance = FDMExec->GetMassBalance(); + const FGPropagate* Propagate = FDMExec->GetPropagate(); + const FGAccelerations* Accelerations = FDMExec->GetAccelerations(); + const FGFCS* FCS = FDMExec->GetFCS(); + const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions(); + const FGExternalReactions* ExternalReactions = FDMExec->GetExternalReactions(); + const FGBuoyantForces* BuoyantForces = FDMExec->GetBuoyantForces(); + streambuf* buffer; string scratch = ""; if (fname == "COUT" || fname == "cout") { buffer = cout.rdbuf(); } else { - datafile.open(fname.c_str()); + if (!datafile.is_open()) datafile.open(fname.c_str()); buffer = datafile.rdbuf(); } @@ -242,7 +293,8 @@ void FGOutput::DelimitedOutput(string fname) if (SubSystems & ssRates) { outstream << delimeter; outstream << "P (deg/s)" + delimeter + "Q (deg/s)" + delimeter + "R (deg/s)" + delimeter; - outstream << "P dot (deg/s^2)" + delimeter + "Q dot (deg/s^2)" + delimeter + "R dot (deg/s^2)"; + outstream << "P dot (deg/s^2)" + delimeter + "Q dot (deg/s^2)" + delimeter + "R dot (deg/s^2)" + delimeter; + outstream << "P_{inertial} (deg/s)" + delimeter + "Q_{inertial} (deg/s)" + delimeter + "R_{inertial} (deg/s)"; } if (SubSystems & ssVelocities) { outstream << delimeter; @@ -252,17 +304,29 @@ void FGOutput::DelimitedOutput(string fname) outstream << "V_{Inertial} (ft/s)" + delimeter; outstream << "UBody" + delimeter + "VBody" + delimeter + "WBody" + delimeter; outstream << "Aero V_{X Body} (ft/s)" + delimeter + "Aero V_{Y Body} (ft/s)" + delimeter + "Aero V_{Z Body} (ft/s)" + delimeter; + outstream << "V_{X_{inertial}} (ft/s)" + delimeter + "V_{Y_{inertial}} (ft/s)" + delimeter + "V_{Z_{inertial}} (ft/s)" + delimeter; + outstream << "V_{X_{ecef}} (ft/s)" + delimeter + "V_{Y_{ecef}} (ft/s)" + delimeter + "V_{Z_{ecef}} (ft/s)" + delimeter; outstream << "V_{North} (ft/s)" + delimeter + "V_{East} (ft/s)" + delimeter + "V_{Down} (ft/s)"; } if (SubSystems & ssForces) { outstream << delimeter; outstream << "F_{Drag} (lbs)" + delimeter + "F_{Side} (lbs)" + delimeter + "F_{Lift} (lbs)" + delimeter; outstream << "L/D" + delimeter; - outstream << "F_X (lbs)" + delimeter + "F_Y (lbs)" + delimeter + "F_Z (lbs)"; + outstream << "F_{Aero x} (lbs)" + delimeter + "F_{Aero y} (lbs)" + delimeter + "F_{Aero z} (lbs)" + delimeter; + outstream << "F_{Prop x} (lbs)" + delimeter + "F_{Prop y} (lbs)" + delimeter + "F_{Prop z} (lbs)" + delimeter; + outstream << "F_{Gear x} (lbs)" + delimeter + "F_{Gear y} (lbs)" + delimeter + "F_{Gear z} (lbs)" + delimeter; + outstream << "F_{Ext x} (lbs)" + delimeter + "F_{Ext y} (lbs)" + delimeter + "F_{Ext z} (lbs)" + delimeter; + outstream << "F_{Buoyant x} (lbs)" + delimeter + "F_{Buoyant y} (lbs)" + delimeter + "F_{Buoyant z} (lbs)" + delimeter; + outstream << "F_{Total x} (lbs)" + delimeter + "F_{Total y} (lbs)" + delimeter + "F_{Total z} (lbs)"; } if (SubSystems & ssMoments) { outstream << delimeter; - outstream << "L (ft-lbs)" + delimeter + "M (ft-lbs)" + delimeter + "N (ft-lbs)"; + outstream << "L_{Aero} (ft-lbs)" + delimeter + "M_{Aero} (ft-lbs)" + delimeter + "N_{Aero} (ft-lbs)" + delimeter; + outstream << "L_{Prop} (ft-lbs)" + delimeter + "M_{Prop} (ft-lbs)" + delimeter + "N_{Prop} (ft-lbs)" + delimeter; + outstream << "L_{Gear} (ft-lbs)" + delimeter + "M_{Gear} (ft-lbs)" + delimeter + "N_{Gear} (ft-lbs)" + delimeter; + outstream << "L_{ext} (ft-lbs)" + delimeter + "M_{ext} (ft-lbs)" + delimeter + "N_{ext} (ft-lbs)" + delimeter; + outstream << "L_{Buoyant} (ft-lbs)" + delimeter + "M_{Buoyant} (ft-lbs)" + delimeter + "N_{Buoyant} (ft-lbs)" + delimeter; + outstream << "L_{Total} (ft-lbs)" + delimeter + "M_{Total} (ft-lbs)" + delimeter + "N_{Total} (ft-lbs)"; } if (SubSystems & ssAtmosphere) { outstream << delimeter; @@ -292,19 +356,21 @@ void FGOutput::DelimitedOutput(string fname) } if (SubSystems & ssPropagate) { outstream << delimeter; - outstream << "Altitude (ft)" + delimeter; + outstream << "Altitude ASL (ft)" + delimeter; + outstream << "Altitude AGL (ft)" + delimeter; outstream << "Phi (deg)" + delimeter + "Theta (deg)" + delimeter + "Psi (deg)" + delimeter; outstream << "Alpha (deg)" + delimeter; outstream << "Beta (deg)" + delimeter; outstream << "Latitude (deg)" + delimeter; outstream << "Longitude (deg)" + delimeter; - outstream << "ECEF X (ft)" + delimeter + "ECEF Y (ft)" + delimeter + "ECEF Z (ft)" + delimeter; - outstream << "EPA (deg)" + delimeter; + outstream << "X_{ECI} (ft)" + delimeter + "Y_{ECI} (ft)" + delimeter + "Z_{ECI} (ft)" + delimeter; + outstream << "X_{ECEF} (ft)" + delimeter + "Y_{ECEF} (ft)" + delimeter + "Z_{ECEF} (ft)" + delimeter; + outstream << "Earth Position Angle (deg)" + delimeter; outstream << "Distance AGL (ft)" + delimeter; - outstream << "Runway Radius (ft)"; + outstream << "Terrain Elevation (ft)"; } - if (SubSystems & ssCoefficients) { - scratch = Aerodynamics->GetCoefficientStrings(delimeter); + if (SubSystems & ssAeroFunctions) { + scratch = Aerodynamics->GetAeroFunctionStrings(delimeter); if (scratch.length() != 0) outstream << delimeter << scratch; } if (SubSystems & ssFCS) { @@ -329,7 +395,7 @@ void FGOutput::DelimitedOutput(string fname) dFirstPass = false; } - outstream << State->Getsim_time(); + outstream << FDMExec->GetSimTime(); if (SubSystems & ssSimulation) { } if (SubSystems & ssAerosurfaces) { @@ -347,7 +413,8 @@ void FGOutput::DelimitedOutput(string fname) if (SubSystems & ssRates) { outstream << delimeter; outstream << (radtodeg*Propagate->GetPQR()).Dump(delimeter) << delimeter; - outstream << (radtodeg*Propagate->GetPQRdot()).Dump(delimeter); + outstream << (radtodeg*Accelerations->GetPQRdot()).Dump(delimeter) << delimeter; + outstream << (radtodeg*Propagate->GetPQRi()).Dump(delimeter); } if (SubSystems & ssVelocities) { outstream << delimeter; @@ -357,16 +424,29 @@ void FGOutput::DelimitedOutput(string fname) outstream << Propagate->GetInertialVelocityMagnitude() << delimeter; outstream << setprecision(12) << Propagate->GetUVW().Dump(delimeter) << delimeter; outstream << Auxiliary->GetAeroUVW().Dump(delimeter) << delimeter; + outstream << Propagate->GetInertialVelocity().Dump(delimeter) << delimeter; + outstream << Propagate->GetECEFVelocity().Dump(delimeter) << delimeter; outstream << Propagate->GetVel().Dump(delimeter); + outstream.precision(10); } if (SubSystems & ssForces) { outstream << delimeter; - outstream << Aerodynamics->GetvFw() << delimeter; + outstream << Aerodynamics->GetvFw().Dump(delimeter) << delimeter; outstream << Aerodynamics->GetLoD() << delimeter; + outstream << Aerodynamics->GetForces().Dump(delimeter) << delimeter; + outstream << Propulsion->GetForces().Dump(delimeter) << delimeter; + outstream << GroundReactions->GetForces().Dump(delimeter) << delimeter; + outstream << ExternalReactions->GetForces().Dump(delimeter) << delimeter; + outstream << BuoyantForces->GetForces().Dump(delimeter) << delimeter; outstream << Aircraft->GetForces().Dump(delimeter); } if (SubSystems & ssMoments) { outstream << delimeter; + outstream << Aerodynamics->GetMoments().Dump(delimeter) << delimeter; + outstream << Propulsion->GetMoments().Dump(delimeter) << delimeter; + outstream << GroundReactions->GetMoments().Dump(delimeter) << delimeter; + outstream << ExternalReactions->GetMoments().Dump(delimeter) << delimeter; + outstream << BuoyantForces->GetMoments().Dump(delimeter) << delimeter; outstream << Aircraft->GetMoments().Dump(delimeter); } if (SubSystems & ssAtmosphere) { @@ -377,31 +457,37 @@ void FGOutput::DelimitedOutput(string fname) outstream << Atmosphere->GetTemperature() << delimeter; outstream << Atmosphere->GetPressureSL() << delimeter; outstream << Atmosphere->GetPressure() << delimeter; - outstream << Atmosphere->GetTurbMagnitude() << delimeter; - outstream << Atmosphere->GetTurbDirection().Dump(delimeter) << delimeter; - outstream << Atmosphere->GetTotalWindNED().Dump(delimeter); + outstream << Winds->GetTurbMagnitude() << delimeter; + outstream << Winds->GetTurbDirection().Dump(delimeter) << delimeter; + outstream << Winds->GetTotalWindNED().Dump(delimeter); } if (SubSystems & ssMassProps) { outstream << delimeter; - outstream << MassBalance->GetJ() << delimeter; + outstream << MassBalance->GetJ().Dump(delimeter) << delimeter; outstream << MassBalance->GetMass() << delimeter; - outstream << MassBalance->GetXYZcg(); + outstream << MassBalance->GetXYZcg().Dump(delimeter); } if (SubSystems & ssPropagate) { + outstream.precision(14); outstream << delimeter; - outstream << Propagate->Geth() << delimeter; + outstream << Propagate->GetAltitudeASL() << delimeter; + outstream << Propagate->GetDistanceAGL() << delimeter; outstream << (radtodeg*Propagate->GetEuler()).Dump(delimeter) << delimeter; outstream << Auxiliary->Getalpha(inDegrees) << delimeter; outstream << Auxiliary->Getbeta(inDegrees) << delimeter; outstream << Propagate->GetLocation().GetLatitudeDeg() << delimeter; outstream << Propagate->GetLocation().GetLongitudeDeg() << delimeter; + outstream.precision(18); + outstream << ((FGColumnVector3)Propagate->GetInertialPosition()).Dump(delimeter) << delimeter; outstream << ((FGColumnVector3)Propagate->GetLocation()).Dump(delimeter) << delimeter; - outstream << Inertial->GetEarthPositionAngleDeg() << delimeter; + outstream.precision(14); + outstream << Propagate->GetEarthPositionAngleDeg() << delimeter; outstream << Propagate->GetDistanceAGL() << delimeter; - outstream << Propagate->GetRunwayRadius(); + outstream << Propagate->GetTerrainElevation(); + outstream.precision(10); } - if (SubSystems & ssCoefficients) { - scratch = Aerodynamics->GetCoefficientValues(delimeter); + if (SubSystems & ssAeroFunctions) { + scratch = Aerodynamics->GetAeroFunctionValues(delimeter); if (scratch.length() != 0) outstream << delimeter << scratch; } if (SubSystems & ssFCS) { @@ -417,9 +503,11 @@ void FGOutput::DelimitedOutput(string fname) outstream << Propulsion->GetPropulsionValues(delimeter); } + outstream.precision(18); for (unsigned int i=0;igetDoubleValue(); } + outstream.precision(10); outstream << endl; outstream.flush(); @@ -429,6 +517,11 @@ void FGOutput::DelimitedOutput(string fname) void FGOutput::SocketDataFill(FGNetFDM* net) { + const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary(); + const FGPropulsion* Propulsion = FDMExec->GetPropulsion(); + const FGPropagate* Propagate = FDMExec->GetPropagate(); + const FGFCS* FCS = FDMExec->GetFCS(); + const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions(); unsigned int i; // Version @@ -437,7 +530,7 @@ void FGOutput::SocketDataFill(FGNetFDM* net) // Positions net->longitude = Propagate->GetLocation().GetLongitude(); // geodetic (radians) net->latitude = Propagate->GetLocation().GetLatitude(); // geodetic (radians) - net->altitude = Propagate->Geth()*0.3048; // altitude, above sea level (meters) + net->altitude = Propagate->GetAltitudeASL()*0.3048; // altitude, above sea level (meters) net->agl = (float)(Propagate->GetDistanceAGL()*0.3048); // altitude, above ground level (meters) net->phi = (float)(Propagate->GetEuler(ePhi)); // roll (radians) @@ -506,7 +599,6 @@ void FGOutput::SocketDataFill(FGNetFDM* net) } } - // Consumables net->num_tanks = Propulsion->GetNumTanks(); // Max number of fuel tanks @@ -514,7 +606,6 @@ void FGOutput::SocketDataFill(FGNetFDM* net) net->fuel_quantity[i] = (float)(((FGTank *)Propulsion->GetTank(i))->GetContents()); } - // Gear status net->num_wheels = GroundReactions->GetNumGearUnits(); @@ -528,13 +619,11 @@ void FGOutput::SocketDataFill(FGNetFDM* net) net->gear_compression[i] = (float)(GroundReactions->GetGearUnit(i)->GetCompLen()); } - // Environment - net->cur_time = (long int)1234567890; // Friday, Feb 13, 2009, 23:31:30 UTC (not processed by FGFS anyway) + net->cur_time = (long int)1234567890; // Friday, Feb 13, 2009, 23:31:30 UTC (not processed by FGFS anyway) net->warp = 0; // offset in seconds to unix time net->visibility = 25000.0; // visibility in meters (for env. effects) - // Control surface positions (normalized values) net->elevator = (float)(FCS->GetDePos(ofNorm)); // Norm Elevator Pos, -- net->elevator_trim_tab = (float)(FCS->GetPitchTrimCmd()); // Norm Elev Trim Tab Pos, -- @@ -547,7 +636,6 @@ void FGOutput::SocketDataFill(FGNetFDM* net) net->speedbrake = (float)(FCS->GetDsbPos(ofNorm)); // Norm Speedbrake Pos, -- net->spoilers = (float)(FCS->GetDspPos(ofNorm)); // Norm Spoiler Pos, -- - // Convert the net buffer to network format if ( isLittleEndian ) { net->version = htonl(net->version); @@ -631,18 +719,29 @@ void FGOutput::FlightGearSocketOutput(void) { int length = sizeof(fgSockBuf); - - if (flightGearSocket == NULL) return; - if (!flightGearSocket->GetConnectStatus()) return; + if (socket == NULL) return; + if (!socket->GetConnectStatus()) return; SocketDataFill(&fgSockBuf); - flightGearSocket->Send((char *)&fgSockBuf, length); + socket->Send((char *)&fgSockBuf, length); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGOutput::SocketOutput(void) { + const FGAerodynamics* Aerodynamics = FDMExec->GetAerodynamics(); + const FGAuxiliary* Auxiliary = FDMExec->GetAuxiliary(); + const FGPropulsion* Propulsion = FDMExec->GetPropulsion(); + const FGMassBalance* MassBalance = FDMExec->GetMassBalance(); + const FGPropagate* Propagate = FDMExec->GetPropagate(); + const FGAccelerations* Accelerations = FDMExec->GetAccelerations(); + const FGFCS* FCS = FDMExec->GetFCS(); + const FGAtmosphere* Atmosphere = FDMExec->GetAtmosphere(); + const FGWinds* Winds = FDMExec->GetWinds(); + const FGAircraft* Aircraft = FDMExec->GetAircraft(); + const FGGroundReactions* GroundReactions = FDMExec->GetGroundReactions(); + string asciiData, scratch; if (socket == NULL) return; @@ -738,8 +837,8 @@ void FGOutput::SocketOutput(void) socket->Append("Latitude (deg)"); socket->Append("Longitude (deg)"); } - if (SubSystems & ssCoefficients) { - scratch = Aerodynamics->GetCoefficientStrings(","); + if (SubSystems & ssAeroFunctions) { + scratch = Aerodynamics->GetAeroFunctionStrings(","); if (scratch.length() != 0) socket->Append(scratch); } if (SubSystems & ssFCS) { @@ -763,7 +862,7 @@ void FGOutput::SocketOutput(void) } socket->Clear(); - socket->Append(State->Getsim_time()); + socket->Append(FDMExec->GetSimTime()); if (SubSystems & ssAerosurfaces) { socket->Append(FCS->GetDaCmd()); @@ -780,9 +879,9 @@ void FGOutput::SocketOutput(void) socket->Append(radtodeg*Propagate->GetPQR(eP)); socket->Append(radtodeg*Propagate->GetPQR(eQ)); socket->Append(radtodeg*Propagate->GetPQR(eR)); - socket->Append(radtodeg*Propagate->GetPQRdot(eP)); - socket->Append(radtodeg*Propagate->GetPQRdot(eQ)); - socket->Append(radtodeg*Propagate->GetPQRdot(eR)); + socket->Append(radtodeg*Accelerations->GetPQRdot(eP)); + socket->Append(radtodeg*Accelerations->GetPQRdot(eQ)); + socket->Append(radtodeg*Accelerations->GetPQRdot(eR)); } if (SubSystems & ssVelocities) { socket->Append(Auxiliary->Getqbar()); @@ -815,9 +914,9 @@ void FGOutput::SocketOutput(void) socket->Append(Atmosphere->GetDensity()); socket->Append(Atmosphere->GetPressureSL()); socket->Append(Atmosphere->GetPressure()); - socket->Append(Atmosphere->GetTurbMagnitude()); - socket->Append(Atmosphere->GetTurbDirection().Dump(",")); - socket->Append(Atmosphere->GetTotalWindNED().Dump(",")); + socket->Append(Winds->GetTurbMagnitude()); + socket->Append(Winds->GetTurbDirection().Dump(",")); + socket->Append(Winds->GetTotalWindNED().Dump(",")); } if (SubSystems & ssMassProps) { socket->Append(MassBalance->GetJ()(1,1)); @@ -835,7 +934,7 @@ void FGOutput::SocketOutput(void) socket->Append(MassBalance->GetXYZcg()(eZ)); } if (SubSystems & ssPropagate) { - socket->Append(Propagate->Geth()); + socket->Append(Propagate->GetAltitudeASL()); socket->Append(radtodeg*Propagate->GetEuler(ePhi)); socket->Append(radtodeg*Propagate->GetEuler(eTht)); socket->Append(radtodeg*Propagate->GetEuler(ePsi)); @@ -844,8 +943,8 @@ void FGOutput::SocketOutput(void) socket->Append(Propagate->GetLocation().GetLatitudeDeg()); socket->Append(Propagate->GetLocation().GetLongitudeDeg()); } - if (SubSystems & ssCoefficients) { - scratch = Aerodynamics->GetCoefficientValues(","); + if (SubSystems & ssAeroFunctions) { + scratch = Aerodynamics->GetAeroFunctionValues(","); if (scratch.length() != 0) socket->Append(scratch); } if (SubSystems & ssFCS) { @@ -868,7 +967,7 @@ void FGOutput::SocketOutput(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGOutput::SocketStatusOutput(string out_str) +void FGOutput::SocketStatusOutput(const string& out_str) { string asciiData; @@ -882,77 +981,81 @@ void FGOutput::SocketStatusOutput(string out_str) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +bool FGOutput::Load(int subSystems, std::string protocol, std::string type, std::string port, std::string name, double outRate, std::vector & outputProperties) +{ + SetType(type); + SetRate(outRate); + SubSystems = subSystems; + OutputProperties = outputProperties; + + if (((Type == otCSV) || (Type == otTab)) && (name != "cout") && (name !="COUT")) + name = FDMExec->GetRootDir() + name; + + if (!port.empty() && (Type == otSocket || Type == otFlightGear)) { + SetProtocol(protocol); + socket = new FGfdmSocket(name, atoi(port.c_str()), Protocol); + } else { + BaseFilename = Filename = name; + } + + Debug(2); + return true; +} + bool FGOutput::Load(Element* element) { - string type="", parameter=""; - string name=""; - string protocol="tcp"; - int OutRate = 0; - string property; - unsigned int port; + int subSystems = 0; Element *property_element; - - string separator = "/"; + std::vector outputProperties; if (!DirectivesFile.empty()) { // A directives filename from the command line overrides output_file_name = DirectivesFile; // one found in the config file. document = LoadXMLDocument(output_file_name); } else if (!element->GetAttributeValue("file").empty()) { - output_file_name = element->GetAttributeValue("file"); + output_file_name = FDMExec->GetRootDir() + element->GetAttributeValue("file"); document = LoadXMLDocument(output_file_name); } else { document = element; } - name = document->GetAttributeValue("name"); - type = document->GetAttributeValue("type"); - SetType(type); - if (!document->GetAttributeValue("port").empty() && type == string("SOCKET")) { - port = atoi(document->GetAttributeValue("port").c_str()); - socket = new FGfdmSocket(name, port); - } else if (!document->GetAttributeValue("port").empty() && type == string("FLIGHTGEAR")) { - port = atoi(document->GetAttributeValue("port").c_str()); - if (!document->GetAttributeValue("protocol").empty()) - protocol = document->GetAttributeValue("protocol"); - if (protocol == "udp") - flightGearSocket = new FGfdmSocket(name, port, FGfdmSocket::ptUDP); // create udp socket - else - flightGearSocket = new FGfdmSocket(name, port, FGfdmSocket::ptTCP); // create tcp socket (default) - } else { - Filename = name; - } + if (!document) return false; + + string type = document->GetAttributeValue("type"); + string name = document->GetAttributeValue("name"); + string port = document->GetAttributeValue("port"); + string protocol = document->GetAttributeValue("protocol"); if (!document->GetAttributeValue("rate").empty()) { - OutRate = (int)document->GetAttributeValueAsNumber("rate"); + rate = document->GetAttributeValueAsNumber("rate"); } else { - OutRate = 1; + rate = 1; } if (document->FindElementValue("simulation") == string("ON")) - SubSystems += ssSimulation; + subSystems += ssSimulation; if (document->FindElementValue("aerosurfaces") == string("ON")) - SubSystems += ssAerosurfaces; + subSystems += ssAerosurfaces; if (document->FindElementValue("rates") == string("ON")) - SubSystems += ssRates; + subSystems += ssRates; if (document->FindElementValue("velocities") == string("ON")) - SubSystems += ssVelocities; + subSystems += ssVelocities; if (document->FindElementValue("forces") == string("ON")) - SubSystems += ssForces; + subSystems += ssForces; if (document->FindElementValue("moments") == string("ON")) - SubSystems += ssMoments; + subSystems += ssMoments; if (document->FindElementValue("atmosphere") == string("ON")) - SubSystems += ssAtmosphere; + subSystems += ssAtmosphere; if (document->FindElementValue("massprops") == string("ON")) - SubSystems += ssMassProps; + subSystems += ssMassProps; if (document->FindElementValue("position") == string("ON")) - SubSystems += ssPropagate; - if (document->FindElementValue("coefficients") == string("ON")) - SubSystems += ssCoefficients; + subSystems += ssPropagate; + if (document->FindElementValue("coefficients") == string("ON") || document->FindElementValue("aerodynamics") == string("ON")) + subSystems += ssAeroFunctions; if (document->FindElementValue("ground_reactions") == string("ON")) - SubSystems += ssGroundReactions; + subSystems += ssGroundReactions; if (document->FindElementValue("fcs") == string("ON")) - SubSystems += ssFCS; + subSystems += ssFCS; if (document->FindElementValue("propulsion") == string("ON")) - SubSystems += ssPropulsion; + subSystems += ssPropulsion; property_element = document->FindElement("property"); while (property_element) { string property_str = property_element->GetDataLine(); @@ -963,17 +1066,28 @@ bool FGOutput::Load(Element* element) << " not be logged. You should check your configuration file." << reset << endl; } else { - OutputProperties.push_back(node); + outputProperties.push_back(node); } property_element = document->FindNextElement("property"); } - OutRate = OutRate>1000?1000:(OutRate<0?0:OutRate); - rate = (int)(0.5 + 1.0/(State->Getdt()*OutRate)); + return Load(subSystems, protocol, type, port, name, rate, outputProperties); +} - Debug(2); - return true; + +//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +void FGOutput::SetRate(double rtHz) +{ + rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz); + if (rtHz > 0) { + rate = (int)(0.5 + 1.0/(FDMExec->GetDeltaT()*rtHz)); + Enable(); + } else { + rate = 1; + Disable(); + } } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -1018,9 +1132,10 @@ void FGOutput::Debug(int from) } switch (Type) { case otCSV: - cout << scratch << " in CSV format output at rate " << 1/(State->Getdt()*rate) << " Hz" << endl; + cout << scratch << " in CSV format output at rate " << 1/(FDMExec->GetDeltaT()*rate) << " Hz" << endl; break; case otNone: + default: cout << " No log output" << endl; break; } @@ -1033,7 +1148,7 @@ void FGOutput::Debug(int from) if (SubSystems & ssMoments) cout << " Moments parameters logged" << endl; 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 & ssAeroFunctions) cout << " Coefficient 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;