JSBSim Flight Dynamics Model 1.3.3 (16 Oct 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{
60 Aerodynamics = FDMExec->GetAerodynamics();
61 Auxiliary = FDMExec->GetAuxiliary();
62 Aircraft = FDMExec->GetAircraft();
63 Winds = FDMExec->GetWinds();
64 Propulsion = FDMExec->GetPropulsion();
65 MassBalance = FDMExec->GetMassBalance();
66 Propagate = FDMExec->GetPropagate();
67 Accelerations = FDMExec->GetAccelerations();
68 FCS = FDMExec->GetFCS();
69 GroundReactions = FDMExec->GetGroundReactions();
70 ExternalReactions = FDMExec->GetExternalReactions();
71 BuoyantForces = FDMExec->GetBuoyantForces();
72
73 Debug(0);
74}
75
76//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77
79{
80 for (auto param: OutputParameters)
81 delete param;
82
83 Debug(1);
84}
85
86//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87
88void FGOutputType::SetIdx(unsigned int idx)
89{
90 string outputProp = CreateIndexedPropertyName("simulation/output", idx);
91
92 PropertyManager->Tie(outputProp + "/log_rate_hz", this, &FGOutputType::GetRateHz, &FGOutputType::SetRateHz);
93 PropertyManager->Tie(outputProp + "/enabled", &enabled);
94 OutputIdx = idx;
95}
96
97//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98
100{
101 if (element->FindElementValue("simulation") == string("ON"))
102 SubSystems += ssSimulation;
103 if (element->FindElementValue("aerosurfaces") == string("ON"))
104 SubSystems += ssAerosurfaces;
105 if (element->FindElementValue("rates") == string("ON"))
106 SubSystems += ssRates;
107 if (element->FindElementValue("velocities") == string("ON"))
108 SubSystems += ssVelocities;
109 if (element->FindElementValue("forces") == string("ON"))
110 SubSystems += ssForces;
111 if (element->FindElementValue("moments") == string("ON"))
112 SubSystems += ssMoments;
113 if (element->FindElementValue("atmosphere") == string("ON"))
114 SubSystems += ssAtmosphere;
115 if (element->FindElementValue("massprops") == string("ON"))
116 SubSystems += ssMassProps;
117 if (element->FindElementValue("position") == string("ON"))
118 SubSystems += ssPropagate;
119 if (element->FindElementValue("coefficients") == string("ON") || element->FindElementValue("aerodynamics") == string("ON"))
120 SubSystems += ssAeroFunctions;
121 if (element->FindElementValue("ground_reactions") == string("ON"))
122 SubSystems += ssGroundReactions;
123 if (element->FindElementValue("fcs") == string("ON"))
124 SubSystems += ssFCS;
125 if (element->FindElementValue("propulsion") == string("ON"))
126 SubSystems += ssPropulsion;
127
128 Element *property_element = element->FindElement("property");
129
130 while (property_element) {
131 string property_str = property_element->GetDataLine();
132 SGPropertyNode* node = PropertyManager->GetNode(property_str);
133 if (!node) {
134 FGXMLLogging log(property_element, LogLevel::ERROR);
135 log << LogFormat::RED << LogFormat::BOLD << " No property by the name "
136 << property_str << " has been defined. This property will "
137 << "not be logged. You should check your configuration file.\n"
138 << LogFormat::RESET;
139 } else {
140 if (property_element->HasAttribute("apply")) {
141 string function_str = property_element->GetAttributeValue("apply");
142 auto f = FDMExec->GetTemplateFunc(function_str);
143 if (f)
144 OutputParameters.push_back(new FGFunctionValue(node, f));
145 else {
146 FGXMLLogging log(property_element, LogLevel::ERROR);
147 log << LogFormat::RED << LogFormat::BOLD << " No function by the name "
148 << function_str << " has been defined. This property will "
149 << "not be logged. You should check your configuration file.\n"
150 << LogFormat::RESET;
151 }
152 }
153 else
154 OutputParameters.push_back(new FGPropertyValue(node));
155
156 if (property_element->HasAttribute("caption"))
157 OutputCaptions.push_back(property_element->GetAttributeValue("caption"));
158 else
159 OutputCaptions.push_back("");
160 }
161 property_element = element->FindNextElement("property");
162 }
163
164 double outRate = 1.0;
165 if (element->HasAttribute("rate"))
166 outRate = element->GetAttributeValueAsNumber("rate");
167
168 SetRateHz(outRate);
169
170 return true;
171}
172
173//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174
176{
177 bool ret = FGModel::InitModel();
178
179 Debug(2);
180 return ret;
181}
182
183//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184
185bool FGOutputType::Run(bool Holding)
186{
187 if (FGModel::Run(Holding)) return true;
188
189 RunPreFunctions();
190 Print();
191 RunPostFunctions();
192
193 Debug(4);
194
195 return false;
196}
197
198//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199
200void FGOutputType::SetRateHz(double rtHz)
201{
202 rtHz = rtHz>1000?1000:(rtHz<0?0:rtHz);
203 if (rtHz > 0) {
204 SetRate(0.5 + 1.0/(FDMExec->GetDeltaT()*rtHz));
205 Enable();
206 } else {
207 SetRate(1);
208 Disable();
209 }
210}
211
212//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213
214double FGOutputType::GetRateHz(void) const
215{
216 return 1.0 / (rate * FDMExec->GetDeltaT());
217}
218
219//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
220
221void FGOutputType::SetOutputProperties(vector<SGPropertyNode_ptr> & outputProperties)
222{
223 for (auto prop: outputProperties)
224 OutputParameters.push_back(new FGPropertyValue(prop));
225}
226
227
228//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229// The bitmasked value choices are as follows:
230// unset: In this case (the default) JSBSim would only print
231// out the normally expected messages, essentially echoing
232// the config files as they are read. If the environment
233// variable is not set, debug_lvl is set to 1 internally
234// 0: This requests JSBSim not to output any messages
235// whatsoever.
236// 1: This value explicity requests the normal JSBSim
237// startup messages
238// 2: This value asks for a message to be printed out when
239// a class is instantiated
240// 4: When this value is set, a message is displayed when a
241// FGModel object executes its Run() method
242// 8: When this value is set, various runtime state variables
243// are printed out periodically
244// 16: When set various parameters are sanity checked and
245// a message is printed out when they go out of bounds
246
247void FGOutputType::Debug(int from)
248{
249 if (debug_lvl <= 0) return;
250
251 if (debug_lvl & 1) { // Standard console startup message output
252 if (from == 0) { // Constructor
253 }
254 if (from == 2) {
255 FGLogging log(LogLevel::DEBUG);
256 if (SubSystems & ssSimulation) log << " Simulation parameters logged\n";
257 if (SubSystems & ssAerosurfaces) log << " Aerosurface parameters logged\n";
258 if (SubSystems & ssRates) log << " Rate parameters logged\n";
259 if (SubSystems & ssVelocities) log << " Velocity parameters logged\n";
260 if (SubSystems & ssForces) log << " Force parameters logged\n";
261 if (SubSystems & ssMoments) log << " Moments parameters logged\n";
262 if (SubSystems & ssAtmosphere) log << " Atmosphere parameters logged\n";
263 if (SubSystems & ssMassProps) log << " Mass parameters logged\n";
264 if (SubSystems & ssAeroFunctions) log << " Coefficient parameters logged\n";
265 if (SubSystems & ssPropagate) log << " Propagate parameters logged\n";
266 if (SubSystems & ssGroundReactions) log << " Ground parameters logged\n";
267 if (SubSystems & ssFCS) log << " FCS parameters logged\n";
268 if (SubSystems & ssPropulsion) log << " Propulsion parameters logged\n";
269 if (!OutputParameters.empty()) log << " Properties logged:\n";
270 for (auto param: OutputParameters)
271 log << " - " << param->GetName() << "\n";
272 }
273 }
274 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
275 FGLogging log(LogLevel::DEBUG);
276 if (from == 0) log << "Instantiated: FGOutputType\n";
277 if (from == 1) log << "Destroyed: FGOutputType\n";
278 }
279 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
280 }
281 if (debug_lvl & 8 ) { // Runtime state variables
282 }
283 if (debug_lvl & 16) { // Sanity checking
284 }
285 if (debug_lvl & 64) {
286 if (from == 0) { // Constructor
287 }
288 }
289}
290}
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:557
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:79
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition FGModel.cpp:101
void SetRate(unsigned int tt)
Set the ouput rate for the model in frames.
Definition FGModel.h:102
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:73