JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
FGOutputType.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Module: FGOutputType.cpp
4  Author: Bertrand Coconnier
5  Date started: 09/10/11
6  Purpose: Manage output of sim parameters to file or stdout
7 
8  ------------- Copyright (C) 2011 Bertrand Coconnier -------------
9 
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU Lesser General Public License as published by the Free
12  Software Foundation; either version 2 of the License, or (at your option) any
13  later version.
14 
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18  details.
19 
20  You should have received a copy of the GNU Lesser General Public License along
21  with this program; if not, write to the Free Software Foundation, Inc., 59
22  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24  Further information about the GNU Lesser General Public License can also be
25  found on the world wide web at http://www.gnu.org.
26 
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29 This is the place where you create output routines to dump data for perusal
30 later.
31 
32 HISTORY
33 --------------------------------------------------------------------------------
34 09/10/11 BC Created
35 
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 
40 #include <ostream>
41 
42 #include "FGFDMExec.h"
43 #include "FGOutputType.h"
44 #include "input_output/FGXMLElement.h"
45 #include "input_output/FGPropertyManager.h"
46 #include "math/FGTemplateFunc.h"
47 #include "math/FGFunctionValue.h"
48 
49 using namespace std;
50 
51 namespace JSBSim {
52 
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 CLASS IMPLEMENTATION
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 
57 FGOutputType::FGOutputType(FGFDMExec* fdmex) :
58  FGModel(fdmex),
59  SubSystems(0),
60  enabled(true)
61 {
62  Aerodynamics = FDMExec->GetAerodynamics();
63  Auxiliary = FDMExec->GetAuxiliary();
64  Aircraft = FDMExec->GetAircraft();
65  Atmosphere = FDMExec->GetAtmosphere();
66  Winds = FDMExec->GetWinds();
67  Propulsion = FDMExec->GetPropulsion();
68  MassBalance = FDMExec->GetMassBalance();
69  Propagate = FDMExec->GetPropagate();
70  Accelerations = FDMExec->GetAccelerations();
71  FCS = FDMExec->GetFCS();
72  GroundReactions = FDMExec->GetGroundReactions();
73  ExternalReactions = FDMExec->GetExternalReactions();
74  BuoyantForces = FDMExec->GetBuoyantForces();
75 
76  Debug(0);
77 }
78 
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 
82 {
83  for (auto param: OutputParameters)
84  delete param;
85 
86  Debug(1);
87 }
88 
89 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 
91 void FGOutputType::SetIdx(unsigned int idx)
92 {
93  string outputProp = CreateIndexedPropertyName("simulation/output", idx);
94 
95  PropertyManager->Tie(outputProp + "/log_rate_hz", this, &FGOutputType::GetRateHz, &FGOutputType::SetRateHz);
96  PropertyManager->Tie(outputProp + "/enabled", &enabled);
97  OutputIdx = idx;
98 }
99 
100 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 
103 {
104  if (element->FindElementValue("simulation") == string("ON"))
105  SubSystems += ssSimulation;
106  if (element->FindElementValue("aerosurfaces") == string("ON"))
107  SubSystems += ssAerosurfaces;
108  if (element->FindElementValue("rates") == string("ON"))
109  SubSystems += ssRates;
110  if (element->FindElementValue("velocities") == string("ON"))
111  SubSystems += ssVelocities;
112  if (element->FindElementValue("forces") == string("ON"))
113  SubSystems += ssForces;
114  if (element->FindElementValue("moments") == string("ON"))
115  SubSystems += ssMoments;
116  if (element->FindElementValue("atmosphere") == string("ON"))
117  SubSystems += ssAtmosphere;
118  if (element->FindElementValue("massprops") == string("ON"))
119  SubSystems += ssMassProps;
120  if (element->FindElementValue("position") == string("ON"))
121  SubSystems += ssPropagate;
122  if (element->FindElementValue("coefficients") == string("ON") || element->FindElementValue("aerodynamics") == string("ON"))
123  SubSystems += ssAeroFunctions;
124  if (element->FindElementValue("ground_reactions") == string("ON"))
125  SubSystems += ssGroundReactions;
126  if (element->FindElementValue("fcs") == string("ON"))
127  SubSystems += ssFCS;
128  if (element->FindElementValue("propulsion") == string("ON"))
129  SubSystems += ssPropulsion;
130 
131  Element *property_element = element->FindElement("property");
132 
133  while (property_element) {
134  string property_str = property_element->GetDataLine();
135  FGPropertyNode* node = PropertyManager->GetNode(property_str);
136  if (!node) {
137  cerr << property_element->ReadFrom()
138  << fgred << highint << endl << " No property by the name "
139  << property_str << " has been defined. This property will " << endl
140  << " not be logged. You should check your configuration file."
141  << reset << endl;
142  } else {
143  if (property_element->HasAttribute("apply")) {
144  string function_str = property_element->GetAttributeValue("apply");
145  FGTemplateFunc* f = FDMExec->GetTemplateFunc(function_str);
146  if (f)
147  OutputParameters.push_back(new FGFunctionValue(node, f));
148  else {
149  cerr << property_element->ReadFrom()
150  << fgred << highint << " No function by the name "
151  << function_str << " has been defined. This property will "
152  << "not be logged. You should check your configuration file."
153  << reset << endl;
154  }
155  }
156  else
157  OutputParameters.push_back(new FGPropertyValue(node));
158 
159  if (property_element->HasAttribute("caption"))
160  OutputCaptions.push_back(property_element->GetAttributeValue("caption"));
161  else
162  OutputCaptions.push_back("");
163  }
164  property_element = element->FindNextElement("property");
165  }
166 
167  double outRate = 1.0;
168  if (element->HasAttribute("rate"))
169  outRate = element->GetAttributeValueAsNumber("rate");
170 
171  SetRateHz(outRate);
172 
173  return true;
174 }
175 
176 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 
179 {
180  bool ret = FGModel::InitModel();
181 
182  Debug(2);
183  return ret;
184 }
185 
186 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 
189 {
190  if (FGModel::Run(false)) return true;
191  if (!enabled) return true;
192 
193  RunPreFunctions();
194  Print();
195  RunPostFunctions();
196 
197  Debug(4);
198 
199  return false;
200 }
201 
202 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 
204 void FGOutputType::SetRateHz(double rtHz)
205 {
206  rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz);
207  if (rtHz > 0) {
208  SetRate(0.5 + 1.0/(FDMExec->GetDeltaT()*rtHz));
209  Enable();
210  } else {
211  SetRate(1);
212  Disable();
213  }
214 }
215 
216 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217 
218 double FGOutputType::GetRateHz(void) const
219 {
220  return 1.0 / (rate * FDMExec->GetDeltaT());
221 }
222 
223 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224 
225 void FGOutputType::SetOutputProperties(vector<FGPropertyNode_ptr> & outputProperties)
226 {
227  for (auto prop: outputProperties)
228  OutputParameters.push_back(new FGPropertyValue(prop));
229 }
230 
231 
232 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233 // The bitmasked value choices are as follows:
234 // unset: In this case (the default) JSBSim would only print
235 // out the normally expected messages, essentially echoing
236 // the config files as they are read. If the environment
237 // variable is not set, debug_lvl is set to 1 internally
238 // 0: This requests JSBSim not to output any messages
239 // whatsoever.
240 // 1: This value explicity requests the normal JSBSim
241 // startup messages
242 // 2: This value asks for a message to be printed out when
243 // a class is instantiated
244 // 4: When this value is set, a message is displayed when a
245 // FGModel object executes its Run() method
246 // 8: When this value is set, various runtime state variables
247 // are printed out periodically
248 // 16: When set various parameters are sanity checked and
249 // a message is printed out when they go out of bounds
250 
251 void FGOutputType::Debug(int from)
252 {
253  if (debug_lvl <= 0) return;
254 
255  if (debug_lvl & 1) { // Standard console startup message output
256  if (from == 0) { // Constructor
257  }
258  if (from == 2) {
259  if (SubSystems & ssSimulation) cout << " Simulation parameters logged" << endl;
260  if (SubSystems & ssAerosurfaces) cout << " Aerosurface parameters logged" << endl;
261  if (SubSystems & ssRates) cout << " Rate parameters logged" << endl;
262  if (SubSystems & ssVelocities) cout << " Velocity parameters logged" << endl;
263  if (SubSystems & ssForces) cout << " Force parameters logged" << endl;
264  if (SubSystems & ssMoments) cout << " Moments parameters logged" << endl;
265  if (SubSystems & ssAtmosphere) cout << " Atmosphere parameters logged" << endl;
266  if (SubSystems & ssMassProps) cout << " Mass parameters logged" << endl;
267  if (SubSystems & ssAeroFunctions) cout << " Coefficient parameters logged" << endl;
268  if (SubSystems & ssPropagate) cout << " Propagate parameters logged" << endl;
269  if (SubSystems & ssGroundReactions) cout << " Ground parameters logged" << endl;
270  if (SubSystems & ssFCS) cout << " FCS parameters logged" << endl;
271  if (SubSystems & ssPropulsion) cout << " Propulsion parameters logged" << endl;
272  if (!OutputParameters.empty()) cout << " Properties logged:" << endl;
273  for (auto param: OutputParameters)
274  cout << " - " << param->GetName() << endl;
275  }
276  }
277  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
278  if (from == 0) cout << "Instantiated: FGOutputType" << endl;
279  if (from == 1) cout << "Destroyed: FGOutputType" << endl;
280  }
281  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
282  }
283  if (debug_lvl & 8 ) { // Runtime state variables
284  }
285  if (debug_lvl & 16) { // Sanity checking
286  }
287  if (debug_lvl & 64) {
288  if (from == 0) { // Constructor
289  }
290  }
291 }
292 }
JSBSim::FGOutputType::ssMoments
@ ssMoments
Subsystem: Moments (= 32)
Definition: FGOutputType.h:181
JSBSim::FGFDMExec
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:185
JSBSim::FGFunctionValue
Represents a property value on which a function is applied.
Definition: FGFunctionValue.h:57
JSBSim::FGOutputType::ssAeroFunctions
@ ssAeroFunctions
Subsystem: Coefficients (= 256)
Definition: FGOutputType.h:184
JSBSim::FGOutputType::GetRateHz
double GetRateHz(void) const
Get the output rate in Hz for this output.
Definition: FGOutputType.cpp:218
JSBSim::FGOutputType::Enable
void Enable(void)
Enables the output generation.
Definition: FGOutputType.h:166
JSBSim::FGModel
Base class for all scheduled JSBSim models.
Definition: FGModel.h:68
JSBSim::Element::HasAttribute
bool HasAttribute(const std::string &key)
Determines if an element has the supplied attribute.
Definition: FGXMLElement.h:155
JSBSim::Element::GetAttributeValue
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Definition: FGXMLElement.cpp:260
JSBSim::FGOutputType::Print
virtual void Print(void)=0
Generate the output.
JSBSim::Element::FindElement
Element * FindElement(const std::string &el="")
Searches for a specified element.
Definition: FGXMLElement.cpp:389
JSBSim::FGOutputType::ssAtmosphere
@ ssAtmosphere
Subsystem: Atmosphere (= 64)
Definition: FGOutputType.h:182
JSBSim::FGFDMExec::GetAircraft
FGAircraft * GetAircraft(void)
Returns the FGAircraft pointer.
Definition: FGFDMExec.h:375
JSBSim::FGOutputType::Disable
void Disable(void)
Disables the output generation.
Definition: FGOutputType.h:168
JSBSim::FGOutputType::InitModel
bool InitModel(void) override
Init the output model according to its configitation.
Definition: FGOutputType.cpp:178
JSBSim::FGFDMExec::GetGroundReactions
FGGroundReactions * GetGroundReactions(void)
Returns the FGGroundReactions pointer.
Definition: FGFDMExec.h:369
JSBSim::FGFDMExec::GetAuxiliary
FGAuxiliary * GetAuxiliary(void)
Returns the FGAuxiliary pointer.
Definition: FGFDMExec.h:379
JSBSim::FGPropertyNode
Class wrapper for property handling.
Definition: FGPropertyManager.h:70
JSBSim::FGOutputType::ssPropagate
@ ssPropagate
Subsystem: Propagate (= 512)
Definition: FGOutputType.h:185
JSBSim::FGOutputType::SetIdx
void SetIdx(unsigned int idx)
Set the idx for this output instance.
Definition: FGOutputType.cpp:91
JSBSim::FGOutputType::ssMassProps
@ ssMassProps
Subsystem: Mass Properties (= 128)
Definition: FGOutputType.h:183
JSBSim::FGFDMExec::GetWinds
FGWinds * GetWinds(void)
Returns the FGWinds pointer.
Definition: FGFDMExec.h:357
JSBSim::FGOutputType::SetOutputProperties
void SetOutputProperties(std::vector< FGPropertyNode_ptr > &outputProperties)
Set the list of properties that should be output for this output instance.
Definition: FGOutputType.cpp:225
JSBSim::FGJSBBase::fgred
static char fgred[6]
red text
Definition: FGJSBBase.h:139
JSBSim::FGFDMExec::GetPropagate
FGPropagate * GetPropagate(void)
Returns the FGPropagate pointer.
Definition: FGFDMExec.h:377
JSBSim::FGOutputType::ssRates
@ ssRates
Subsystem: Body rates (= 4)
Definition: FGOutputType.h:178
JSBSim::FGPropertyValue
Represents a property value which can use late binding.
Definition: FGPropertyValue.h:59
JSBSim::FGFDMExec::GetMassBalance
FGMassBalance * GetMassBalance(void)
Returns the FGAircraft pointer.
Definition: FGFDMExec.h:363
JSBSim::FGOutputType::ssForces
@ ssForces
Subsystem: Forces (= 16)
Definition: FGOutputType.h:180
JSBSim::FGOutputType::ssFCS
@ ssFCS
Subsystem: FCS (= 2048)
Definition: FGOutputType.h:187
JSBSim::Element::FindElementValue
std::string FindElementValue(const std::string &el="")
Searches for the named element and returns the string data belonging to it.
Definition: FGXMLElement.cpp:468
JSBSim::FGJSBBase::reset
static char reset[5]
resets text properties
Definition: FGJSBBase.h:129
JSBSim::FGFDMExec::GetAerodynamics
FGAerodynamics * GetAerodynamics(void)
Returns the FGAerodynamics pointer.
Definition: FGFDMExec.h:365
JSBSim::FGOutputType::ssPropulsion
@ ssPropulsion
Subsystem: Propulsion (= 4096)
Definition: FGOutputType.h:188
JSBSim::FGFDMExec::GetDeltaT
double GetDeltaT(void) const
Returns the simulation delta T.
Definition: FGFDMExec.h:545
JSBSim::FGFDMExec::GetPropulsion
FGPropulsion * GetPropulsion(void)
Returns the FGPropulsion pointer.
Definition: FGFDMExec.h:361
JSBSim::FGModel::SetRate
void SetRate(unsigned int tt)
Set the ouput rate for the model in frames.
Definition: FGModel.h:90
JSBSim::Element::GetDataLine
std::string GetDataLine(unsigned int i=0)
Gets a line of data belonging to an element.
Definition: FGXMLElement.cpp:333
JSBSim::Element::GetAttributeValueAsNumber
double GetAttributeValueAsNumber(const std::string &key)
Retrieves an attribute value as a double precision real number.
Definition: FGXMLElement.cpp:279
JSBSim::FGFDMExec::GetFCS
FGFCS * GetFCS(void)
Returns the FGFCS pointer.
Definition: FGFDMExec.h:359
JSBSim::FGModel::Run
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition: FGModel.cpp:89
JSBSim::FGOutputType::~FGOutputType
~FGOutputType() override
Destructor.
Definition: FGOutputType.cpp:81
JSBSim::FGTemplateFunc
Definition: FGTemplateFunc.h:56
JSBSim::FGOutputType::ssAerosurfaces
@ ssAerosurfaces
Subsystem: Aerosurfaces (= 2)
Definition: FGOutputType.h:177
JSBSim::FGOutputType::ssGroundReactions
@ ssGroundReactions
Subsystem: Ground Reactions (= 1024)
Definition: FGOutputType.h:186
JSBSim::FGOutputType::ssSimulation
@ ssSimulation
Subsystem: Simulation (= 1)
Definition: FGOutputType.h:176
JSBSim::FGFDMExec::GetExternalReactions
FGExternalReactions * GetExternalReactions(void)
Returns the FGExternalReactions pointer.
Definition: FGFDMExec.h:371
JSBSim::FGOutputType::SetRateHz
void SetRateHz(double rtHz)
Set the output rate for this output instances.
Definition: FGOutputType.cpp:204
JSBSim::Element::ReadFrom
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
Definition: FGXMLElement.cpp:738
JSBSim::FGJSBBase::highint
static char highint[5]
highlights text
Definition: FGJSBBase.h:123
JSBSim::Element::FindNextElement
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
Definition: FGXMLElement.cpp:407
JSBSim::FGOutputType::Run
bool Run(void)
Executes the output directives (implement the FGModel interface).
Definition: FGOutputType.cpp:188
JSBSim::FGFDMExec::GetAccelerations
FGAccelerations * GetAccelerations(void)
Returns the FGAccelerations pointer.
Definition: FGFDMExec.h:355
JSBSim::FGFDMExec::GetBuoyantForces
FGBuoyantForces * GetBuoyantForces(void)
Returns the FGBuoyantForces pointer.
Definition: FGFDMExec.h:373
JSBSim::FGOutputType::Load
bool Load(Element *el) override
Init the output directives from an XML file (implement the FGModel interface).
Definition: FGOutputType.cpp:102
JSBSim::FGOutputType::ssVelocities
@ ssVelocities
Subsystem: Velocities (= 8)
Definition: FGOutputType.h:179
JSBSim::Element
Definition: FGXMLElement.h:143
JSBSim::FGPropertyManager::Tie
void Tie(const std::string &name, T *pointer)
Tie a property to an external variable.
Definition: FGPropertyManager.h:449