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
FGAircraft.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGAircraft.cpp
4 Author: Jon S. Berndt
5 Date started: 12/12/98
6 Purpose: Encapsulates an aircraft
7 Called by: FGFDMExec
8
9 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
10
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 2 of the License, or (at your option) any
14 later version.
15
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
19 details.
20
21 You should have received a copy of the GNU Lesser General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc., 59
23 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 Further information about the GNU Lesser General Public License can also be
26 found on the world wide web at http://www.gnu.org.
27
28FUNCTIONAL DESCRIPTION
29--------------------------------------------------------------------------------
30Models the aircraft reactions and forces. This class is instantiated by the
31FGFDMExec class and scheduled as an FDM entry.
32
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34COMMENTS, REFERENCES, and NOTES
35%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36
37%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38INCLUDES
39%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41#include "FGAircraft.h"
42#include "FGFDMExec.h"
43#include "input_output/FGXMLElement.h"
44#include "input_output/FGLog.h"
45
46using namespace std;
47
48namespace JSBSim {
49
50/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51CLASS IMPLEMENTATION
52%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex, "FGAircraft")
55{
56 WingSpan = 0.0;
57 WingArea = 0.0;
58 cbar = 0.0;
59 HTailArea = VTailArea = 0.0;
60 HTailArm = VTailArm = 0.0;
61 lbarh = lbarv = 0.0;
62 vbarh = vbarv = 0.0;
63 WingIncidence = 0.0;
64
65 bind();
66
67 Debug(0);
68}
69
70//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71
73{
74 Debug(1);
75}
76
77//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78
79bool FGAircraft::InitModel(void)
80{
81 if (!FGModel::InitModel()) return false;
82
83 vForces.InitMatrix();
84 vMoments.InitMatrix();
85
86 return true;
87}
88
89//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90
91bool FGAircraft::Run(bool Holding)
92{
93 if (FGModel::Run(Holding)) return true;
94 if (Holding) return false;
95
96 RunPreFunctions();
97
98 vForces = in.AeroForce;
99 vForces += in.PropForce;
100 vForces += in.GroundForce;
101 vForces += in.ExternalForce;
102 vForces += in.BuoyantForce;
103
104 vMoments = in.AeroMoment;
105 vMoments += in.PropMoment;
106 vMoments += in.GroundMoment;
107 vMoments += in.ExternalMoment;
108 vMoments += in.BuoyantMoment;
109
110 RunPostFunctions();
111
112 return false;
113}
114
115//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116
118{
119 string element_name;
120 Element* element;
121
122 if (!FGModel::Upload(el, true)) return false;
123
124 if (el->FindElement("wingarea"))
125 WingArea = el->FindElementValueAsNumberConvertTo("wingarea", "FT2");
126 if (el->FindElement("wingspan"))
127 WingSpan = el->FindElementValueAsNumberConvertTo("wingspan", "FT");
128 if (el->FindElement("chord"))
129 cbar = el->FindElementValueAsNumberConvertTo("chord", "FT");
130 if (el->FindElement("wing_incidence"))
131 WingIncidence = el->FindElementValueAsNumberConvertTo("wing_incidence", "RAD");
132 if (el->FindElement("htailarea"))
133 HTailArea = el->FindElementValueAsNumberConvertTo("htailarea", "FT2");
134 if (el->FindElement("htailarm"))
135 HTailArm = el->FindElementValueAsNumberConvertTo("htailarm", "FT");
136 if (el->FindElement("vtailarea"))
137 VTailArea = el->FindElementValueAsNumberConvertTo("vtailarea", "FT2");
138 if (el->FindElement("vtailarm"))
139 VTailArm = el->FindElementValueAsNumberConvertTo("vtailarm", "FT");
140
141 // Find all LOCATION elements that descend from this METRICS branch of the
142 // config file. This would be CG location, eyepoint, etc.
143
144 element = el->FindElement("location");
145 while (element) {
146 element_name = element->GetAttributeValue("name");
147
148 if (element_name == "AERORP") vXYZrp = element->FindElementTripletConvertTo("IN");
149 else if (element_name == "EYEPOINT") vXYZep = element->FindElementTripletConvertTo("IN");
150 else if (element_name == "VRP") vXYZvrp = element->FindElementTripletConvertTo("IN");
151
152 element = el->FindNextElement("location");
153 }
154
155 // calculate some derived parameters
156 if (cbar != 0.0) {
157 lbarh = HTailArm/cbar;
158 lbarv = VTailArm/cbar;
159 if (WingArea != 0.0) {
160 vbarh = HTailArm*HTailArea / (cbar*WingArea);
161 vbarv = VTailArm*VTailArea / (WingSpan*WingArea);
162 }
163 }
164
165 PostLoad(el, FDMExec);
166
167 Debug(2);
168
169 return true;
170}
171
172//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173
174void FGAircraft::bind(void)
175{
176 PropertyManager->Tie("metrics/Sw-sqft", this, &FGAircraft::GetWingArea, &FGAircraft::SetWingArea);
177 PropertyManager->Tie("metrics/bw-ft", this, &FGAircraft::GetWingSpan);
178 PropertyManager->Tie("metrics/cbarw-ft", this, &FGAircraft::Getcbar);
179 PropertyManager->Tie("metrics/iw-rad", this, &FGAircraft::GetWingIncidence);
180 PropertyManager->Tie("metrics/iw-deg", this, &FGAircraft::GetWingIncidenceDeg);
181 PropertyManager->Tie("metrics/Sh-sqft", this, &FGAircraft::GetHTailArea);
182 PropertyManager->Tie("metrics/lh-ft", this, &FGAircraft::GetHTailArm);
183 PropertyManager->Tie("metrics/Sv-sqft", this, &FGAircraft::GetVTailArea);
184 PropertyManager->Tie("metrics/lv-ft", this, &FGAircraft::GetVTailArm);
185 PropertyManager->Tie("metrics/lh-norm", this, &FGAircraft::Getlbarh);
186 PropertyManager->Tie("metrics/lv-norm", this, &FGAircraft::Getlbarv);
187 PropertyManager->Tie("metrics/vbarh-norm", this, &FGAircraft::Getvbarh);
188 PropertyManager->Tie("metrics/vbarv-norm", this, &FGAircraft::Getvbarv);
189 PropertyManager->Tie("metrics/aero-rp-x-in", this, eX, &FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
190 PropertyManager->Tie("metrics/aero-rp-y-in", this, eY, &FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
191 PropertyManager->Tie("metrics/aero-rp-z-in", this, eZ, &FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
192 PropertyManager->Tie("metrics/eyepoint-x-in", this, eX, &FGAircraft::GetXYZep);
193 PropertyManager->Tie("metrics/eyepoint-y-in", this, eY,&FGAircraft::GetXYZep);
194 PropertyManager->Tie("metrics/eyepoint-z-in", this, eZ, &FGAircraft::GetXYZep);
195 PropertyManager->Tie("metrics/visualrefpoint-x-in", this, eX, &FGAircraft::GetXYZvrp);
196 PropertyManager->Tie("metrics/visualrefpoint-y-in", this, eY, &FGAircraft::GetXYZvrp);
197 PropertyManager->Tie("metrics/visualrefpoint-z-in", this, eZ, &FGAircraft::GetXYZvrp);
198}
199
200//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201// The bitmasked value choices are as follows:
202// unset: In this case (the default) JSBSim would only print
203// out the normally expected messages, essentially echoing
204// the config files as they are read. If the environment
205// variable is not set, debug_lvl is set to 1 internally
206// 0: This requests JSBSim not to output any messages
207// whatsoever.
208// 1: This value explicity requests the normal JSBSim
209// startup messages
210// 2: This value asks for a message to be printed out when
211// a class is instantiated
212// 4: When this value is set, a message is displayed when a
213// FGModel object executes its Run() method
214// 8: When this value is set, various runtime state variables
215// are printed out periodically
216// 16: When set various parameters are sanity checked and
217// a message is printed out when they go out of bounds
218
219void FGAircraft::Debug(int from)
220{
221 if (debug_lvl <= 0) return;
222
223 if (debug_lvl & 1) { // Standard console startup message output
224 if (from == 2) { // Loading
225 FGLogging log(LogLevel::DEBUG);
226 log << "\n Aircraft Metrics:\n" << fixed;
227 log << " WingArea: " << WingArea << "\n";
228 log << " WingSpan: " << WingSpan << "\n";
229 log << " Incidence: " << WingIncidence << "\n";
230 log << " Chord: " << cbar << "\n";
231 log << " H. Tail Area: " << HTailArea << "\n";
232 log << " H. Tail Arm: " << HTailArm << "\n";
233 log << " V. Tail Area: " << VTailArea << "\n";
234 log << " V. Tail Arm: " << VTailArm << "\n";
235 log << " Eyepoint (x, y, z): " << vXYZep << "\n";
236 log << " Ref Pt (x, y, z): " << vXYZrp << "\n";
237 log << " Visual Ref Pt (x, y, z): " << vXYZvrp << "\n";
238 }
239 }
240 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
241 FGLogging log(LogLevel::DEBUG);
242 if (from == 0) log << "Instantiated: FGAircraft\n";
243 if (from == 1) log << "Destroyed: FGAircraft\n";
244 }
245 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
246 }
247 if (debug_lvl & 8 ) { // Runtime state variables
248 }
249 if (debug_lvl & 16) { // Sanity checking
250 }
251 if (debug_lvl & 64) {
252 if (from == 0) { // Constructor
253 }
254 }
255}
256
257} // namespace JSBSim
Element * FindElement(const std::string &el="")
Searches for a specified element.
FGColumnVector3 FindElementTripletConvertTo(const std::string &target_units)
Composes a 3-element column vector for the supplied location or orientation.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
double FindElementValueAsNumberConvertTo(const std::string &el, const std::string &target_units)
Searches for the named element and converts and returns the data belonging to it.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
double Getcbar(void) const
Gets the average wing chord.
Definition FGAircraft.h:138
bool Load(Element *el) override
Loads the aircraft.
FGAircraft(FGFDMExec *Executive)
Constructor.
double GetWingArea(void) const
Gets the wing area.
Definition FGAircraft.h:134
bool Run(bool Holding) override
Runs the Aircraft model; called by the Executive Can pass in a value indicating if the executive is d...
double GetWingSpan(void) const
Gets the wing span.
Definition FGAircraft.h:136
const FGColumnVector3 & GetXYZrp(void) const
Gets the the aero reference point (RP) coordinates.
Definition FGAircraft.h:155
~FGAircraft() override
Destructor.
Encapsulates the JSBSim simulation executive.
Definition FGFDMExec.h:185
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
bool Upload(Element *el, bool preLoad)
Uploads this model in memory.
Definition FGModel.cpp:123
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:73