FlightGear next
FGOutputType.cpp
Go to the documentation of this file.
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
27FUNCTIONAL DESCRIPTION
28--------------------------------------------------------------------------------
29This is the place where you create output routines to dump data for perusal
30later.
31
32HISTORY
33--------------------------------------------------------------------------------
3409/10/11 BC Created
35
36%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37INCLUDES
38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39
40#include <ostream>
41
42#include "FGFDMExec.h"
43#include "FGOutputType.h"
46#include "math/FGTemplateFunc.h"
48
49using namespace std;
50
51namespace JSBSim {
52
53/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54CLASS IMPLEMENTATION
55%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56
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
91void 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"))
106 if (element->FindElementValue("aerosurfaces") == string("ON"))
108 if (element->FindElementValue("rates") == string("ON"))
110 if (element->FindElementValue("velocities") == string("ON"))
112 if (element->FindElementValue("forces") == string("ON"))
114 if (element->FindElementValue("moments") == string("ON"))
116 if (element->FindElementValue("atmosphere") == string("ON"))
118 if (element->FindElementValue("massprops") == string("ON"))
120 if (element->FindElementValue("position") == string("ON"))
122 if (element->FindElementValue("coefficients") == string("ON") || element->FindElementValue("aerodynamics") == string("ON"))
124 if (element->FindElementValue("ground_reactions") == string("ON"))
126 if (element->FindElementValue("fcs") == string("ON"))
127 SubSystems += ssFCS;
128 if (element->FindElementValue("propulsion") == string("ON"))
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
194 Print();
196
197 Debug(4);
198
199 return false;
200}
201
202//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203
204void 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
218double FGOutputType::GetRateHz(void) const
219{
220 return 1.0 / (rate * FDMExec->GetDeltaT());
221}
222
223//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
224
225void 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
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}
std::string ReadFrom(void) const
Return a string that contains a description of the location where the current XML element was read fr...
double GetAttributeValueAsNumber(const std::string &key)
Retrieves an attribute value as a double precision real number.
std::string FindElementValue(const std::string &el="")
Searches for the named element and returns the string data belonging to it.
std::string GetDataLine(unsigned int i=0)
Gets a line of data belonging to an element.
bool HasAttribute(const std::string &key)
Determines if an element has the supplied attribute.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Element * FindElement(const std::string &el="")
Searches for a specified element.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
Represents a property value on which a function is applied.
static char highint[5]
highlights text
Definition FGJSBBase.h:123
static char reset[5]
resets text properties
Definition FGJSBBase.h:129
static char fgred[6]
red text
Definition FGJSBBase.h:139
static std::string CreateIndexedPropertyName(const std::string &Property, int index)
unsigned int rate
Definition FGModel.h:102
FGPropertyManager * PropertyManager
Definition FGModel.h:117
bool InitModel(void) override
Definition FGModel.cpp:81
FGFDMExec * FDMExec
Definition FGModel.h:116
void SetRate(unsigned int tt)
Set the ouput rate for the model in frames.
Definition FGModel.h:90
FGModel(FGFDMExec *)
Constructor.
Definition FGModel.cpp:57
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition FGModel.cpp:89
@ ssGroundReactions
Subsystem: Ground Reactions (= 1024)
@ ssMoments
Subsystem: Moments (= 32)
@ ssPropagate
Subsystem: Propagate (= 512)
@ ssPropulsion
Subsystem: Propulsion (= 4096)
@ ssSimulation
Subsystem: Simulation (= 1)
@ ssForces
Subsystem: Forces (= 16)
@ ssAerosurfaces
Subsystem: Aerosurfaces (= 2)
@ ssMassProps
Subsystem: Mass Properties (= 128)
@ ssFCS
Subsystem: FCS (= 2048)
@ ssRates
Subsystem: Body rates (= 4)
@ ssAtmosphere
Subsystem: Atmosphere (= 64)
@ ssAeroFunctions
Subsystem: Coefficients (= 256)
@ ssVelocities
Subsystem: Velocities (= 8)
FGGroundReactions * GroundReactions
FGAircraft * Aircraft
std::vector< FGPropertyValue * > OutputParameters
void Disable(void)
Disables the output generation.
unsigned int OutputIdx
FGAccelerations * Accelerations
FGPropulsion * Propulsion
void SetOutputProperties(std::vector< FGPropertyNode_ptr > &outputProperties)
Set the list of properties that should be output for this output instance.
FGAuxiliary * Auxiliary
FGOutputType(FGFDMExec *fdmex)
Constructor (implement the FGModel interface).
FGPropagate * Propagate
FGExternalReactions * ExternalReactions
void SetIdx(unsigned int idx)
Set the idx for this output instance.
FGAtmosphere * Atmosphere
~FGOutputType() override
Destructor.
bool Run(void)
Executes the output directives (implement the FGModel interface).
void SetRateHz(double rtHz)
Set the output rate for this output instances.
FGMassBalance * MassBalance
std::vector< std::string > OutputCaptions
bool Load(Element *el) override
Init the output directives from an XML file (implement the FGModel interface).
FGAerodynamics * Aerodynamics
void Debug(int from) override
virtual void Print(void)=0
Generate the output.
double GetRateHz(void) const
Get the output rate in Hz for this output.
bool InitModel(void) override
Init the output model according to its configitation.
FGBuoyantForces * BuoyantForces
void Enable(void)
Enables the output generation.
Class wrapper for property handling.
Represents a property value which can use late binding.
short debug_lvl