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;
113 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 FGAircraft::~FGAircraft()
120 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 bool FGAircraft::Load(FGConfigFile* AC_cfg)
126 if (!ReadPrologue(AC_cfg)) return false;
128 while ((AC_cfg->GetNextConfigLine() != string("EOF")) &&
129 (token = AC_cfg->GetValue()) != string("/FDM_CONFIG")) {
130 if (token == "METRICS") {
131 if (debug_lvl > 0) cout << fgcyan << "\n Reading Metrics" << fgdef << endl;
132 if (!ReadMetrics(AC_cfg)) return false;
133 } else if (token == "AERODYNAMICS") {
134 if (debug_lvl > 0) cout << fgcyan << "\n Reading Aerodynamics" << fgdef << endl;
135 if (!ReadAerodynamics(AC_cfg)) return false;
136 } else if (token == "UNDERCARRIAGE") {
137 if (debug_lvl > 0) cout << fgcyan << "\n Reading Landing Gear" << fgdef << endl;
138 if (!ReadUndercarriage(AC_cfg)) return false;
139 } else if (token == "PROPULSION") {
140 if (debug_lvl > 0) cout << fgcyan << "\n Reading Propulsion" << fgdef << endl;
141 if (!ReadPropulsion(AC_cfg)) return false;
142 } else if (token == "FLIGHT_CONTROL") {
143 if (debug_lvl > 0) cout << fgcyan << "\n Reading Flight Control" << fgdef << endl;
144 if (!ReadFlightControls(AC_cfg)) return false;
145 } else if (token == "OUTPUT") {
146 if (debug_lvl > 0) cout << fgcyan << "\n Reading Output directives" << fgdef << endl;
147 if (!ReadOutput(AC_cfg)) return false;
154 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156 bool FGAircraft::Run(void)
158 if (!FGModel::Run()) { // if false then execute this Run()
159 vForces.InitMatrix();
160 vForces += Aerodynamics->GetForces();
161 vForces += Inertial->GetForces();
162 vForces += Propulsion->GetForces();
163 vForces += GroundReactions->GetForces();
165 vMoments.InitMatrix();
166 vMoments += Aerodynamics->GetMoments();
167 vMoments += Propulsion->GetMoments();
168 vMoments += GroundReactions->GetMoments();
170 vBodyAccel = vForces/MassBalance->GetMass();
172 vNcg = vBodyAccel/Inertial->gravity();
174 vNwcg = State->GetTb2s() * vNcg;
175 vNwcg(3) = -1*vNwcg(3) + 1;
177 if (alphaclmax != 0) {
178 if (Translation->Getalpha() > 0.85*alphaclmax) {
179 impending_stall = 10*(Translation->Getalpha()/alphaclmax - 0.85);
186 } else { // skip Run() execution this time
191 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193 float FGAircraft::GetNlf(void)
198 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200 bool FGAircraft::ReadPrologue(FGConfigFile* AC_cfg)
202 string token = AC_cfg->GetValue();
204 AircraftName = AC_cfg->GetValue("NAME");
205 if (debug_lvl > 0) cout << underon << "Reading Aircraft Configuration File"
206 << underoff << ": " << highint << AircraftName << normint << endl;
207 scratch = AC_cfg->GetValue("VERSION").c_str();
209 CFGVersion = AC_cfg->GetValue("VERSION");
212 cout << " Version: " << highint << CFGVersion
214 if (CFGVersion != needed_cfg_version) {
215 cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT."
216 " RESULTS WILL BE UNPREDICTABLE !!" << endl;
217 cerr << "Current version needed is: " << needed_cfg_version << endl;
218 cerr << " You have version: " << CFGVersion << endl << fgdef << endl;
224 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
226 bool FGAircraft::ReadMetrics(FGConfigFile* AC_cfg)
230 double EW, bixx, biyy, bizz, bixy, bixz;
231 double pmWt, pmX, pmY, pmZ;
232 FGColumnVector3 vbaseXYZcg;
234 AC_cfg->GetNextConfigLine();
236 while ((token = AC_cfg->GetValue()) != string("/METRICS")) {
237 *AC_cfg >> parameter;
238 if (parameter == "AC_WINGAREA") {
240 if (debug_lvl > 0) cout << " WingArea: " << WingArea << endl;
241 } else if (parameter == "AC_WINGSPAN") {
243 if (debug_lvl > 0) cout << " WingSpan: " << WingSpan << endl;
244 } else if (parameter == "AC_WINGINCIDENCE") {
245 *AC_cfg >> WingIncidence;
246 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
247 } else if (parameter == "AC_CHORD") {
249 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
250 } else if (parameter == "AC_HTAILAREA") {
251 *AC_cfg >> HTailArea;
252 if (debug_lvl > 0) cout << " H. Tail Area: " << HTailArea << endl;
253 } else if (parameter == "AC_HTAILARM") {
255 if (debug_lvl > 0) cout << " H. Tail Arm: " << HTailArm << endl;
256 } else if (parameter == "AC_VTAILAREA") {
257 *AC_cfg >> VTailArea;
258 if (debug_lvl > 0) cout << " V. Tail Area: " << VTailArea << endl;
259 } else if (parameter == "AC_VTAILARM") {
261 if (debug_lvl > 0) cout << " V. Tail Arm: " << VTailArm << endl;
262 } else if (parameter == "AC_IXX") {
264 if (debug_lvl > 0) cout << " baseIxx: " << bixx << endl;
265 MassBalance->SetBaseIxx(bixx);
266 } else if (parameter == "AC_IYY") {
268 if (debug_lvl > 0) cout << " baseIyy: " << biyy << endl;
269 MassBalance->SetBaseIyy(biyy);
270 } else if (parameter == "AC_IZZ") {
272 if (debug_lvl > 0) cout << " baseIzz: " << bizz << endl;
273 MassBalance->SetBaseIzz(bizz);
274 } else if (parameter == "AC_IXY") {
276 if (debug_lvl > 0) cout << " baseIxy: " << bixy << endl;
277 MassBalance->SetBaseIxy(bixy);
278 } else if (parameter == "AC_IXZ") {
280 if (debug_lvl > 0) cout << " baseIxz: " << bixz << endl;
281 MassBalance->SetBaseIxz(bixz);
282 } else if (parameter == "AC_EMPTYWT") {
284 MassBalance->SetEmptyWeight(EW);
285 if (debug_lvl > 0) cout << " EmptyWeight: " << EW << endl;
286 } else if (parameter == "AC_CGLOC") {
287 *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
288 MassBalance->SetBaseCG(vbaseXYZcg);
289 if (debug_lvl > 0) cout << " CG (x, y, z): " << vbaseXYZcg << endl;
290 } else if (parameter == "AC_EYEPTLOC") {
291 *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
292 if (debug_lvl > 0) cout << " Eyepoint (x, y, z): " << vXYZep << endl;
293 } else if (parameter == "AC_AERORP") {
294 *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
295 if (debug_lvl > 0) cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
296 } else if (parameter == "AC_ALPHALIMITS") {
297 *AC_cfg >> alphaclmin >> alphaclmax;
298 if (debug_lvl > 0) cout << " Maximum Alpha: " << alphaclmax
299 << " Minimum Alpha: " << alphaclmin
301 } else if (parameter == "AC_POINTMASS") {
302 *AC_cfg >> pmWt >> pmX >> pmY >> pmZ;
303 if (debug_lvl > 0) cout << " Point Mass Object: " << pmWt << " lbs. at "
304 << "X, Y, Z (in.): " << pmX << " " << pmY << " " << pmZ
309 // calculate some derived parameters
311 lbarh = HTailArm/cbar;
312 lbarv = VTailArm/cbar;
313 if (WingArea != 0.0) {
314 vbarh = HTailArm*HTailArea / (cbar*WingArea);
315 vbarv = VTailArm*VTailArea / (cbar*WingArea);
321 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323 bool FGAircraft::ReadPropulsion(FGConfigFile* AC_cfg)
325 if (!Propulsion->Load(AC_cfg)) {
326 cerr << " Propulsion not successfully loaded" << endl;
332 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334 bool FGAircraft::ReadFlightControls(FGConfigFile* AC_cfg)
336 if (!FCS->Load(AC_cfg)) {
337 cerr << " Flight Controls not successfully loaded" << endl;
343 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345 bool FGAircraft::ReadAerodynamics(FGConfigFile* AC_cfg)
347 if (!Aerodynamics->Load(AC_cfg)) {
348 cerr << " Aerodynamics not successfully loaded" << endl;
354 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
356 bool FGAircraft::ReadUndercarriage(FGConfigFile* AC_cfg)
358 if (!GroundReactions->Load(AC_cfg)) {
359 cerr << " Ground Reactions not successfully loaded" << endl;
365 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
367 bool FGAircraft::ReadOutput(FGConfigFile* AC_cfg)
369 if (!Output->Load(AC_cfg)) {
370 cerr << " Output not successfully loaded" << endl;
376 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
377 // The bitmasked value choices are as follows:
378 // unset: In this case (the default) JSBSim would only print
379 // out the normally expected messages, essentially echoing
380 // the config files as they are read. If the environment
381 // variable is not set, debug_lvl is set to 1 internally
382 // 0: This requests JSBSim not to output any messages
384 // 1: This value explicity requests the normal JSBSim
386 // 2: This value asks for a message to be printed out when
387 // a class is instantiated
388 // 4: When this value is set, a message is displayed when a
389 // FGModel object executes its Run() method
390 // 8: When this value is set, various runtime state variables
391 // are printed out periodically
392 // 16: When set various parameters are sanity checked and
393 // a message is printed out when they go out of bounds
395 void FGAircraft::Debug(int from)
397 if (debug_lvl <= 0) return;
399 if (debug_lvl & 1) { // Standard console startup message output
400 if (from == 0) { // Constructor
403 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
404 if (from == 0) cout << "Instantiated: FGAircraft" << endl;
405 if (from == 1) cout << "Destroyed: FGAircraft" << endl;
407 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
409 if (debug_lvl & 8 ) { // Runtime state variables
411 if (debug_lvl & 16) { // Sanity checking
413 if (debug_lvl & 32) { // Turbulence