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::Run(void)
124 if (!FGModel::Run()) { // if false then execute this Run()
125 vForces.InitMatrix();
126 vForces += Aerodynamics->GetForces();
127 vForces += Inertial->GetForces();
128 vForces += Propulsion->GetForces();
129 vForces += GroundReactions->GetForces();
131 vMoments.InitMatrix();
132 vMoments += Aerodynamics->GetMoments();
133 vMoments += Propulsion->GetMoments();
134 vMoments += GroundReactions->GetMoments();
136 vBodyAccel = vForces/MassBalance->GetMass();
138 vNcg = vBodyAccel/Inertial->gravity();
140 vNwcg = State->GetTb2s() * vNcg;
141 vNwcg(3) = -1*vNwcg(3) + 1;
143 if (alphaclmax != 0) {
144 if (Translation->Getalpha() > 0.85*alphaclmax) {
145 impending_stall = 10*(Translation->Getalpha()/alphaclmax - 0.85);
152 } else { // skip Run() execution this time
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 float FGAircraft::GetNlf(void)
164 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166 bool FGAircraft::Load(FGConfigFile* AC_cfg)
170 double EW, bixx, biyy, bizz, bixy, bixz;
171 double pmWt, pmX, pmY, pmZ;
172 FGColumnVector3 vbaseXYZcg;
174 AC_cfg->GetNextConfigLine();
176 while ((token = AC_cfg->GetValue()) != string("/METRICS")) {
177 *AC_cfg >> parameter;
178 if (parameter == "AC_WINGAREA") {
180 if (debug_lvl > 0) cout << " WingArea: " << WingArea << endl;
181 } else if (parameter == "AC_WINGSPAN") {
183 if (debug_lvl > 0) cout << " WingSpan: " << WingSpan << endl;
184 } else if (parameter == "AC_WINGINCIDENCE") {
185 *AC_cfg >> WingIncidence;
186 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
187 } else if (parameter == "AC_CHORD") {
189 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
190 } else if (parameter == "AC_HTAILAREA") {
191 *AC_cfg >> HTailArea;
192 if (debug_lvl > 0) cout << " H. Tail Area: " << HTailArea << endl;
193 } else if (parameter == "AC_HTAILARM") {
195 if (debug_lvl > 0) cout << " H. Tail Arm: " << HTailArm << endl;
196 } else if (parameter == "AC_VTAILAREA") {
197 *AC_cfg >> VTailArea;
198 if (debug_lvl > 0) cout << " V. Tail Area: " << VTailArea << endl;
199 } else if (parameter == "AC_VTAILARM") {
201 if (debug_lvl > 0) cout << " V. Tail Arm: " << VTailArm << endl;
202 } else if (parameter == "AC_IXX") {
204 if (debug_lvl > 0) cout << " baseIxx: " << bixx << endl;
205 MassBalance->SetBaseIxx(bixx);
206 } else if (parameter == "AC_IYY") {
208 if (debug_lvl > 0) cout << " baseIyy: " << biyy << endl;
209 MassBalance->SetBaseIyy(biyy);
210 } else if (parameter == "AC_IZZ") {
212 if (debug_lvl > 0) cout << " baseIzz: " << bizz << endl;
213 MassBalance->SetBaseIzz(bizz);
214 } else if (parameter == "AC_IXY") {
216 if (debug_lvl > 0) cout << " baseIxy: " << bixy << endl;
217 MassBalance->SetBaseIxy(bixy);
218 } else if (parameter == "AC_IXZ") {
220 if (debug_lvl > 0) cout << " baseIxz: " << bixz << endl;
221 MassBalance->SetBaseIxz(bixz);
222 } else if (parameter == "AC_EMPTYWT") {
224 MassBalance->SetEmptyWeight(EW);
225 if (debug_lvl > 0) cout << " EmptyWeight: " << EW << endl;
226 } else if (parameter == "AC_CGLOC") {
227 *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
228 MassBalance->SetBaseCG(vbaseXYZcg);
229 if (debug_lvl > 0) cout << " CG (x, y, z): " << vbaseXYZcg << endl;
230 } else if (parameter == "AC_EYEPTLOC") {
231 *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
232 if (debug_lvl > 0) cout << " Eyepoint (x, y, z): " << vXYZep << endl;
233 } else if (parameter == "AC_AERORP") {
234 *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
235 if (debug_lvl > 0) cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
236 } else if (parameter == "AC_ALPHALIMITS") {
237 *AC_cfg >> alphaclmin >> alphaclmax;
238 if (debug_lvl > 0) cout << " Maximum Alpha: " << alphaclmax
239 << " Minimum Alpha: " << alphaclmin
241 } else if (parameter == "AC_POINTMASS") {
242 *AC_cfg >> pmWt >> pmX >> pmY >> pmZ;
243 if (debug_lvl > 0) cout << " Point Mass Object: " << pmWt << " lbs. at "
244 << "X, Y, Z (in.): " << pmX << " " << pmY << " " << pmZ
249 // calculate some derived parameters
251 lbarh = HTailArm/cbar;
252 lbarv = VTailArm/cbar;
253 if (WingArea != 0.0) {
254 vbarh = HTailArm*HTailArea / (cbar*WingArea);
255 vbarv = VTailArm*VTailArea / (cbar*WingArea);
261 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
262 // The bitmasked value choices are as follows:
263 // unset: In this case (the default) JSBSim would only print
264 // out the normally expected messages, essentially echoing
265 // the config files as they are read. If the environment
266 // variable is not set, debug_lvl is set to 1 internally
267 // 0: This requests JSBSim not to output any messages
269 // 1: This value explicity requests the normal JSBSim
271 // 2: This value asks for a message to be printed out when
272 // a class is instantiated
273 // 4: When this value is set, a message is displayed when a
274 // FGModel object executes its Run() method
275 // 8: When this value is set, various runtime state variables
276 // are printed out periodically
277 // 16: When set various parameters are sanity checked and
278 // a message is printed out when they go out of bounds
280 void FGAircraft::Debug(int from)
282 if (debug_lvl <= 0) return;
284 if (debug_lvl & 1) { // Standard console startup message output
285 if (from == 0) { // Constructor
288 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
289 if (from == 0) cout << "Instantiated: FGAircraft" << endl;
290 if (from == 1) cout << "Destroyed: FGAircraft" << endl;
292 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
294 if (debug_lvl & 8 ) { // Runtime state variables
296 if (debug_lvl & 16) { // Sanity checking
298 if (debug_lvl & 64) {
299 if (from == 0) { // Constructor
300 cout << IdSrc << endl;
301 cout << IdHdr << endl;