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
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
55{
56 Name = "FGAircraft";
57 WingSpan = 0.0;
58 WingArea = 0.0;
59 cbar = 0.0;
60 HTailArea = VTailArea = 0.0;
61 HTailArm = VTailArm = 0.0;
62 lbarh = lbarv = 0.0;
63 vbarh = vbarv = 0.0;
64 WingIncidence = 0.0;
65
66 bind();
67
68 Debug(0);
69}
70
71//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72
74{
75 Debug(1);
76}
77
78//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80bool FGAircraft::InitModel(void)
81{
82 if (!FGModel::InitModel()) return false;
83
84 vForces.InitMatrix();
85 vMoments.InitMatrix();
86
87 return true;
88}
89
90//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91
92bool FGAircraft::Run(bool Holding)
93{
94 if (FGModel::Run(Holding)) return true;
95 if (Holding) return false;
96
97 RunPreFunctions();
98
99 vForces = in.AeroForce;
100 vForces += in.PropForce;
101 vForces += in.GroundForce;
102 vForces += in.ExternalForce;
103 vForces += in.BuoyantForce;
104
105 vMoments = in.AeroMoment;
106 vMoments += in.PropMoment;
107 vMoments += in.GroundMoment;
108 vMoments += in.ExternalMoment;
109 vMoments += in.BuoyantMoment;
110
111 RunPostFunctions();
112
113 return false;
114}
115
116//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117
119{
120 string element_name;
121 Element* element;
122
123 if (!FGModel::Upload(el, true)) return false;
124
125 if (el->FindElement("wingarea"))
126 WingArea = el->FindElementValueAsNumberConvertTo("wingarea", "FT2");
127 if (el->FindElement("wingspan"))
128 WingSpan = el->FindElementValueAsNumberConvertTo("wingspan", "FT");
129 if (el->FindElement("chord"))
130 cbar = el->FindElementValueAsNumberConvertTo("chord", "FT");
131 if (el->FindElement("wing_incidence"))
132 WingIncidence = el->FindElementValueAsNumberConvertTo("wing_incidence", "RAD");
133 if (el->FindElement("htailarea"))
134 HTailArea = el->FindElementValueAsNumberConvertTo("htailarea", "FT2");
135 if (el->FindElement("htailarm"))
136 HTailArm = el->FindElementValueAsNumberConvertTo("htailarm", "FT");
137 if (el->FindElement("vtailarea"))
138 VTailArea = el->FindElementValueAsNumberConvertTo("vtailarea", "FT2");
139 if (el->FindElement("vtailarm"))
140 VTailArm = el->FindElementValueAsNumberConvertTo("vtailarm", "FT");
141
142 // Find all LOCATION elements that descend from this METRICS branch of the
143 // config file. This would be CG location, eyepoint, etc.
144
145 element = el->FindElement("location");
146 while (element) {
147 element_name = element->GetAttributeValue("name");
148
149 if (element_name == "AERORP") vXYZrp = element->FindElementTripletConvertTo("IN");
150 else if (element_name == "EYEPOINT") vXYZep = element->FindElementTripletConvertTo("IN");
151 else if (element_name == "VRP") vXYZvrp = element->FindElementTripletConvertTo("IN");
152
153 element = el->FindNextElement("location");
154 }
155
156 // calculate some derived parameters
157 if (cbar != 0.0) {
158 lbarh = HTailArm/cbar;
159 lbarv = VTailArm/cbar;
160 if (WingArea != 0.0) {
161 vbarh = HTailArm*HTailArea / (cbar*WingArea);
162 vbarv = VTailArm*VTailArea / (WingSpan*WingArea);
163 }
164 }
165
166 PostLoad(el, FDMExec);
167
168 Debug(2);
169
170 return true;
171}
172
173//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174
175void FGAircraft::bind(void)
176{
177 PropertyManager->Tie("metrics/Sw-sqft", this, &FGAircraft::GetWingArea, &FGAircraft::SetWingArea);
178 PropertyManager->Tie("metrics/bw-ft", this, &FGAircraft::GetWingSpan);
179 PropertyManager->Tie("metrics/cbarw-ft", this, &FGAircraft::Getcbar);
180 PropertyManager->Tie("metrics/iw-rad", this, &FGAircraft::GetWingIncidence);
181 PropertyManager->Tie("metrics/iw-deg", this, &FGAircraft::GetWingIncidenceDeg);
182 PropertyManager->Tie("metrics/Sh-sqft", this, &FGAircraft::GetHTailArea);
183 PropertyManager->Tie("metrics/lh-ft", this, &FGAircraft::GetHTailArm);
184 PropertyManager->Tie("metrics/Sv-sqft", this, &FGAircraft::GetVTailArea);
185 PropertyManager->Tie("metrics/lv-ft", this, &FGAircraft::GetVTailArm);
186 PropertyManager->Tie("metrics/lh-norm", this, &FGAircraft::Getlbarh);
187 PropertyManager->Tie("metrics/lv-norm", this, &FGAircraft::Getlbarv);
188 PropertyManager->Tie("metrics/vbarh-norm", this, &FGAircraft::Getvbarh);
189 PropertyManager->Tie("metrics/vbarv-norm", this, &FGAircraft::Getvbarv);
190 PropertyManager->Tie("metrics/aero-rp-x-in", this, eX, &FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
191 PropertyManager->Tie("metrics/aero-rp-y-in", this, eY, &FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
192 PropertyManager->Tie("metrics/aero-rp-z-in", this, eZ, &FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
193 PropertyManager->Tie("metrics/eyepoint-x-in", this, eX, &FGAircraft::GetXYZep);
194 PropertyManager->Tie("metrics/eyepoint-y-in", this, eY,&FGAircraft::GetXYZep);
195 PropertyManager->Tie("metrics/eyepoint-z-in", this, eZ, &FGAircraft::GetXYZep);
196 PropertyManager->Tie("metrics/visualrefpoint-x-in", this, eX, &FGAircraft::GetXYZvrp);
197 PropertyManager->Tie("metrics/visualrefpoint-y-in", this, eY, &FGAircraft::GetXYZvrp);
198 PropertyManager->Tie("metrics/visualrefpoint-z-in", this, eZ, &FGAircraft::GetXYZvrp);
199}
200
201//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202// The bitmasked value choices are as follows:
203// unset: In this case (the default) JSBSim would only print
204// out the normally expected messages, essentially echoing
205// the config files as they are read. If the environment
206// variable is not set, debug_lvl is set to 1 internally
207// 0: This requests JSBSim not to output any messages
208// whatsoever.
209// 1: This value explicity requests the normal JSBSim
210// startup messages
211// 2: This value asks for a message to be printed out when
212// a class is instantiated
213// 4: When this value is set, a message is displayed when a
214// FGModel object executes its Run() method
215// 8: When this value is set, various runtime state variables
216// are printed out periodically
217// 16: When set various parameters are sanity checked and
218// a message is printed out when they go out of bounds
219
220void FGAircraft::Debug(int from)
221{
222 if (debug_lvl <= 0) return;
223
224 if (debug_lvl & 1) { // Standard console startup message output
225 if (from == 2) { // Loading
226 FGLogging log(LogLevel::DEBUG);
227 log << "\n Aircraft Metrics:\n" << fixed;
228 log << " WingArea: " << WingArea << "\n";
229 log << " WingSpan: " << WingSpan << "\n";
230 log << " Incidence: " << WingIncidence << "\n";
231 log << " Chord: " << cbar << "\n";
232 log << " H. Tail Area: " << HTailArea << "\n";
233 log << " H. Tail Arm: " << HTailArm << "\n";
234 log << " V. Tail Area: " << VTailArea << "\n";
235 log << " V. Tail Arm: " << VTailArm << "\n";
236 log << " Eyepoint (x, y, z): " << vXYZep << "\n";
237 log << " Ref Pt (x, y, z): " << vXYZrp << "\n";
238 log << " Visual Ref Pt (x, y, z): " << vXYZvrp << "\n";
239 }
240 }
241 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
242 FGLogging log(LogLevel::DEBUG);
243 if (from == 0) log << "Instantiated: FGAircraft\n";
244 if (from == 1) log << "Destroyed: FGAircraft\n";
245 }
246 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
247 }
248 if (debug_lvl & 8 ) { // Runtime state variables
249 }
250 if (debug_lvl & 16) { // Sanity checking
251 }
252 if (debug_lvl & 64) {
253 if (from == 0) { // Constructor
254 }
255 }
256}
257
258} // 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:70
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition FGModel.cpp:90
bool Upload(Element *el, bool preLoad)
Uploads this model in memory.
Definition FGModel.cpp:111
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71