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"
85 #include "FGPropertyManager.h"
87 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
91 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
95 static const char *IdSrc = "$Id$";
96 static const char *IdHdr = ID_AIRCRAFT;
98 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
102 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
105 HTailArea = VTailArea = 0.0;
106 HTailArm = VTailArm = 0.0;
115 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 FGAircraft::~FGAircraft()
123 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125 bool FGAircraft::Run(void)
127 if (!FGModel::Run()) { // if false then execute this Run()
128 vForces.InitMatrix();
129 vForces += Aerodynamics->GetForces();
130 vForces += Inertial->GetForces();
131 vForces += Propulsion->GetForces();
132 vForces += GroundReactions->GetForces();
134 vMoments.InitMatrix();
135 vMoments += Aerodynamics->GetMoments();
136 vMoments += Propulsion->GetMoments();
137 vMoments += GroundReactions->GetMoments();
139 vBodyAccel = vForces/MassBalance->GetMass();
141 vNcg = vBodyAccel/Inertial->gravity();
143 vNwcg = State->GetTb2s() * vNcg;
144 vNwcg(3) = -1*vNwcg(3) + 1;
147 } else { // skip Run() execution this time
152 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 float FGAircraft::GetNlf(void)
156 return -1*Aerodynamics->GetvFs(3)/MassBalance->GetWeight();
159 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 bool FGAircraft::Load(FGConfigFile* AC_cfg)
165 double EW, bixx, biyy, bizz, bixy, bixz;
166 double pmWt, pmX, pmY, pmZ;
167 FGColumnVector3 vbaseXYZcg;
169 AC_cfg->GetNextConfigLine();
171 while ((token = AC_cfg->GetValue()) != string("/METRICS")) {
172 *AC_cfg >> parameter;
173 if (parameter == "AC_WINGAREA") {
175 if (debug_lvl > 0) cout << " WingArea: " << WingArea << endl;
176 } else if (parameter == "AC_WINGSPAN") {
178 if (debug_lvl > 0) cout << " WingSpan: " << WingSpan << endl;
179 } else if (parameter == "AC_WINGINCIDENCE") {
180 *AC_cfg >> WingIncidence;
181 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
182 } else if (parameter == "AC_CHORD") {
184 if (debug_lvl > 0) cout << " Chord: " << cbar << endl;
185 } else if (parameter == "AC_HTAILAREA") {
186 *AC_cfg >> HTailArea;
187 if (debug_lvl > 0) cout << " H. Tail Area: " << HTailArea << endl;
188 } else if (parameter == "AC_HTAILARM") {
190 if (debug_lvl > 0) cout << " H. Tail Arm: " << HTailArm << endl;
191 } else if (parameter == "AC_VTAILAREA") {
192 *AC_cfg >> VTailArea;
193 if (debug_lvl > 0) cout << " V. Tail Area: " << VTailArea << endl;
194 } else if (parameter == "AC_VTAILARM") {
196 if (debug_lvl > 0) cout << " V. Tail Arm: " << VTailArm << endl;
197 } else if (parameter == "AC_IXX") {
199 if (debug_lvl > 0) cout << " baseIxx: " << bixx << endl;
200 MassBalance->SetBaseIxx(bixx);
201 } else if (parameter == "AC_IYY") {
203 if (debug_lvl > 0) cout << " baseIyy: " << biyy << endl;
204 MassBalance->SetBaseIyy(biyy);
205 } else if (parameter == "AC_IZZ") {
207 if (debug_lvl > 0) cout << " baseIzz: " << bizz << endl;
208 MassBalance->SetBaseIzz(bizz);
209 } else if (parameter == "AC_IXY") {
211 if (debug_lvl > 0) cout << " baseIxy: " << bixy << endl;
212 MassBalance->SetBaseIxy(bixy);
213 } else if (parameter == "AC_IXZ") {
215 if (debug_lvl > 0) cout << " baseIxz: " << bixz << endl;
216 MassBalance->SetBaseIxz(bixz);
217 } else if (parameter == "AC_EMPTYWT") {
219 MassBalance->SetEmptyWeight(EW);
220 if (debug_lvl > 0) cout << " EmptyWeight: " << EW << endl;
221 } else if (parameter == "AC_CGLOC") {
222 *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
223 MassBalance->SetBaseCG(vbaseXYZcg);
224 if (debug_lvl > 0) cout << " CG (x, y, z): " << vbaseXYZcg << endl;
225 } else if (parameter == "AC_EYEPTLOC") {
226 *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
227 if (debug_lvl > 0) cout << " Eyepoint (x, y, z): " << vXYZep << endl;
228 } else if (parameter == "AC_AERORP") {
229 *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
230 if (debug_lvl > 0) cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
231 } else if (parameter == "AC_POINTMASS") {
232 *AC_cfg >> pmWt >> pmX >> pmY >> pmZ;
233 MassBalance->AddPointMass(pmWt, pmX, pmY, pmZ);
234 if (debug_lvl > 0) cout << " Point Mass Object: " << pmWt << " lbs. at "
235 << "X, Y, Z (in.): " << pmX << " " << pmY << " " << pmZ
240 // calculate some derived parameters
242 lbarh = HTailArm/cbar;
243 lbarv = VTailArm/cbar;
244 if (WingArea != 0.0) {
245 vbarh = HTailArm*HTailArea / (cbar*WingArea);
246 vbarv = VTailArm*VTailArea / (cbar*WingArea);
252 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254 void FGAircraft::bind(void)
256 typedef double (FGAircraft::*PMF)(int) const;
257 PropertyManager->Tie("metrics/Sw-sqft", this,
258 &FGAircraft::GetWingArea);
259 PropertyManager->Tie("metrics/bw-ft", this,
260 &FGAircraft::GetWingSpan);
261 PropertyManager->Tie("metrics/cbarw-ft", this,
262 &FGAircraft::Getcbar);
263 PropertyManager->Tie("metrics/iw-deg", this,
264 &FGAircraft::GetWingIncidence);
265 PropertyManager->Tie("metrics/Sh-sqft", this,
266 &FGAircraft::GetHTailArea);
267 PropertyManager->Tie("metrics/lh-ft", this,
268 &FGAircraft::GetHTailArm);
269 PropertyManager->Tie("metrics/Sv-sqft", this,
270 &FGAircraft::GetVTailArea);
271 PropertyManager->Tie("metrics/lv-ft", this,
272 &FGAircraft::GetVTailArm);
273 PropertyManager->Tie("metrics/lh-norm", this,
274 &FGAircraft::Getlbarh);
275 PropertyManager->Tie("metrics/lv-norm", this,
276 &FGAircraft::Getlbarv);
277 PropertyManager->Tie("metrics/vbarh-norm", this,
278 &FGAircraft::Getvbarh);
279 PropertyManager->Tie("metrics/vbarv-norm", this,
280 &FGAircraft::Getvbarv);
281 PropertyManager->Tie("moments/l-total-lbsft", this,1,
282 (PMF)&FGAircraft::GetMoments);
283 PropertyManager->Tie("moments/m-total-lbsft", this,2,
284 (PMF)&FGAircraft::GetMoments);
285 PropertyManager->Tie("moments/n-total-lbsft", this,3,
286 (PMF)&FGAircraft::GetMoments);
287 PropertyManager->Tie("forces/fbx-total-lbs", this,1,
288 (PMF)&FGAircraft::GetForces);
289 PropertyManager->Tie("forces/fby-total-lbs", this,2,
290 (PMF)&FGAircraft::GetForces);
291 PropertyManager->Tie("forces/fbz-total-lbs", this,3,
292 (PMF)&FGAircraft::GetForces);
293 PropertyManager->Tie("metrics/aero-rp-x-ft", this,1,
294 (PMF)&FGAircraft::GetXYZrp);
295 PropertyManager->Tie("metrics/aero-rp-y-ft", this,2,
296 (PMF)&FGAircraft::GetXYZrp);
297 PropertyManager->Tie("metrics/aero-rp-z-ft", this,3,
298 (PMF)&FGAircraft::GetXYZrp);
299 PropertyManager->Tie("metrics/eyepoint-x-ft", this,1,
300 (PMF)&FGAircraft::GetXYZep);
301 PropertyManager->Tie("metrics/eyepoint-y-ft", this,2,
302 (PMF)&FGAircraft::GetXYZep);
303 PropertyManager->Tie("metrics/eyepoint-z-ft", this,3,
304 (PMF)&FGAircraft::GetXYZep);
307 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
309 void FGAircraft::unbind(void)
311 PropertyManager->Untie("metrics/Sw-sqft");
312 PropertyManager->Untie("metrics/bw-ft");
313 PropertyManager->Untie("metrics/cbarw-ft");
314 PropertyManager->Untie("metrics/iw-deg");
315 PropertyManager->Untie("metrics/Sh-sqft");
316 PropertyManager->Untie("metrics/lh-ft");
317 PropertyManager->Untie("metrics/Sv-sqft");
318 PropertyManager->Untie("metrics/lv-ft");
319 PropertyManager->Untie("metrics/lh-norm");
320 PropertyManager->Untie("metrics/lv-norm");
321 PropertyManager->Untie("metrics/vbarh-norm");
322 PropertyManager->Untie("metrics/vbarv-norm");
323 PropertyManager->Untie("moments/l-total-lbsft");
324 PropertyManager->Untie("moments/m-total-lbsft");
325 PropertyManager->Untie("moments/n-total-lbsft");
326 PropertyManager->Untie("forces/fbx-total-lbs");
327 PropertyManager->Untie("forces/fby-total-lbs");
328 PropertyManager->Untie("forces/fbz-total-lbs");
329 PropertyManager->Untie("metrics/aero-rp-x-ft");
330 PropertyManager->Untie("metrics/aero-rp-y-ft");
331 PropertyManager->Untie("metrics/aero-rp-z-ft");
332 PropertyManager->Untie("metrics/eyepoint-x-ft");
333 PropertyManager->Untie("metrics/eyepoint-y-ft");
334 PropertyManager->Untie("metrics/eyepoint-z-ft");
337 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 // The bitmasked value choices are as follows:
339 // unset: In this case (the default) JSBSim would only print
340 // out the normally expected messages, essentially echoing
341 // the config files as they are read. If the environment
342 // variable is not set, debug_lvl is set to 1 internally
343 // 0: This requests JSBSim not to output any messages
345 // 1: This value explicity requests the normal JSBSim
347 // 2: This value asks for a message to be printed out when
348 // a class is instantiated
349 // 4: When this value is set, a message is displayed when a
350 // FGModel object executes its Run() method
351 // 8: When this value is set, various runtime state variables
352 // are printed out periodically
353 // 16: When set various parameters are sanity checked and
354 // a message is printed out when they go out of bounds
356 void FGAircraft::Debug(int from)
358 if (debug_lvl <= 0) return;
360 if (debug_lvl & 1) { // Standard console startup message output
361 if (from == 0) { // Constructor
364 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
365 if (from == 0) cout << "Instantiated: FGAircraft" << endl;
366 if (from == 1) cout << "Destroyed: FGAircraft" << endl;
368 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
370 if (debug_lvl & 8 ) { // Runtime state variables
372 if (debug_lvl & 16) { // Sanity checking
374 if (debug_lvl & 64) {
375 if (from == 0) { // Constructor
376 cout << IdSrc << endl;
377 cout << IdHdr << endl;