1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Encapsulates an aircraft
9 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
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 General Public License for more
21 You should have received a copy of the GNU 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.
25 Further information about the GNU General Public License can also be found on
26 the world wide web at http://www.gnu.org.
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.
34 --------------------------------------------------------------------------------
36 04/03/99 JSB Changed Aero() method to correct body axis force calculation
37 from wind vector. Fix provided by Tony Peden.
38 05/03/99 JSB Changed (for the better?) the way configurations are read in.
39 9/17/99 TP Combined force and moment functions. Added aero reference
40 point to config file. Added calculations for moments due to
41 difference in cg and aero reference point
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 COMMENTS, REFERENCES, and NOTES
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 #include <sys/types.h>
56 # include <simgear/compiler.h>
58 # ifdef SG_HAVE_STD_INCLUDES
64 # if defined (sgi) && !defined(__GNUC__)
71 #include "FGAircraft.h"
72 #include "FGMassBalance.h"
73 #include "FGInertial.h"
74 #include "FGGroundReactions.h"
75 #include "FGAerodynamics.h"
76 #include "FGTranslation.h"
77 #include "FGRotation.h"
78 #include "FGAtmosphere.h"
80 #include "FGFDMExec.h"
82 #include "FGPosition.h"
83 #include "FGAuxiliary.h"
86 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
90 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94 static const char *IdSrc = "$Id$";
95 static const char *IdHdr = ID_AIRCRAFT;
97 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
101 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
104 alphaclmin = alphaclmax = 0;
105 HTailArea = VTailArea = HTailArm = VTailArm = 0.0;
106 lbarh = lbarv = vbarh = vbarv = 0.0;
110 if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 FGAircraft::~FGAircraft()
119 if (debug_lvl & 2) cout << "Destroyed: FGAircraft" << endl;
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 bool FGAircraft::Load(FGConfigFile* AC_cfg)
128 if (!ReadPrologue(AC_cfg)) return false;
130 while ((AC_cfg->GetNextConfigLine() != string("EOF")) &&
131 (token = AC_cfg->GetValue()) != string("/FDM_CONFIG")) {
132 if (token == "METRICS") {
133 if (debug_lvl > 0) cout << fgcyan << "\n Reading Metrics" << fgdef << endl;
134 if (!ReadMetrics(AC_cfg)) return false;
135 } else if (token == "AERODYNAMICS") {
136 if (debug_lvl > 0) cout << fgcyan << "\n Reading Aerodynamics" << fgdef << endl;
137 if (!ReadAerodynamics(AC_cfg)) return false;
138 } else if (token == "UNDERCARRIAGE") {
139 if (debug_lvl > 0) cout << fgcyan << "\n Reading Landing Gear" << fgdef << endl;
140 if (!ReadUndercarriage(AC_cfg)) return false;
141 } else if (token == "PROPULSION") {
142 if (debug_lvl > 0) cout << fgcyan << "\n Reading Propulsion" << fgdef << endl;
143 if (!ReadPropulsion(AC_cfg)) return false;
144 } else if (token == "FLIGHT_CONTROL") {
145 if (debug_lvl > 0) cout << fgcyan << "\n Reading Flight Control" << fgdef << endl;
146 if (!ReadFlightControls(AC_cfg)) return false;
147 } else if (token == "OUTPUT") {
148 if (debug_lvl > 0) cout << fgcyan << "\n Reading Output directives" << fgdef << endl;
149 if (!ReadOutput(AC_cfg)) return false;
156 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158 bool FGAircraft::Run(void)
160 if (!FGModel::Run()) { // if false then execute this Run()
161 vForces.InitMatrix();
162 vForces += Aerodynamics->GetForces();
163 vForces += Inertial->GetForces();
164 vForces += Propulsion->GetForces();
165 vForces += GroundReactions->GetForces();
167 vMoments.InitMatrix();
168 vMoments += Aerodynamics->GetMoments();
169 vMoments += Propulsion->GetMoments();
170 vMoments += GroundReactions->GetMoments();
172 vBodyAccel = vForces/MassBalance->GetMass();
174 vNcg = vBodyAccel/Inertial->gravity();
176 vNwcg = State->GetTb2s() * vNcg;
177 vNwcg(3) = -1*vNwcg(3) + 1;
179 if (alphaclmax != 0) {
180 if (Translation->Getalpha() > 0.85*alphaclmax) {
181 impending_stall = 10*(Translation->Getalpha()/alphaclmax - 0.85);
188 } else { // skip Run() execution this time
193 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 float FGAircraft::GetNlf(void)
200 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 bool FGAircraft::ReadPrologue(FGConfigFile* AC_cfg)
204 string token = AC_cfg->GetValue();
206 AircraftName = AC_cfg->GetValue("NAME");
207 if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File"
208 << underoff << ": " << highint << AircraftName << normint << endl;
209 scratch = AC_cfg->GetValue("VERSION").c_str();
211 CFGVersion = AC_cfg->GetValue("VERSION");
214 cout << " Version: " << highint << CFGVersion
216 if (CFGVersion != needed_cfg_version) {
217 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
218 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
219 cerr << "Current version needed is: " << needed_cfg_version << endl;
220 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
226 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228 bool FGAircraft::ReadMetrics(FGConfigFile* AC_cfg)
232 double EW, bixx, biyy, bizz, bixy, bixz;
233 double pmWt, pmX, pmY, pmZ;
234 FGColumnVector3 vbaseXYZcg;
236 AC_cfg->GetNextConfigLine();
238 while ((token = AC_cfg->GetValue()) != string("/METRICS")) {
239 *AC_cfg >> parameter;
240 if (parameter == "AC_WINGAREA") {
242 if (debug_lvl > 0) cout << " WingArea: " << WingArea << endl;
243 } else if (parameter == "AC_WINGSPAN") {
245 if (debug_lvl > 0) cout << " WingSpan: " << WingSpan << endl;
246 } else if (parameter == "AC_WINGINCIDENCE") {
247 *AC_cfg >> WingIncidence;
248 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
249 } else if (parameter == "AC_CHORD") {
251 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
252 } else if (parameter == "AC_HTAILAREA") {
253 *AC_cfg >> HTailArea;
254 if (debug_lvl > 0) cout << " H. Tail Area: " << HTailArea << endl;
255 } else if (parameter == "AC_HTAILARM") {
257 if (debug_lvl > 0) cout << " H. Tail Arm: " << HTailArm << endl;
258 } else if (parameter == "AC_VTAILAREA") {
259 *AC_cfg >> VTailArea;
260 if (debug_lvl > 0) cout << " V. Tail Area: " << VTailArea << endl;
261 } else if (parameter == "AC_VTAILARM") {
263 if (debug_lvl > 0) cout << " V. Tail Arm: " << VTailArm << endl;
264 } else if (parameter == "AC_IXX") {
266 if (debug_lvl > 0) cout << " baseIxx: " << bixx << endl;
267 MassBalance->SetBaseIxx(bixx);
268 } else if (parameter == "AC_IYY") {
270 if (debug_lvl > 0) cout << " baseIyy: " << biyy << endl;
271 MassBalance->SetBaseIyy(biyy);
272 } else if (parameter == "AC_IZZ") {
274 if (debug_lvl > 0) cout << " baseIzz: " << bizz << endl;
275 MassBalance->SetBaseIzz(bizz);
276 } else if (parameter == "AC_IXY") {
278 if (debug_lvl > 0) cout << " baseIxy: " << bixy << endl;
279 MassBalance->SetBaseIxy(bixy);
280 } else if (parameter == "AC_IXZ") {
282 if (debug_lvl > 0) cout << " baseIxz: " << bixz << endl;
283 MassBalance->SetBaseIxz(bixz);
284 } else if (parameter == "AC_EMPTYWT") {
286 MassBalance->SetEmptyWeight(EW);
287 if (debug_lvl > 0) cout << " EmptyWeight: " << EW << endl;
288 } else if (parameter == "AC_CGLOC") {
289 *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
290 MassBalance->SetBaseCG(vbaseXYZcg);
291 if (debug_lvl > 0) cout << " CG (x, y, z): " << vbaseXYZcg << endl;
292 } else if (parameter == "AC_EYEPTLOC") {
293 *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
294 if (debug_lvl > 0) cout << " Eyepoint (x, y, z): " << vXYZep << endl;
295 } else if (parameter == "AC_AERORP") {
296 *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
297 if (debug_lvl > 0) cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
298 } else if (parameter == "AC_ALPHALIMITS") {
299 *AC_cfg >> alphaclmin >> alphaclmax;
300 if (debug_lvl > 0) cout << " Maximum Alpha: " << alphaclmax
301 << " Minimum Alpha: " << alphaclmin
303 } else if (parameter == "AC_POINTMASS") {
304 *AC_cfg >> pmWt >> pmX >> pmY >> pmZ;
305 if (debug_lvl > 0) cout << " Point Mass Object: " << pmWt << " lbs. at "
306 << "X, Y, Z (in.): " << pmX << " " << pmY << " " << pmZ
311 // calculate some derived parameters
313 lbarh = HTailArm/cbar;
314 lbarv = VTailArm/cbar;
315 if (WingArea != 0.0) {
316 vbarh = HTailArm*HTailArea / (cbar*WingArea);
317 vbarv = VTailArm*VTailArea / (cbar*WingArea);
323 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
325 bool FGAircraft::ReadPropulsion(FGConfigFile* AC_cfg)
327 if (!Propulsion->Load(AC_cfg)) {
328 cerr << " Propulsion not successfully loaded" << endl;
334 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336 bool FGAircraft::ReadFlightControls(FGConfigFile* AC_cfg)
338 if (!FCS->Load(AC_cfg)) {
339 cerr << " Flight Controls not successfully loaded" << endl;
345 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
347 bool FGAircraft::ReadAerodynamics(FGConfigFile* AC_cfg)
349 if (!Aerodynamics->Load(AC_cfg)) {
350 cerr << " Aerodynamics not successfully loaded" << endl;
356 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
358 bool FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg)
360 if (!GroundReactions->Load(AC_cfg)) {
361 cerr << " Ground Reactions not successfully loaded" << endl;
367 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
369 bool FGAircraft::ReadOutput(FGConfigFile* AC_cfg)
371 if (!Output->Load(AC_cfg)) {
372 cerr << " Output not successfully loaded" << endl;
378 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
380 void FGAircraft::Debug(void)
382 //TODO: Add your source code here