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