JSBSim Flight Dynamics Model  1.0 (02 March 2017)
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 Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  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 with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24  Further information about the GNU Lesser General Public License can also be found on
25  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 
47 namespace JSBSim {
48 
49 IDENT(IdSrc,"$Id: FGOutputType.cpp,v 1.17 2015/08/23 09:43:31 bcoconni Exp $");
50 IDENT(IdHdr,ID_OUTPUTTYPE);
51 
52 using namespace std;
53 
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 CLASS IMPLEMENTATION
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 
59  FGModel(fdmex),
60  SubSystems(0),
61  enabled(true)
62 {
63  Aerodynamics = FDMExec->GetAerodynamics();
64  Auxiliary = FDMExec->GetAuxiliary();
65  Aircraft = FDMExec->GetAircraft();
66  Atmosphere = FDMExec->GetAtmosphere();
67  Winds = FDMExec->GetWinds();
68  Propulsion = FDMExec->GetPropulsion();
69  MassBalance = FDMExec->GetMassBalance();
70  Propagate = FDMExec->GetPropagate();
71  Accelerations = FDMExec->GetAccelerations();
72  FCS = FDMExec->GetFCS();
73  GroundReactions = FDMExec->GetGroundReactions();
74  ExternalReactions = FDMExec->GetExternalReactions();
75  BuoyantForces = FDMExec->GetBuoyantForces();
76 
77  Debug(0);
78 }
79 
80 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81 
83 {
84  OutputProperties.clear();
85  Debug(1);
86 }
87 
88 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 
90 void FGOutputType::SetIdx(unsigned int idx)
91 {
92  string outputProp = CreateIndexedPropertyName("simulation/output", idx);
93 
94  PropertyManager->Tie(outputProp + "/log_rate_hz", this, &FGOutputType::GetRateHz, &FGOutputType::SetRateHz, false);
95  PropertyManager->Tie(outputProp + "/enabled", &enabled);
96  OutputIdx = idx;
97 }
98 
99 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 
102 {
103  if (element->FindElementValue("simulation") == string("ON"))
104  SubSystems += ssSimulation;
105  if (element->FindElementValue("aerosurfaces") == string("ON"))
106  SubSystems += ssAerosurfaces;
107  if (element->FindElementValue("rates") == string("ON"))
108  SubSystems += ssRates;
109  if (element->FindElementValue("velocities") == string("ON"))
110  SubSystems += ssVelocities;
111  if (element->FindElementValue("forces") == string("ON"))
112  SubSystems += ssForces;
113  if (element->FindElementValue("moments") == string("ON"))
114  SubSystems += ssMoments;
115  if (element->FindElementValue("atmosphere") == string("ON"))
116  SubSystems += ssAtmosphere;
117  if (element->FindElementValue("massprops") == string("ON"))
118  SubSystems += ssMassProps;
119  if (element->FindElementValue("position") == string("ON"))
120  SubSystems += ssPropagate;
121  if (element->FindElementValue("coefficients") == string("ON") || element->FindElementValue("aerodynamics") == string("ON"))
122  SubSystems += ssAeroFunctions;
123  if (element->FindElementValue("ground_reactions") == string("ON"))
124  SubSystems += ssGroundReactions;
125  if (element->FindElementValue("fcs") == string("ON"))
126  SubSystems += ssFCS;
127  if (element->FindElementValue("propulsion") == string("ON"))
128  SubSystems += ssPropulsion;
129 
130  Element *property_element = element->FindElement("property");
131 
132  while (property_element) {
133  string property_str = property_element->GetDataLine();
134  FGPropertyNode* node = PropertyManager->GetNode(property_str);
135  if (!node) {
136  cerr << fgred << highint << endl << " No property by the name "
137  << property_str << " has been defined. This property will " << endl
138  << " not be logged. You should check your configuration file."
139  << reset << endl;
140  } else {
141  OutputProperties.push_back(node);
142  if (property_element->HasAttribute("caption")) {
143  OutputCaptions.push_back(property_element->GetAttributeValue("caption"));
144  } else {
145  OutputCaptions.push_back("");
146  }
147  }
148  property_element = element->FindNextElement("property");
149  }
150 
151  double outRate = 1.0;
152  if (!element->GetAttributeValue("rate").empty()) {
153  outRate = element->GetAttributeValueAsNumber("rate");
154  }
155  SetRateHz(outRate);
156 
157  return true;
158 }
159 
160 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 
163 {
164  bool ret = FGModel::InitModel();
165 
166  Debug(2);
167  return ret;
168 }
169 
170 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171 
173 {
174  if (FGModel::Run(false)) return true;
175  if (!enabled) return true;
176 
177  RunPreFunctions();
178  Print();
179  RunPostFunctions();
180 
181  Debug(4);
182 
183  return false;
184 }
185 
186 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 
188 void FGOutputType::SetRateHz(double rtHz)
189 {
190  rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz);
191  if (rtHz > 0) {
192  SetRate(0.5 + 1.0/(FDMExec->GetDeltaT()*rtHz));
193  Enable();
194  } else {
195  SetRate(1);
196  Disable();
197  }
198 }
199 
200 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 
202 double FGOutputType::GetRateHz(void) const
203 {
204  return 1.0 / (rate * FDMExec->GetDeltaT());
205 }
206 
207 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 // The bitmasked value choices are as follows:
209 // unset: In this case (the default) JSBSim would only print
210 // out the normally expected messages, essentially echoing
211 // the config files as they are read. If the environment
212 // variable is not set, debug_lvl is set to 1 internally
213 // 0: This requests JSBSim not to output any messages
214 // whatsoever.
215 // 1: This value explicity requests the normal JSBSim
216 // startup messages
217 // 2: This value asks for a message to be printed out when
218 // a class is instantiated
219 // 4: When this value is set, a message is displayed when a
220 // FGModel object executes its Run() method
221 // 8: When this value is set, various runtime state variables
222 // are printed out periodically
223 // 16: When set various parameters are sanity checked and
224 // a message is printed out when they go out of bounds
225 
226 void FGOutputType::Debug(int from)
227 {
228  if (debug_lvl <= 0) return;
229 
230  if (debug_lvl & 1) { // Standard console startup message output
231  if (from == 0) { // Constructor
232 
233  }
234  if (from == 2) {
235  if (SubSystems & ssSimulation) cout << " Simulation parameters logged" << endl;
236  if (SubSystems & ssAerosurfaces) cout << " Aerosurface parameters logged" << endl;
237  if (SubSystems & ssRates) cout << " Rate parameters logged" << endl;
238  if (SubSystems & ssVelocities) cout << " Velocity parameters logged" << endl;
239  if (SubSystems & ssForces) cout << " Force parameters logged" << endl;
240  if (SubSystems & ssMoments) cout << " Moments parameters logged" << endl;
241  if (SubSystems & ssAtmosphere) cout << " Atmosphere parameters logged" << endl;
242  if (SubSystems & ssMassProps) cout << " Mass parameters logged" << endl;
243  if (SubSystems & ssAeroFunctions) cout << " Coefficient parameters logged" << endl;
244  if (SubSystems & ssPropagate) cout << " Propagate parameters logged" << endl;
245  if (SubSystems & ssGroundReactions) cout << " Ground parameters logged" << endl;
246  if (SubSystems & ssFCS) cout << " FCS parameters logged" << endl;
247  if (SubSystems & ssPropulsion) cout << " Propulsion parameters logged" << endl;
248  if (OutputProperties.size() > 0) cout << " Properties logged:" << endl;
249  for (unsigned int i=0;i<OutputProperties.size();i++) {
250  cout << " - " << OutputProperties[i]->GetName() << endl;
251  }
252  }
253  }
254  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
255  if (from == 0) cout << "Instantiated: FGOutputType" << endl;
256  if (from == 1) cout << "Destroyed: FGOutputType" << endl;
257  }
258  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
259  }
260  if (debug_lvl & 8 ) { // Runtime state variables
261  }
262  if (debug_lvl & 16) { // Sanity checking
263  }
264  if (debug_lvl & 64) {
265  if (from == 0) { // Constructor
266  cout << IdSrc << endl;
267  cout << IdHdr << endl;
268  }
269  }
270 }
271 }
Subsystem: Propagate (= 512)
Definition: FGOutputType.h:193
FGAccelerations * GetAccelerations(void)
Returns the FGAccelerations pointer.
Definition: FGFDMExec.h:347
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
virtual bool InitModel(void)
Init the output model according to its configitation.
bool HasAttribute(const std::string &key)
Determines if an element has the supplied attribute.
Definition: FGXMLElement.h:162
Class wrapper for property handling.
FGAuxiliary * GetAuxiliary(void)
Returns the FGAuxiliary pointer.
Definition: FGFDMExec.h:371
static char reset[5]
resets text properties
Definition: FGJSBBase.h:131
Subsystem: Aerosurfaces (= 2)
Definition: FGOutputType.h:185
Subsystem: Simulation (= 1)
Definition: FGOutputType.h:184
virtual void Print(void)=0
Generate the output.
STL namespace.
Element * FindElement(const std::string &el="")
Searches for a specified element.
Subsystem: Velocities (= 8)
Definition: FGOutputType.h:187
static char fgred[6]
red text
Definition: FGJSBBase.h:141
double GetRateHz(void) const
Get the output rate in Hz for this output.
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition: FGModel.cpp:92
void SetRateHz(double rtHz)
Set the output rate for this output instances.
void SetRate(unsigned int tt)
Set the ouput rate for the model in frames.
Definition: FGModel.h:98
void Enable(void)
Enables the output generation.
Definition: FGOutputType.h:174
FGExternalReactions * GetExternalReactions(void)
Returns the FGExternalReactions pointer.
Definition: FGFDMExec.h:363
FGBuoyantForces * GetBuoyantForces(void)
Returns the FGBuoyantForces pointer.
Definition: FGFDMExec.h:365
Subsystem: Atmosphere (= 64)
Definition: FGOutputType.h:190
void Tie(const std::string &name, bool *pointer, bool useDefault=true)
Tie a property to an external bool variable.
FGWinds * GetWinds(void)
Returns the FGWinds pointer.
Definition: FGFDMExec.h:349
FGAircraft * GetAircraft(void)
Returns the FGAircraft pointer.
Definition: FGFDMExec.h:367
double GetAttributeValueAsNumber(const std::string &key)
Retrieves an attribute value as a double precision real number.
FGGroundReactions * GetGroundReactions(void)
Returns the FGGroundReactions pointer.
Definition: FGFDMExec.h:361
std::string FindElementValue(const std::string &el="")
Searches for the named element and returns the string data belonging to it.
Base class for all scheduled JSBSim models.
Definition: FGModel.h:74
virtual bool Load(Element *el)
Init the output directives from an XML file (implement the FGModel interface).
bool Run(void)
Executes the output directives (implement the FGModel interface).
std::string GetDataLine(unsigned int i=0)
Gets a line of data belonging to an element.
FGOutputType(FGFDMExec *fdmex)
Constructor (implement the FGModel interface).
Subsystem: Moments (= 32)
Definition: FGOutputType.h:189
FGFCS * GetFCS(void)
Returns the FGFCS pointer.
Definition: FGFDMExec.h:351
void SetIdx(unsigned int idx)
Set the idx for this output instance.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
static char highint[5]
highlights text
Definition: FGJSBBase.h:125
Subsystem: Ground Reactions (= 1024)
Definition: FGOutputType.h:194
Subsystem: FCS (= 2048)
Definition: FGOutputType.h:195
double GetDeltaT(void) const
Returns the simulation delta T.
Definition: FGFDMExec.h:536
FGAerodynamics * GetAerodynamics(void)
Returns the FGAerodynamics pointer.
Definition: FGFDMExec.h:357
FGPropulsion * GetPropulsion(void)
Returns the FGPropulsion pointer.
Definition: FGFDMExec.h:353
Subsystem: Mass Properties (= 128)
Definition: FGOutputType.h:191
virtual ~FGOutputType()
Destructor.
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189
Subsystem: Body rates (= 4)
Definition: FGOutputType.h:186
Subsystem: Forces (= 16)
Definition: FGOutputType.h:188
Subsystem: Coefficients (= 256)
Definition: FGOutputType.h:192
Subsystem: Propulsion (= 4096)
Definition: FGOutputType.h:196
void Disable(void)
Disables the output generation.
Definition: FGOutputType.h:176
FGPropagate * GetPropagate(void)
Returns the FGPropagate pointer.
Definition: FGFDMExec.h:369
FGMassBalance * GetMassBalance(void)
Returns the FGAircraft pointer.
Definition: FGFDMExec.h:355