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),
111 alphaclmin = alphaclmax = 0;
112 HTailArea = VTailArea = HTailArm = VTailArm = 0.0;
113 lbarh = lbarv = vbarh = vbarv = 0.0;
117 if (debug_lvl & 2) cout << "Instantiated: " << Name << endl;
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 FGAircraft::~FGAircraft()
126 if (debug_lvl & 2) cout << "Destroyed: FGAircraft" << endl;
129 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 bool FGAircraft::Load(FGConfigFile* AC_cfg)
135 ReadPrologue(AC_cfg);
137 while ((AC_cfg->GetNextConfigLine() != string("EOF")) &&
138 (token = AC_cfg->GetValue()) != string("/FDM_CONFIG")) {
139 if (token == "METRICS") {
140 if (debug_lvl > 0) cout << fgcyan << "\n Reading Metrics" << fgdef << endl;
142 } else if (token == "AERODYNAMICS") {
143 if (debug_lvl > 0) cout << fgcyan << "\n Reading Aerodynamics" << fgdef << endl;
144 ReadAerodynamics(AC_cfg);
145 } else if (token == "UNDERCARRIAGE") {
146 if (debug_lvl > 0) cout << fgcyan << "\n Reading Landing Gear" << fgdef << endl;
147 ReadUndercarriage(AC_cfg);
148 } else if (token == "PROPULSION") {
149 if (debug_lvl > 0) cout << fgcyan << "\n Reading Propulsion" << fgdef << endl;
150 ReadPropulsion(AC_cfg);
151 } else if (token == "FLIGHT_CONTROL") {
152 if (debug_lvl > 0) cout << fgcyan << "\n Reading Flight Control" << fgdef << endl;
153 ReadFlightControls(AC_cfg);
154 } else if (token == "OUTPUT") {
155 if (debug_lvl > 0) cout << fgcyan << "\n Reading Output directives" << fgdef << endl;
163 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
165 bool FGAircraft::Run(void)
167 if (!FGModel::Run()) { // if false then execute this Run()
168 vForces.InitMatrix();
169 vForces += Aerodynamics->GetForces();
170 vForces += Inertial->GetForces();
171 vForces += Propulsion->GetForces();
172 vForces += GroundReactions->GetForces();
174 vMoments.InitMatrix();
175 vMoments += Aerodynamics->GetMoments();
176 vMoments += Propulsion->GetMoments();
177 vMoments += GroundReactions->GetMoments();
179 vBodyAccel = vForces/MassBalance->GetMass();
181 vNcg = vBodyAccel/Inertial->gravity();
183 if (alphaclmax != 0) {
184 if (Translation->Getalpha() > 0.85*alphaclmax) {
185 impending_stall = 10*(Translation->Getalpha()/alphaclmax - 0.85);
192 } else { // skip Run() execution this time
197 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 void FGAircraft::ReadPrologue(FGConfigFile* AC_cfg)
201 string token = AC_cfg->GetValue();
203 AircraftName = AC_cfg->GetValue("NAME");
204 if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File"
205 << underoff << ": " << highint << AircraftName << normint << endl;
206 scratch = AC_cfg->GetValue("VERSION").c_str();
208 CFGVersion = AC_cfg->GetValue("VERSION");
211 cout << " Version: " << highint << CFGVersion
213 if (CFGVersion != needed_cfg_version) {
214 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
215 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
216 cerr << "Current version needed is: " << needed_cfg_version << endl;
217 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
221 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223 void FGAircraft::ReadMetrics(FGConfigFile* AC_cfg)
227 double EW, bixx, biyy, bizz, bixz, biyz;
228 FGColumnVector3 vbaseXYZcg(3);
230 AC_cfg->GetNextConfigLine();
232 while ((token = AC_cfg->GetValue()) != string("/METRICS")) {
233 *AC_cfg >> parameter;
234 if (parameter == "AC_WINGAREA") {
236 if (debug_lvl > 0) cout << " WingArea: " << WingArea << endl;
237 } else if (parameter == "AC_WINGSPAN") {
239 if (debug_lvl > 0) cout << " WingSpan: " << WingSpan << endl;
240 } else if (parameter == "AC_WINGINCIDENCE") {
241 *AC_cfg >> WingIncidence;
242 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
243 } else if (parameter == "AC_CHORD") {
245 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
246 } else if (parameter == "AC_HTAILAREA") {
247 *AC_cfg >> HTailArea;
248 if (debug_lvl > 0) cout << " H. Tail Area: " << HTailArea << endl;
249 } else if (parameter == "AC_HTAILARM") {
251 if (debug_lvl > 0) cout << " H. Tail Arm: " << HTailArm << endl;
252 } else if (parameter == "AC_VTAILAREA") {
253 *AC_cfg >> VTailArea;
254 if (debug_lvl > 0) cout << " V. Tail Area: " << VTailArea << endl;
255 } else if (parameter == "AC_VTAILARM") {
257 if (debug_lvl > 0) cout << " V. Tail Arm: " << VTailArm << endl;
258 } else if (parameter == "AC_IXX") {
260 if (debug_lvl > 0) cout << " baseIxx: " << bixx << endl;
261 MassBalance->SetBaseIxx(bixx);
262 } else if (parameter == "AC_IYY") {
264 if (debug_lvl > 0) cout << " baseIyy: " << biyy << endl;
265 MassBalance->SetBaseIyy(biyy);
266 } else if (parameter == "AC_IZZ") {
268 if (debug_lvl > 0) cout << " baseIzz: " << bizz << endl;
269 MassBalance->SetBaseIzz(bizz);
270 } else if (parameter == "AC_IXZ") {
272 if (debug_lvl > 0) cout << " baseIxz: " << bixz << endl;
273 MassBalance->SetBaseIxz(bixz);
274 } else if (parameter == "AC_IYZ") {
276 if (debug_lvl > 0) cout << " baseIyz: " << biyz << endl;
277 MassBalance->SetBaseIyz(biyz);
278 } else if (parameter == "AC_EMPTYWT") {
280 MassBalance->SetEmptyWeight(EW);
281 if (debug_lvl > 0) cout << " EmptyWeight: " << EW << endl;
282 } else if (parameter == "AC_CGLOC") {
283 *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
284 MassBalance->SetBaseCG(vbaseXYZcg);
285 if (debug_lvl > 0) cout << " CG (x, y, z): " << vbaseXYZcg << endl;
286 } else if (parameter == "AC_EYEPTLOC") {
287 *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
288 if (debug_lvl > 0) cout << " Eyepoint (x, y, z): " << vXYZep << endl;
289 } else if (parameter == "AC_AERORP") {
290 *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
291 if (debug_lvl > 0) cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
292 } else if (parameter == "AC_ALPHALIMITS") {
293 *AC_cfg >> alphaclmin >> alphaclmax;
294 if (debug_lvl > 0) cout << " Maximum Alpha: " << alphaclmax
295 << " Minimum Alpha: " << alphaclmin
300 // calculate some derived parameters
302 lbarh = HTailArm/cbar;
303 lbarv = VTailArm/cbar;
304 if (WingArea != 0.0) {
305 vbarh = HTailArm*HTailArea / (cbar*WingArea);
306 vbarv = VTailArm*VTailArea / (cbar*WingArea);
312 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
314 void FGAircraft::ReadPropulsion(FGConfigFile* AC_cfg)
316 if (!Propulsion->Load(AC_cfg)) {
317 cerr << "Propulsion not successfully loaded" << endl;
321 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323 void FGAircraft::ReadFlightControls(FGConfigFile* AC_cfg)
325 if (!FCS->Load(AC_cfg)) {
326 cerr << "Flight Controls not successfully loaded" << endl;
330 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
332 void FGAircraft::ReadAerodynamics(FGConfigFile* AC_cfg)
334 if (!Aerodynamics->Load(AC_cfg)) {
335 cerr << "Aerodynamics not successfully loaded" << endl;
339 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341 void FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg)
343 if (!GroundReactions->Load(AC_cfg)) {
344 cerr << "Ground Reactions not successfully loaded" << endl;
348 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
350 void FGAircraft::ReadOutput(FGConfigFile* AC_cfg)
352 if (!Output->Load(AC_cfg)) {
353 cerr << "Output not successfully loaded" << endl;
357 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
359 void FGAircraft::Debug(void)
361 //TODO: Add your source code here