JSBSim Flight Dynamics Model  1.0 (02 March 2017)
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 Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  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 with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA 02111-1307, USA.
24 
25  Further information about the GNU Lesser General Public License can also be found on
26  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 <sys/stat.h>
42 #include <sys/types.h>
43 #include <iostream>
44 #include <cmath>
45 
46 #include "FGAircraft.h"
47 #include "FGFDMExec.h"
48 #include "input_output/FGPropertyManager.h"
49 #include "input_output/FGXMLElement.h"
50 
51 using namespace std;
52 
53 namespace JSBSim {
54 
55 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 DEFINITIONS
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 GLOBAL DATA
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 
63 IDENT(IdSrc,"$Id: FGAircraft.cpp,v 1.43 2015/01/31 14:56:21 bcoconni Exp $");
64 IDENT(IdHdr,ID_AIRCRAFT);
65 
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 CLASS IMPLEMENTATION
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69 
70 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
71 {
72  Name = "FGAircraft";
73  WingSpan = 0.0;
74  WingArea = 0.0;
75  cbar = 0.0;
76  HTailArea = VTailArea = 0.0;
77  HTailArm = VTailArm = 0.0;
78  lbarh = lbarv = 0.0;
79  vbarh = vbarv = 0.0;
80  WingIncidence = 0.0;
81  PitotAngle = 0.0;
82 
83  bind();
84 
85  Debug(0);
86 }
87 
88 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 
91 {
92  Debug(1);
93 }
94 
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 
97 bool FGAircraft::InitModel(void)
98 {
99  if (!FGModel::InitModel()) return false;
100 
101  vForces.InitMatrix();
102  vMoments.InitMatrix();
103 
104  return true;
105 }
106 
107 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108 
109 bool FGAircraft::Run(bool Holding)
110 {
111  if (FGModel::Run(Holding)) return true;
112  if (Holding) return false;
113 
114  RunPreFunctions();
115 
116  vForces = in.AeroForce;
117  vForces += in.PropForce;
118  vForces += in.GroundForce;
119  vForces += in.ExternalForce;
120  vForces += in.BuoyantForce;
121 
122  vMoments = in.AeroMoment;
123  vMoments += in.PropMoment;
124  vMoments += in.GroundMoment;
125  vMoments += in.ExternalMoment;
126  vMoments += in.BuoyantMoment;
127 
128  RunPostFunctions();
129 
130  return false;
131 }
132 
133 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 
136 {
137  string element_name;
138  Element* element;
139 
140  if (!FGModel::Load(el)) return false;
141 
142  if (el->FindElement("wingarea"))
143  WingArea = el->FindElementValueAsNumberConvertTo("wingarea", "FT2");
144  if (el->FindElement("wingspan"))
145  WingSpan = el->FindElementValueAsNumberConvertTo("wingspan", "FT");
146  if (el->FindElement("chord"))
147  cbar = el->FindElementValueAsNumberConvertTo("chord", "FT");
148  if (el->FindElement("wing_incidence"))
149  WingIncidence = el->FindElementValueAsNumberConvertTo("wing_incidence", "RAD");
150  if (el->FindElement("htailarea"))
151  HTailArea = el->FindElementValueAsNumberConvertTo("htailarea", "FT2");
152  if (el->FindElement("htailarm"))
153  HTailArm = el->FindElementValueAsNumberConvertTo("htailarm", "FT");
154  if (el->FindElement("vtailarea"))
155  VTailArea = el->FindElementValueAsNumberConvertTo("vtailarea", "FT2");
156  if (el->FindElement("vtailarm"))
157  VTailArm = el->FindElementValueAsNumberConvertTo("vtailarm", "FT");
158  if (el->FindElement("pitot_angle"))
159  PitotAngle = el->FindElementValueAsNumberConvertTo("pitot_angle", "RAD");
160 
161  // Find all LOCATION elements that descend from this METRICS branch of the
162  // config file. This would be CG location, eyepoint, etc.
163 
164  element = el->FindElement("location");
165  while (element) {
166  element_name = element->GetAttributeValue("name");
167 
168  if (element_name == "AERORP") vXYZrp = element->FindElementTripletConvertTo("IN");
169  else if (element_name == "EYEPOINT") vXYZep = element->FindElementTripletConvertTo("IN");
170  else if (element_name == "VRP") vXYZvrp = element->FindElementTripletConvertTo("IN");
171 
172  element = el->FindNextElement("location");
173  }
174 
175  // calculate some derived parameters
176  if (cbar != 0.0) {
177  lbarh = HTailArm/cbar;
178  lbarv = VTailArm/cbar;
179  if (WingArea != 0.0) {
180  vbarh = HTailArm*HTailArea / (cbar*WingArea);
181  vbarv = VTailArm*VTailArea / (WingSpan*WingArea);
182  }
183  }
184 
185  PostLoad(el, PropertyManager);
186 
187  Debug(2);
188 
189  return true;
190 }
191 
192 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193 
194 void FGAircraft::bind(void)
195 {
196  typedef double (FGAircraft::*PMF)(int) const;
197  PropertyManager->Tie("metrics/Sw-sqft", this, &FGAircraft::GetWingArea, &FGAircraft::SetWingArea);
198  PropertyManager->Tie("metrics/bw-ft", this, &FGAircraft::GetWingSpan);
199  PropertyManager->Tie("metrics/cbarw-ft", this, &FGAircraft::Getcbar);
200  PropertyManager->Tie("metrics/iw-rad", this, &FGAircraft::GetWingIncidence);
201  PropertyManager->Tie("metrics/iw-deg", this, &FGAircraft::GetWingIncidenceDeg);
202  PropertyManager->Tie("metrics/Sh-sqft", this, &FGAircraft::GetHTailArea);
203  PropertyManager->Tie("metrics/lh-ft", this, &FGAircraft::GetHTailArm);
204  PropertyManager->Tie("metrics/Sv-sqft", this, &FGAircraft::GetVTailArea);
205  PropertyManager->Tie("metrics/lv-ft", this, &FGAircraft::GetVTailArm);
206  PropertyManager->Tie("metrics/lh-norm", this, &FGAircraft::Getlbarh);
207  PropertyManager->Tie("metrics/lv-norm", this, &FGAircraft::Getlbarv);
208  PropertyManager->Tie("metrics/vbarh-norm", this, &FGAircraft::Getvbarh);
209  PropertyManager->Tie("metrics/vbarv-norm", this, &FGAircraft::Getvbarv);
210  PropertyManager->Tie("metrics/aero-rp-x-in", this, eX, (PMF)&FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
211  PropertyManager->Tie("metrics/aero-rp-y-in", this, eY, (PMF)&FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
212  PropertyManager->Tie("metrics/aero-rp-z-in", this, eZ, (PMF)&FGAircraft::GetXYZrp, &FGAircraft::SetXYZrp);
213  PropertyManager->Tie("metrics/eyepoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZep);
214  PropertyManager->Tie("metrics/eyepoint-y-in", this, eY,(PMF)&FGAircraft::GetXYZep);
215  PropertyManager->Tie("metrics/eyepoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZep);
216  PropertyManager->Tie("metrics/visualrefpoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZvrp);
217  PropertyManager->Tie("metrics/visualrefpoint-y-in", this, eY, (PMF)&FGAircraft::GetXYZvrp);
218  PropertyManager->Tie("metrics/visualrefpoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZvrp);
219 }
220 
221 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
222 // The bitmasked value choices are as follows:
223 // unset: In this case (the default) JSBSim would only print
224 // out the normally expected messages, essentially echoing
225 // the config files as they are read. If the environment
226 // variable is not set, debug_lvl is set to 1 internally
227 // 0: This requests JSBSim not to output any messages
228 // whatsoever.
229 // 1: This value explicity requests the normal JSBSim
230 // startup messages
231 // 2: This value asks for a message to be printed out when
232 // a class is instantiated
233 // 4: When this value is set, a message is displayed when a
234 // FGModel object executes its Run() method
235 // 8: When this value is set, various runtime state variables
236 // are printed out periodically
237 // 16: When set various parameters are sanity checked and
238 // a message is printed out when they go out of bounds
239 
240 void FGAircraft::Debug(int from)
241 {
242  if (debug_lvl <= 0) return;
243 
244  if (debug_lvl & 1) { // Standard console startup message output
245  if (from == 2) { // Loading
246  cout << endl << " Aircraft Metrics:" << endl;
247  cout << " WingArea: " << WingArea << endl;
248  cout << " WingSpan: " << WingSpan << endl;
249  cout << " Incidence: " << WingIncidence << endl;
250  cout << " Chord: " << cbar << endl;
251  cout << " H. Tail Area: " << HTailArea << endl;
252  cout << " H. Tail Arm: " << HTailArm << endl;
253  cout << " V. Tail Area: " << VTailArea << endl;
254  cout << " V. Tail Arm: " << VTailArm << endl;
255  cout << " Eyepoint (x, y, z): " << vXYZep << endl;
256  cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
257  cout << " Visual Ref Pt (x, y, z): " << vXYZvrp << endl;
258  }
259  }
260  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
261  if (from == 0) cout << "Instantiated: FGAircraft" << endl;
262  if (from == 1) cout << "Destroyed: FGAircraft" << endl;
263  }
264  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
265  }
266  if (debug_lvl & 8 ) { // Runtime state variables
267  }
268  if (debug_lvl & 16) { // Sanity checking
269  }
270  if (debug_lvl & 64) {
271  if (from == 0) { // Constructor
272  cout << IdSrc << endl;
273  cout << IdHdr << endl;
274  }
275  }
276 }
277 
278 } // namespace JSBSim
Encapsulates an Aircraft and its systems.
Definition: FGAircraft.h:110
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. ...
STL namespace.
Element * FindElement(const std::string &el="")
Searches for a specified element.
double GetWingSpan(void) const
Gets the wing span.
Definition: FGAircraft.h:144
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition: FGModel.cpp:92
void Tie(const std::string &name, bool *pointer, bool useDefault=true)
Tie a property to an external bool variable.
Base class for all scheduled JSBSim models.
Definition: FGModel.h:74
~FGAircraft()
Destructor.
Definition: FGAircraft.cpp:90
double Getcbar(void) const
Gets the average wing chord.
Definition: FGAircraft.h:146
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
bool Load(Element *el)
Loads the aircraft.
Definition: FGAircraft.cpp:135
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189
bool Run(bool Holding)
Runs the Aircraft model; called by the Executive Can pass in a value indicating if the executive is d...
Definition: FGAircraft.cpp:109
virtual bool Load(Element *el)
Loads this model.
Definition: FGModel.cpp:113
FGColumnVector3 FindElementTripletConvertTo(const std::string &target_units)
Composes a 3-element column vector for the supplied location or orientation.
double GetWingArea(void) const
Gets the wing area.
Definition: FGAircraft.h:142