JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
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
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 "FGFDMExec.h"
41#include "FGOutputType.h"
42#include "FGXMLElement.h"
43#include "FGPropertyManager.h"
44#include "math/FGTemplateFunc.h"
45#include "math/FGFunctionValue.h"
46#include "FGLog.h"
47
48using namespace std;
49
50namespace JSBSim {
51
52/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53CLASS IMPLEMENTATION
54%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55
57 FGModel(fdmex),
58 SubSystems(0),
59 enabled(true)
60{
61 Aerodynamics = FDMExec->GetAerodynamics();
62 Auxiliary = FDMExec->GetAuxiliary();
63 Aircraft = FDMExec->GetAircraft();
64 Winds = FDMExec->GetWinds();
65 Propulsion = FDMExec->GetPropulsion();
66 MassBalance = FDMExec->GetMassBalance();
67 Propagate = FDMExec->GetPropagate();
68 Accelerations = FDMExec->GetAccelerations();
69 FCS = FDMExec->GetFCS();
70 GroundReactions = FDMExec->GetGroundReactions();
71 ExternalReactions = FDMExec->GetExternalReactions();
72 BuoyantForces = FDMExec->GetBuoyantForces();
73
74 Debug(0);
75}
76
77//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78
80{
81 for (auto param: OutputParameters)
82 delete param;
83
84 Debug(1);
85}
86
87//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88
89void FGOutputType::SetIdx(unsigned int idx)
90{
91 string outputProp = CreateIndexedPropertyName("simulation/output", idx);
92
93 PropertyManager->Tie(outputProp + "/log_rate_hz", this, &FGOutputType::GetRateHz, &FGOutputType::SetRateHz);
94 PropertyManager->Tie(outputProp + "/enabled", &enabled);
95 OutputIdx = idx;
96}
97
98//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99
101{
102 if (element->FindElementValue("simulation") == string("ON"))
103 SubSystems += ssSimulation;
104 if (element->FindElementValue("aerosurfaces") == string("ON"))
105 SubSystems += ssAerosurfaces;
106 if (element->FindElementValue("rates") == string("ON"))
107 SubSystems += ssRates;
108 if (element->FindElementValue("velocities") == string("ON"))
109 SubSystems += ssVelocities;
110 if (element->FindElementValue("forces") == string("ON"))
111 SubSystems += ssForces;
112 if (element->FindElementValue("moments") == string("ON"))
113 SubSystems += ssMoments;
114 if (element->FindElementValue("atmosphere") == string("ON"))
115 SubSystems += ssAtmosphere;
116 if (element->FindElementValue("massprops") == string("ON"))
117 SubSystems += ssMassProps;
118 if (element->FindElementValue("position") == string("ON"))
119 SubSystems += ssPropagate;
120 if (element->FindElementValue("coefficients") == string("ON") || element->FindElementValue("aerodynamics") == string("ON"))
121 SubSystems += ssAeroFunctions;
122 if (element->FindElementValue("ground_reactions") == string("ON"))
123 SubSystems += ssGroundReactions;
124 if (element->FindElementValue("fcs") == string("ON"))
125 SubSystems += ssFCS;
126 if (element->FindElementValue("propulsion") == string("ON"))
127 SubSystems += ssPropulsion;
128
129 Element *property_element = element->FindElement("property");
130
131 while (property_element) {
132 string property_str = property_element->GetDataLine();
133 SGPropertyNode* node = PropertyManager->GetNode(property_str);
134 if (!node) {
135 FGXMLLogging log(property_element, LogLevel::ERROR);
136 log << LogFormat::RED << LogFormat::BOLD << " No property by the name "
137 << property_str << " has been defined. This property will "
138 << "not be logged. You should check your configuration file.\n"
139 << LogFormat::RESET;
140 } else {
141 if (property_element->HasAttribute("apply")) {
142 string function_str = property_element->GetAttributeValue("apply");
143 auto f = FDMExec->GetTemplateFunc(function_str);
144 if (f)
145 OutputParameters.push_back(new FGFunctionValue(node, f));
146 else {
147 FGXMLLogging log(property_element, LogLevel::ERROR);
148 log << LogFormat::RED << LogFormat::BOLD << " No function by the name "
149 << function_str << " has been defined. This property will "
150 << "not be logged. You should check your configuration file.\n"
151 << LogFormat::RESET;
152 }
153 }
154 else
155 OutputParameters.push_back(new FGPropertyValue(node));
156
157 if (property_element->HasAttribute("caption"))
158 OutputCaptions.push_back(property_element->GetAttributeValue("caption"));
159 else
160 OutputCaptions.push_back("");
161 }
162 property_element = element->FindNextElement("property");
163 }
164
165 double outRate = 1.0;
166 if (element->HasAttribute("rate"))
167 outRate = element->GetAttributeValueAsNumber("rate");
168
169 SetRateHz(outRate);
170
171 return true;
172}
173
174//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175
177{
178 bool ret = FGModel::InitModel();
179
180 Debug(2);
181 return ret;
182}
183
184//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185
186bool FGOutputType::Run(bool Holding)
187{
188 if (FGModel::Run(Holding)) return true;
189 if (!enabled) return true;
190
191 RunPreFunctions();
192 Print();
193 RunPostFunctions();
194
195 Debug(4);
196
197 return false;
198}
199
200//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201
202void FGOutputType::SetRateHz(double rtHz)
203{
204 rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz);
205 if (rtHz > 0) {
206 SetRate(0.5 + 1.0/(FDMExec->GetDeltaT()*rtHz));
207 Enable();
208 } else {
209 SetRate(1);
210 Disable();
211 }
212}
213
214//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215
216double FGOutputType::GetRateHz(void) const
217{
218 return 1.0 / (rate * FDMExec->GetDeltaT());
219}
220
221//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222
223void FGOutputType::SetOutputProperties(vector<SGPropertyNode_ptr> & outputProperties)
224{
225 for (auto prop: outputProperties)
226 OutputParameters.push_back(new FGPropertyValue(prop));
227}
228
229
230//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231// The bitmasked value choices are as follows:
232// unset: In this case (the default) JSBSim would only print
233// out the normally expected messages, essentially echoing
234// the config files as they are read. If the environment
235// variable is not set, debug_lvl is set to 1 internally
236// 0: This requests JSBSim not to output any messages
237// whatsoever.
238// 1: This value explicity requests the normal JSBSim
239// startup messages
240// 2: This value asks for a message to be printed out when
241// a class is instantiated
242// 4: When this value is set, a message is displayed when a
243// FGModel object executes its Run() method
244// 8: When this value is set, various runtime state variables
245// are printed out periodically
246// 16: When set various parameters are sanity checked and
247// a message is printed out when they go out of bounds
248
249void FGOutputType::Debug(int from)
250{
251 if (debug_lvl <= 0) return;
252
253 if (debug_lvl & 1) { // Standard console startup message output
254 if (from == 0) { // Constructor
255 }
256 if (from == 2) {
257 FGLogging log(LogLevel::DEBUG);
258 if (SubSystems & ssSimulation) log << " Simulation parameters logged\n";
259 if (SubSystems & ssAerosurfaces) log << " Aerosurface parameters logged\n";
260 if (SubSystems & ssRates) log << " Rate parameters logged\n";
261 if (SubSystems & ssVelocities) log << " Velocity parameters logged\n";
262 if (SubSystems & ssForces) log << " Force parameters logged\n";
263 if (SubSystems & ssMoments) log << " Moments parameters logged\n";
264 if (SubSystems & ssAtmosphere) log << " Atmosphere parameters logged\n";
265 if (SubSystems & ssMassProps) log << " Mass parameters logged\n";
266 if (SubSystems & ssAeroFunctions) log << " Coefficient parameters logged\n";
267 if (SubSystems & ssPropagate) log << " Propagate parameters logged\n";
268 if (SubSystems & ssGroundReactions) log << " Ground parameters logged\n";
269 if (SubSystems & ssFCS) log << " FCS parameters logged\n";
270 if (SubSystems & ssPropulsion) log << " Propulsion parameters logged\n";
271 if (!OutputParameters.empty()) log << " Properties logged:\n";
272 for (auto param: OutputParameters)
273 log << " - " << param->GetName() << "\n";
274 }
275 }
276 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
277 FGLogging log(LogLevel::DEBUG);
278 if (from == 0) log << "Instantiated: FGOutputType\n";
279 if (from == 1) log << "Destroyed: FGOutputType\n";
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}
Element * FindElement(const std::string &el="")
Searches for a specified element.
double GetAttributeValueAsNumber(const std::string &key)
Retrieves an attribute value as a double precision real number.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
std::string GetDataLine(unsigned int i=0)
Gets a line of data belonging to an element.
std::string FindElementValue(const std::string &el="")
Searches for the named element and returns the string data belonging to it.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
bool HasAttribute(const std::string &key)
Determines if an element has the supplied attribute.
Encapsulates the JSBSim simulation executive.
Definition FGFDMExec.h:185
std::shared_ptr< FGWinds > GetWinds(void) const
Returns the FGWinds pointer.
std::shared_ptr< FGBuoyantForces > GetBuoyantForces(void) const
Returns the FGBuoyantForces pointer.
std::shared_ptr< FGAircraft > GetAircraft(void) const
Returns the FGAircraft pointer.
std::shared_ptr< FGFCS > GetFCS(void) const
Returns the FGFCS pointer.
double GetDeltaT(void) const
Returns the simulation delta T.
Definition FGFDMExec.h:553
std::shared_ptr< FGPropagate > GetPropagate(void) const
Returns the FGPropagate pointer.
std::shared_ptr< FGAerodynamics > GetAerodynamics(void) const
Returns the FGAerodynamics pointer.
std::shared_ptr< FGExternalReactions > GetExternalReactions(void) const
Returns the FGExternalReactions pointer.
std::shared_ptr< FGGroundReactions > GetGroundReactions(void) const
Returns the FGGroundReactions pointer.
std::shared_ptr< FGMassBalance > GetMassBalance(void) const
Returns the FGAircraft pointer.
std::shared_ptr< FGPropulsion > GetPropulsion(void) const
Returns the FGPropulsion pointer.
std::shared_ptr< FGAuxiliary > GetAuxiliary(void) const
Returns the FGAuxiliary pointer.
std::shared_ptr< FGAccelerations > GetAccelerations(void) const
Returns the FGAccelerations pointer.
Represents a property value on which a function is applied.
Base class for all scheduled JSBSim models.
Definition FGModel.h:70
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition FGModel.cpp:90
void SetRate(unsigned int tt)
Set the ouput rate for the model in frames.
Definition FGModel.h:91
bool Load(Element *el) override
Init the output directives from an XML file (implement the FGModel interface).
~FGOutputType() override
Destructor.
void SetOutputProperties(std::vector< SGPropertyNode_ptr > &outputProperties)
Set the list of properties that should be output for this output instance.
void SetRateHz(double rtHz)
Set the output rate for this output instances.
void SetIdx(unsigned int idx)
Set the idx for this output instance.
bool Run(bool Holding) override
Executes the output directives (implement the FGModel interface).
FGOutputType(FGFDMExec *fdmex)
Constructor (implement the FGModel interface).
bool InitModel(void) override
Init the output model according to its configitation.
void Disable(void)
Disables the output generation.
double GetRateHz(void) const
Get the output rate in Hz for this output.
virtual void Print(void)=0
Generate the output.
void Enable(void)
Enables the output generation.
@ ssPropulsion
Subsystem: Propulsion (= 4096)
@ ssForces
Subsystem: Forces (= 16)
@ ssAtmosphere
Subsystem: Atmosphere (= 64)
@ ssPropagate
Subsystem: Propagate (= 512)
@ ssGroundReactions
Subsystem: Ground Reactions (= 1024)
@ ssFCS
Subsystem: FCS (= 2048)
@ ssMoments
Subsystem: Moments (= 32)
@ ssRates
Subsystem: Body rates (= 4)
@ ssVelocities
Subsystem: Velocities (= 8)
@ ssAerosurfaces
Subsystem: Aerosurfaces (= 2)
@ ssMassProps
Subsystem: Mass Properties (= 128)
@ ssSimulation
Subsystem: Simulation (= 1)
@ ssAeroFunctions
Subsystem: Coefficients (= 256)
Represents a property value which can use late binding.
A node in a property tree.
Definition props.hxx:747
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71