JSBSim Flight Dynamics Model  1.1.11 (13 Feb 2022)
An Open Source Flight Dynamics and Control Software Library in C++
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 
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 Models the aircraft reactions and forces. This class is instantiated by the
31 FGFDMExec class and scheduled as an FDM entry.
32 
33 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34 COMMENTS, REFERENCES, and NOTES
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 
41 #include "FGAircraft.h"
42 #include "input_output/FGXMLElement.h"
43 
44 using namespace std;
45 
46 namespace JSBSim {
47 
48 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 CLASS IMPLEMENTATION
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 
52 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
53 {
54  Name = "FGAircraft";
55  WingSpan = 0.0;
56  WingArea = 0.0;
57  cbar = 0.0;
58  HTailArea = VTailArea = 0.0;
59  HTailArm = VTailArm = 0.0;
60  lbarh = lbarv = 0.0;
61  vbarh = vbarv = 0.0;
62  WingIncidence = 0.0;
63 
64  bind();
65 
66  Debug(0);
67 }
68 
69 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 
72 {
73  Debug(1);
74 }
75 
76 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 
78 bool FGAircraft::InitModel(void)
79 {
80  if (!FGModel::InitModel()) return false;
81 
82  vForces.InitMatrix();
83  vMoments.InitMatrix();
84 
85  return true;
86 }
87 
88 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 
90 bool FGAircraft::Run(bool Holding)
91 {
92  if (FGModel::Run(Holding)) return true;
93  if (Holding) return false;
94 
95  RunPreFunctions();
96 
97  vForces = in.AeroForce;
98  vForces += in.PropForce;
99  vForces += in.GroundForce;
100  vForces += in.ExternalForce;
101  vForces += in.BuoyantForce;
102 
103  vMoments = in.AeroMoment;
104  vMoments += in.PropMoment;
105  vMoments += in.GroundMoment;
106  vMoments += in.ExternalMoment;
107  vMoments += in.BuoyantMoment;
108 
109  RunPostFunctions();
110 
111  return false;
112 }
113 
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 
117 {
118  string element_name;
119  Element* element;
120 
121  if (!FGModel::Upload(el, true)) return false;
122 
123  if (el->FindElement("wingarea"))
124  WingArea = el->FindElementValueAsNumberConvertTo("wingarea", "FT2");
125  if (el->FindElement("wingspan"))
126  WingSpan = el->FindElementValueAsNumberConvertTo("wingspan", "FT");
127  if (el->FindElement("chord"))
128  cbar = el->FindElementValueAsNumberConvertTo("chord", "FT");
129  if (el->FindElement("wing_incidence"))
130  WingIncidence = el->FindElementValueAsNumberConvertTo("wing_incidence", "RAD");
131  if (el->FindElement("htailarea"))
132  HTailArea = el->FindElementValueAsNumberConvertTo("htailarea", "FT2");
133  if (el->FindElement("htailarm"))
134  HTailArm = el->FindElementValueAsNumberConvertTo("htailarm", "FT");
135  if (el->FindElement("vtailarea"))
136  VTailArea = el->FindElementValueAsNumberConvertTo("vtailarea", "FT2");
137  if (el->FindElement("vtailarm"))
138  VTailArm = el->FindElementValueAsNumberConvertTo("vtailarm", "FT");
139 
140  // Find all LOCATION elements that descend from this METRICS branch of the
141  // config file. This would be CG location, eyepoint, etc.
142 
143  element = el->FindElement("location");
144  while (element) {
145  element_name = element->GetAttributeValue("name");
146 
147  if (element_name == "AERORP") vXYZrp = element->FindElementTripletConvertTo("IN");
148  else if (element_name == "EYEPOINT") vXYZep = element->FindElementTripletConvertTo("IN");
149  else if (element_name == "VRP") vXYZvrp = element->FindElementTripletConvertTo("IN");
150 
151  element = el->FindNextElement("location");
152  }
153 
154  // calculate some derived parameters
155  if (cbar != 0.0) {
156  lbarh = HTailArm/cbar;
157  lbarv = VTailArm/cbar;
158  if (WingArea != 0.0) {
159  vbarh = HTailArm*HTailArea / (cbar*WingArea);
160  vbarv = VTailArm*VTailArea / (WingSpan*WingArea);
161  }
162  }
163 
164  PostLoad(el, FDMExec);
165 
166  Debug(2);
167 
168  return true;
169 }
170 
171 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 
173 void FGAircraft::bind(void)
174 {
175  typedef double (FGAircraft::*PMF)(int) const;
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, (PMF)&FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
190  PropertyManager->Tie("metrics/aero-rp-y-in", this, eY, (PMF)&FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
191  PropertyManager->Tie("metrics/aero-rp-z-in", this, eZ, (PMF)&FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
192  PropertyManager->Tie("metrics/eyepoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZep);
193  PropertyManager->Tie("metrics/eyepoint-y-in", this, eY,(PMF)&FGAircraft::GetXYZep);
194  PropertyManager->Tie("metrics/eyepoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZep);
195  PropertyManager->Tie("metrics/visualrefpoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZvrp);
196  PropertyManager->Tie("metrics/visualrefpoint-y-in", this, eY, (PMF)&FGAircraft::GetXYZvrp);
197  PropertyManager->Tie("metrics/visualrefpoint-z-in", this, eZ, (PMF)&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 
219 void 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  cout << endl << " Aircraft Metrics:" << endl;
226  cout << " WingArea: " << WingArea << endl;
227  cout << " WingSpan: " << WingSpan << endl;
228  cout << " Incidence: " << WingIncidence << endl;
229  cout << " Chord: " << cbar << endl;
230  cout << " H. Tail Area: " << HTailArea << endl;
231  cout << " H. Tail Arm: " << HTailArm << endl;
232  cout << " V. Tail Area: " << VTailArea << endl;
233  cout << " V. Tail Arm: " << VTailArm << endl;
234  cout << " Eyepoint (x, y, z): " << vXYZep << endl;
235  cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
236  cout << " Visual Ref Pt (x, y, z): " << vXYZvrp << endl;
237  }
238  }
239  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
240  if (from == 0) cout << "Instantiated: FGAircraft" << endl;
241  if (from == 1) cout << "Destroyed: FGAircraft" << endl;
242  }
243  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
244  }
245  if (debug_lvl & 8 ) { // Runtime state variables
246  }
247  if (debug_lvl & 16) { // Sanity checking
248  }
249  if (debug_lvl & 64) {
250  if (from == 0) { // Constructor
251  }
252  }
253 }
254 
255 } // namespace JSBSim
JSBSim::FGFDMExec
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:185
JSBSim::FGModel::Upload
bool Upload(Element *el, bool preLoad)
Uploads this model in memory.
Definition: FGModel.cpp:110
JSBSim::FGModel
Base class for all scheduled JSBSim models.
Definition: FGModel.h:68
JSBSim::Element::GetAttributeValue
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Definition: FGXMLElement.cpp:260
JSBSim::FGAircraft::GetXYZrp
const FGColumnVector3 & GetXYZrp(void) const
Gets the the aero reference point (RP) coordinates.
Definition: FGAircraft.h:155
JSBSim::Element::FindElement
Element * FindElement(const std::string &el="")
Searches for a specified element.
Definition: FGXMLElement.cpp:389
JSBSim::Element::FindElementValueAsNumberConvertTo
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.
Definition: FGXMLElement.cpp:480
JSBSim::FGAircraft::GetWingSpan
double GetWingSpan(void) const
Gets the wing span.
Definition: FGAircraft.h:136
JSBSim::FGAircraft::Run
bool Run(bool Holding) override
Runs the Aircraft model; called by the Executive Can pass in a value indicating if the executive is d...
Definition: FGAircraft.cpp:90
JSBSim::FGModel::Run
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition: FGModel.cpp:89
JSBSim::FGAircraft
Encapsulates an Aircraft and its systems.
Definition: FGAircraft.h:102
JSBSim::FGAircraft::GetWingArea
double GetWingArea(void) const
Gets the wing area.
Definition: FGAircraft.h:134
JSBSim::FGAircraft::~FGAircraft
~FGAircraft() override
Destructor.
Definition: FGAircraft.cpp:71
JSBSim::Element::FindNextElement
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
Definition: FGXMLElement.cpp:407
JSBSim::FGAircraft::Load
bool Load(Element *el) override
Loads the aircraft.
Definition: FGAircraft.cpp:116
JSBSim::FGAircraft::Getcbar
double Getcbar(void) const
Gets the average wing chord.
Definition: FGAircraft.h:138
JSBSim::Element
Definition: FGXMLElement.h:143
JSBSim::FGPropertyManager::Tie
void Tie(const std::string &name, T *pointer)
Tie a property to an external variable.
Definition: FGPropertyManager.h:449
JSBSim::Element::FindElementTripletConvertTo
FGColumnVector3 FindElementTripletConvertTo(const std::string &target_units)
Composes a 3-element column vector for the supplied location or orientation.
Definition: FGXMLElement.cpp:589