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"
77 #include "FGFDMExec.h"
78 #include "FGPosition.h"
79 #include "FGPropertyManager.h"
83 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
87 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
91 static const char *IdSrc = "$Id$";
92 static const char *IdHdr = ID_AIRCRAFT;
94 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
98 FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
102 HTailArea = VTailArea = 0.0;
103 HTailArm = VTailArm = 0.0;
113 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 FGAircraft::~FGAircraft()
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 bool FGAircraft::Run(void)
125 if (!FGModel::Run()) { // if false then execute this Run()
126 vForces.InitMatrix();
127 vForces += Aerodynamics->GetForces();
128 vForces += Inertial->GetForces();
129 vForces += Propulsion->GetForces();
130 vForces += GroundReactions->GetForces();
132 vMoments.InitMatrix();
133 vMoments += Aerodynamics->GetMoments();
134 vMoments += Propulsion->GetMoments();
135 vMoments += GroundReactions->GetMoments();
137 vBodyAccel = vForces/MassBalance->GetMass();
139 vNcg = vBodyAccel/Inertial->gravity();
141 vNwcg = State->GetTb2s() * vNcg;
142 vNwcg(3) = -1*vNwcg(3) + 1;
145 } else { // skip Run() execution this time
150 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152 float FGAircraft::GetNlf(void)
154 return -1*Aerodynamics->GetvFs(3)/MassBalance->GetWeight();
157 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 bool FGAircraft::Load(FGConfigFile* AC_cfg)
163 double EW, bixx, biyy, bizz, bixy, bixz, biyz;
164 double pmWt, pmX, pmY, pmZ;
165 FGColumnVector3 vbaseXYZcg;
167 bixx = biyy = bizz = bixy = bixz = biyz = 0.0;
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 << " Incidence: " << WingIncidence << 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 << " slug-ft2" << endl;
200 } else if (parameter == "AC_IYY") {
202 if (debug_lvl > 0) cout << " baseIyy: " << biyy << " slug-ft2" << endl;
203 } else if (parameter == "AC_IZZ") {
205 if (debug_lvl > 0) cout << " baseIzz: " << bizz << " slug-ft2" << endl;
206 } else if (parameter == "AC_IXY") {
208 if (debug_lvl > 0) cout << " baseIxy: " << bixy << " slug-ft2" << endl;
209 } else if (parameter == "AC_IXZ") {
211 if (debug_lvl > 0) cout << " baseIxz: " << bixz << " slug-ft2" << endl;
212 } else if (parameter == "AC_IYZ") {
214 if (debug_lvl > 0) cout << " baseIyz: " << biyz << " slug-ft2" << endl;
215 } else if (parameter == "AC_EMPTYWT") {
217 MassBalance->SetEmptyWeight(EW);
218 if (debug_lvl > 0) cout << " EmptyWeight: " << EW << " lbm" << endl;
219 } else if (parameter == "AC_CGLOC") {
220 *AC_cfg >> vbaseXYZcg(eX) >> vbaseXYZcg(eY) >> vbaseXYZcg(eZ);
221 MassBalance->SetBaseCG(vbaseXYZcg);
222 if (debug_lvl > 0) cout << " CG (x, y, z): " << vbaseXYZcg << endl;
223 } else if (parameter == "AC_EYEPTLOC") {
224 *AC_cfg >> vXYZep(eX) >> vXYZep(eY) >> vXYZep(eZ);
225 if (debug_lvl > 0) cout << " Eyepoint (x, y, z): " << vXYZep << endl;
226 } else if (parameter == "AC_AERORP") {
227 *AC_cfg >> vXYZrp(eX) >> vXYZrp(eY) >> vXYZrp(eZ);
228 if (debug_lvl > 0) cout << " Ref Pt (x, y, z): " << vXYZrp << endl;
229 } else if (parameter == "AC_VRP") {
230 *AC_cfg >> vXYZvrp(eX) >> vXYZvrp(eY) >> vXYZvrp(eZ);
231 if (debug_lvl > 0) cout << " Visual Ref Pt (x, y, z): " << vXYZvrp << endl;
232 Position->SetVRP(vXYZvrp);
233 } else if (parameter == "AC_POINTMASS") {
234 *AC_cfg >> pmWt >> pmX >> pmY >> pmZ;
235 MassBalance->AddPointMass(pmWt, pmX, pmY, pmZ);
236 if (debug_lvl > 0) cout << " Point Mass Object: " << pmWt << " lbs. at "
237 << "X, Y, Z (in.): " << pmX << " " << pmY << " " << pmZ
242 MassBalance->SetAircraftBaseInertias(FGMatrix33( bixx, -bixy, -bixz,
244 -bixz, -biyz, bizz ));
246 // calculate some derived parameters
248 lbarh = HTailArm/cbar;
249 lbarv = VTailArm/cbar;
250 if (WingArea != 0.0) {
251 vbarh = HTailArm*HTailArea / (cbar*WingArea);
252 vbarv = VTailArm*VTailArea / (cbar*WingArea);
258 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
260 void FGAircraft::bind(void)
262 typedef double (FGAircraft::*PMF)(int) const;
263 PropertyManager->Tie("metrics/Sw-sqft", this,
264 &FGAircraft::GetWingArea);
265 PropertyManager->Tie("metrics/bw-ft", this,
266 &FGAircraft::GetWingSpan);
267 PropertyManager->Tie("metrics/cbarw-ft", this,
268 &FGAircraft::Getcbar);
269 PropertyManager->Tie("metrics/iw-deg", this,
270 &FGAircraft::GetWingIncidence);
271 PropertyManager->Tie("metrics/Sh-sqft", this,
272 &FGAircraft::GetHTailArea);
273 PropertyManager->Tie("metrics/lh-ft", this,
274 &FGAircraft::GetHTailArm);
275 PropertyManager->Tie("metrics/Sv-sqft", this,
276 &FGAircraft::GetVTailArea);
277 PropertyManager->Tie("metrics/lv-ft", this,
278 &FGAircraft::GetVTailArm);
279 PropertyManager->Tie("metrics/lh-norm", this,
280 &FGAircraft::Getlbarh);
281 PropertyManager->Tie("metrics/lv-norm", this,
282 &FGAircraft::Getlbarv);
283 PropertyManager->Tie("metrics/vbarh-norm", this,
284 &FGAircraft::Getvbarh);
285 PropertyManager->Tie("metrics/vbarv-norm", this,
286 &FGAircraft::Getvbarv);
287 PropertyManager->Tie("moments/l-total-lbsft", this,1,
288 (PMF)&FGAircraft::GetMoments);
289 PropertyManager->Tie("moments/m-total-lbsft", this,2,
290 (PMF)&FGAircraft::GetMoments);
291 PropertyManager->Tie("moments/n-total-lbsft", this,3,
292 (PMF)&FGAircraft::GetMoments);
293 PropertyManager->Tie("forces/fbx-total-lbs", this,1,
294 (PMF)&FGAircraft::GetForces);
295 PropertyManager->Tie("forces/fby-total-lbs", this,2,
296 (PMF)&FGAircraft::GetForces);
297 PropertyManager->Tie("forces/fbz-total-lbs", this,3,
298 (PMF)&FGAircraft::GetForces);
299 PropertyManager->Tie("metrics/aero-rp-x-in", this,1,
300 (PMF)&FGAircraft::GetXYZrp);
301 PropertyManager->Tie("metrics/aero-rp-y-in", this,2,
302 (PMF)&FGAircraft::GetXYZrp);
303 PropertyManager->Tie("metrics/aero-rp-z-in", this,3,
304 (PMF)&FGAircraft::GetXYZrp);
305 PropertyManager->Tie("metrics/eyepoint-x-in", this,1,
306 (PMF)&FGAircraft::GetXYZep);
307 PropertyManager->Tie("metrics/eyepoint-y-in", this,2,
308 (PMF)&FGAircraft::GetXYZep);
309 PropertyManager->Tie("metrics/eyepoint-z-in", this,3,
310 (PMF)&FGAircraft::GetXYZep);
311 PropertyManager->Tie("metrics/visualrefpoint-x-in", this,1,
312 (PMF)&FGAircraft::GetXYZvrp);
313 PropertyManager->Tie("metrics/visualrefpoint-y-in", this,2,
314 (PMF)&FGAircraft::GetXYZvrp);
315 PropertyManager->Tie("metrics/visualrefpoint-z-in", this,3,
316 (PMF)&FGAircraft::GetXYZvrp);
319 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321 void FGAircraft::unbind(void)
323 PropertyManager->Untie("metrics/Sw-sqft");
324 PropertyManager->Untie("metrics/bw-ft");
325 PropertyManager->Untie("metrics/cbarw-ft");
326 PropertyManager->Untie("metrics/iw-deg");
327 PropertyManager->Untie("metrics/Sh-sqft");
328 PropertyManager->Untie("metrics/lh-ft");
329 PropertyManager->Untie("metrics/Sv-sqft");
330 PropertyManager->Untie("metrics/lv-ft");
331 PropertyManager->Untie("metrics/lh-norm");
332 PropertyManager->Untie("metrics/lv-norm");
333 PropertyManager->Untie("metrics/vbarh-norm");
334 PropertyManager->Untie("metrics/vbarv-norm");
335 PropertyManager->Untie("moments/l-total-lbsft");
336 PropertyManager->Untie("moments/m-total-lbsft");
337 PropertyManager->Untie("moments/n-total-lbsft");
338 PropertyManager->Untie("forces/fbx-total-lbs");
339 PropertyManager->Untie("forces/fby-total-lbs");
340 PropertyManager->Untie("forces/fbz-total-lbs");
341 PropertyManager->Untie("metrics/aero-rp-x-in");
342 PropertyManager->Untie("metrics/aero-rp-y-in");
343 PropertyManager->Untie("metrics/aero-rp-z-in");
344 PropertyManager->Untie("metrics/eyepoint-x-in");
345 PropertyManager->Untie("metrics/eyepoint-y-in");
346 PropertyManager->Untie("metrics/eyepoint-z-in");
347 PropertyManager->Untie("metrics/visualrefpoint-x-in");
348 PropertyManager->Untie("metrics/visualrefpoint-y-in");
349 PropertyManager->Untie("metrics/visualrefpoint-z-in");
352 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353 // The bitmasked value choices are as follows:
354 // unset: In this case (the default) JSBSim would only print
355 // out the normally expected messages, essentially echoing
356 // the config files as they are read. If the environment
357 // variable is not set, debug_lvl is set to 1 internally
358 // 0: This requests JSBSim not to output any messages
360 // 1: This value explicity requests the normal JSBSim
362 // 2: This value asks for a message to be printed out when
363 // a class is instantiated
364 // 4: When this value is set, a message is displayed when a
365 // FGModel object executes its Run() method
366 // 8: When this value is set, various runtime state variables
367 // are printed out periodically
368 // 16: When set various parameters are sanity checked and
369 // a message is printed out when they go out of bounds
371 void FGAircraft::Debug(int from)
373 if (debug_lvl <= 0) return;
375 if (debug_lvl & 1) { // Standard console startup message output
376 if (from == 0) { // Constructor
379 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
380 if (from == 0) cout << "Instantiated: FGAircraft" << endl;
381 if (from == 1) cout << "Destroyed: FGAircraft" << endl;
383 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
385 if (debug_lvl & 8 ) { // Runtime state variables
387 if (debug_lvl & 16) { // Sanity checking
389 if (debug_lvl & 64) {
390 if (from == 0) { // Constructor
391 cout << IdSrc << endl;
392 cout << IdHdr << endl;
397 } // namespace JSBSim