]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/models/FGAircraft.cpp
Sync with JSBSim cvs + Anders' patch to get it working with FlightGear.
[flightgear.git] / src / FDM / JSBSim / models / FGAircraft.cpp
index edce3e0a3fbcb5b3ea15d9f452fdda8087557f68..0ed6ac74f33975f09d0dcdca72953d51d0e7ab09 100644 (file)
@@ -6,7 +6,7 @@
  Purpose:      Encapsulates an aircraft
  Called by:    FGFDMExec
 
- ------------- Copyright (C) 1999  Jon S. Berndt (jsb@hal-pc.org) -------------
+ ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
 
  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU Lesser General Public License as published by the Free Software
@@ -41,32 +41,22 @@ INCLUDES
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#ifdef FGFS
-#  ifndef __BORLANDC__
-#    include <simgear/compiler.h>
-#  endif
-#  ifdef SG_HAVE_STD_INCLUDES
-#    include <cmath>
-#  else
-#    include <math.h>
-#  endif
-#else
-#  if defined (sgi) && !defined(__GNUC__)
-#    include <math.h>
-#  else
-#    include <cmath>
-#  endif
-#endif
+#include <cmath>
 
 #include "FGAircraft.h"
 #include "FGMassBalance.h"
 #include "FGInertial.h"
 #include "FGGroundReactions.h"
+#include "FGExternalReactions.h"
+#include "FGBuoyantForces.h"
 #include "FGAerodynamics.h"
-#include <FGState.h>
-#include <FGFDMExec.h>
+#include "FGFDMExec.h"
 #include "FGPropagate.h"
-#include <input_output/FGPropertyManager.h>
+#include "FGPropulsion.h"
+#include "input_output/FGPropertyManager.h"
+#include <iostream>
+
+using namespace std;
 
 namespace JSBSim {
 
@@ -78,7 +68,7 @@ DEFINITIONS
 GLOBAL DATA
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-static const char *IdSrc = "$Id$";
+static const char *IdSrc = "$Id: FGAircraft.cpp,v 1.28 2010/09/07 00:40:03 jberndt Exp $";
 static const char *IdHdr = ID_AIRCRAFT;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -105,22 +95,37 @@ FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
 
 FGAircraft::~FGAircraft()
 {
-  unbind();
   Debug(1);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
+bool FGAircraft::InitModel(void)
+{
+  if (!FGModel::InitModel()) return false;
+
+  return true;
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
 bool FGAircraft::Run(void)
 {
   if (FGModel::Run()) return true;
   if (FDMExec->Holding()) return false;
 
+  RunPreFunctions();
+
   vForces.InitMatrix();
   if (!HoldDown) {
     vForces += Aerodynamics->GetForces();
     vForces += Propulsion->GetForces();
     vForces += GroundReactions->GetForces();
+    vForces += ExternalReactions->GetForces();
+    vForces += BuoyantForces->GetForces();
+  } else {
+    const FGMatrix33& mTl2b = Propagate->GetTl2b();
+    vForces = mTl2b * FGColumnVector3(0,0,-MassBalance->GetWeight());
   }
 
   vMoments.InitMatrix();
@@ -128,23 +133,27 @@ bool FGAircraft::Run(void)
     vMoments += Aerodynamics->GetMoments();
     vMoments += Propulsion->GetMoments();
     vMoments += GroundReactions->GetMoments();
+    vMoments += ExternalReactions->GetMoments();
+    vMoments += BuoyantForces->GetMoments();
   }
 
   vBodyAccel = vForces/MassBalance->GetMass();
 
-  vNcg = vBodyAccel/Inertial->gravity();
+  vNcg = vBodyAccel/Inertial->SLgravity();
+
+  vNwcg = Aerodynamics->GetTb2w() * vNcg;
+  vNwcg(3) = 1.0 - vNwcg(3);
 
-  vNwcg = State->GetTb2s() * vNcg;
-  vNwcg(3) = -1*vNwcg(3) + 1;
+  RunPostFunctions();
 
   return false;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-double FGAircraft::GetNlf(void)
+double FGAircraft::GetNlf(void) const
 {
-  return -1*Aerodynamics->GetvFs(3)/MassBalance->GetWeight();
+  return -1*Aerodynamics->GetvFw(3)/MassBalance->GetWeight();
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -154,6 +163,8 @@ bool FGAircraft::Load(Element* el)
   string element_name;
   Element* element;
 
+  FGModel::Load(el);
+
   if (el->FindElement("wingarea"))
     WingArea = el->FindElementValueAsNumberConvertTo("wingarea", "FT2");
   if (el->FindElement("wingspan"))
@@ -161,7 +172,7 @@ bool FGAircraft::Load(Element* el)
   if (el->FindElement("chord"))
     cbar = el->FindElementValueAsNumberConvertTo("chord", "FT");
   if (el->FindElement("wing_incidence"))
-    WingIncidence = el->FindElementValueAsNumberConvertTo("wing_incidence", "DEG");
+    WingIncidence = el->FindElementValueAsNumberConvertTo("wing_incidence", "RAD");
   if (el->FindElement("htailarea"))
     HTailArea = el->FindElementValueAsNumberConvertTo("htailarea", "FT2");
   if (el->FindElement("htailarm"))
@@ -191,10 +202,12 @@ bool FGAircraft::Load(Element* el)
     lbarv = VTailArm/cbar;
     if (WingArea != 0.0) {
       vbarh = HTailArm*HTailArea / (cbar*WingArea);
-      vbarv = VTailArm*VTailArea / (cbar*WingArea);
+      vbarv = VTailArm*VTailArea / (WingSpan*WingArea);
     }
   }
 
+  PostLoad(el, PropertyManager);
+
   Debug(2);
 
   return true;
@@ -205,10 +218,11 @@ bool FGAircraft::Load(Element* el)
 void FGAircraft::bind(void)
 {
   typedef double (FGAircraft::*PMF)(int) const;
-  PropertyManager->Tie("metrics/Sw-sqft", this, &FGAircraft::GetWingArea);
+  PropertyManager->Tie("metrics/Sw-sqft", this, &FGAircraft::GetWingArea, &FGAircraft::SetWingArea);
   PropertyManager->Tie("metrics/bw-ft", this, &FGAircraft::GetWingSpan);
   PropertyManager->Tie("metrics/cbarw-ft", this, &FGAircraft::Getcbar);
-  PropertyManager->Tie("metrics/iw-deg", this, &FGAircraft::GetWingIncidence);
+  PropertyManager->Tie("metrics/iw-rad", this, &FGAircraft::GetWingIncidence);
+  PropertyManager->Tie("metrics/iw-deg", this, &FGAircraft::GetWingIncidenceDeg);
   PropertyManager->Tie("metrics/Sh-sqft", this, &FGAircraft::GetHTailArea);
   PropertyManager->Tie("metrics/lh-ft", this, &FGAircraft::GetHTailArm);
   PropertyManager->Tie("metrics/Sv-sqft", this, &FGAircraft::GetVTailArea);
@@ -217,13 +231,6 @@ void FGAircraft::bind(void)
   PropertyManager->Tie("metrics/lv-norm", this, &FGAircraft::Getlbarv);
   PropertyManager->Tie("metrics/vbarh-norm", this, &FGAircraft::Getvbarh);
   PropertyManager->Tie("metrics/vbarv-norm", this, &FGAircraft::Getvbarv);
-  PropertyManager->Tie("forces/hold-down", this, &FGAircraft::GetHoldDown, &FGAircraft::SetHoldDown);
-  PropertyManager->Tie("moments/l-total-lbsft", this, eL, (PMF)&FGAircraft::GetMoments);
-  PropertyManager->Tie("moments/m-total-lbsft", this, eM, (PMF)&FGAircraft::GetMoments);
-  PropertyManager->Tie("moments/n-total-lbsft", this, eN, (PMF)&FGAircraft::GetMoments);
-  PropertyManager->Tie("forces/fbx-total-lbs", this, eX, (PMF)&FGAircraft::GetForces);
-  PropertyManager->Tie("forces/fby-total-lbs", this, eY, (PMF)&FGAircraft::GetForces);
-  PropertyManager->Tie("forces/fbz-total-lbs", this, eZ, (PMF)&FGAircraft::GetForces);
   PropertyManager->Tie("metrics/aero-rp-x-in", this, eX, (PMF)&FGAircraft::GetXYZrp);
   PropertyManager->Tie("metrics/aero-rp-y-in", this, eY, (PMF)&FGAircraft::GetXYZrp);
   PropertyManager->Tie("metrics/aero-rp-z-in", this, eZ, (PMF)&FGAircraft::GetXYZrp);
@@ -233,40 +240,14 @@ void FGAircraft::bind(void)
   PropertyManager->Tie("metrics/visualrefpoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZvrp);
   PropertyManager->Tie("metrics/visualrefpoint-y-in", this, eY, (PMF)&FGAircraft::GetXYZvrp);
   PropertyManager->Tie("metrics/visualrefpoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZvrp);
-}
-
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-void FGAircraft::unbind(void)
-{
-  PropertyManager->Untie("metrics/Sw-sqft");
-  PropertyManager->Untie("metrics/bw-ft");
-  PropertyManager->Untie("metrics/cbarw-ft");
-  PropertyManager->Untie("metrics/iw-deg");
-  PropertyManager->Untie("metrics/Sh-sqft");
-  PropertyManager->Untie("metrics/lh-ft");
-  PropertyManager->Untie("metrics/Sv-sqft");
-  PropertyManager->Untie("metrics/lv-ft");
-  PropertyManager->Untie("metrics/lh-norm");
-  PropertyManager->Untie("metrics/lv-norm");
-  PropertyManager->Untie("metrics/vbarh-norm");
-  PropertyManager->Untie("metrics/vbarv-norm");
-  PropertyManager->Untie("moments/l-total-lbsft");
-  PropertyManager->Untie("moments/m-total-lbsft");
-  PropertyManager->Untie("moments/n-total-lbsft");
-  PropertyManager->Untie("forces/fbx-total-lbs");
-  PropertyManager->Untie("forces/fby-total-lbs");
-  PropertyManager->Untie("forces/fbz-total-lbs");
-  PropertyManager->Untie("forces/hold-down");
-  PropertyManager->Untie("metrics/aero-rp-x-in");
-  PropertyManager->Untie("metrics/aero-rp-y-in");
-  PropertyManager->Untie("metrics/aero-rp-z-in");
-  PropertyManager->Untie("metrics/eyepoint-x-in");
-  PropertyManager->Untie("metrics/eyepoint-y-in");
-  PropertyManager->Untie("metrics/eyepoint-z-in");
-  PropertyManager->Untie("metrics/visualrefpoint-x-in");
-  PropertyManager->Untie("metrics/visualrefpoint-y-in");
-  PropertyManager->Untie("metrics/visualrefpoint-z-in");
+  PropertyManager->Tie("forces/fbx-total-lbs", this, eX, (PMF)&FGAircraft::GetForces);
+  PropertyManager->Tie("forces/fby-total-lbs", this, eY, (PMF)&FGAircraft::GetForces);
+  PropertyManager->Tie("forces/fbz-total-lbs", this, eZ, (PMF)&FGAircraft::GetForces);
+  PropertyManager->Tie("forces/load-factor", this, &FGAircraft::GetNlf);
+  PropertyManager->Tie("forces/hold-down", this, &FGAircraft::GetHoldDown, &FGAircraft::SetHoldDown);
+  PropertyManager->Tie("moments/l-total-lbsft", this, eL, (PMF)&FGAircraft::GetMoments);
+  PropertyManager->Tie("moments/m-total-lbsft", this, eM, (PMF)&FGAircraft::GetMoments);
+  PropertyManager->Tie("moments/n-total-lbsft", this, eN, (PMF)&FGAircraft::GetMoments);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%