LCOV - code coverage report
Current view: top level - models - FGAircraft.cpp (source / functions) Hit Total Coverage
Test: JSBSim-Coverage-Statistics Lines: 130 140 92.9 %
Date: 2010-08-24 Functions: 11 13 84.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 33 58 56.9 %

           Branch data     Line data    Source code
       1                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       2                 :            : 
       3                 :            :  Module:       FGAircraft.cpp
       4                 :            :  Author:       Jon S. Berndt
       5                 :            :  Date started: 12/12/98
       6                 :            :  Purpose:      Encapsulates an aircraft
       7                 :            :  Called by:    FGFDMExec
       8                 :            : 
       9                 :            :  ------------- Copyright (C) 1999  Jon S. Berndt (jon@jsbsim.org) -------------
      10                 :            : 
      11                 :            :  This program is free software; you can redistribute it and/or modify it under
      12                 :            :  the terms of the GNU Lesser General Public License as published by the Free Software
      13                 :            :  Foundation; either version 2 of the License, or (at your option) any later
      14                 :            :  version.
      15                 :            : 
      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 Lesser General Public License for more
      19                 :            :  details.
      20                 :            : 
      21                 :            :  You should have received a copy of the GNU Lesser 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.
      24                 :            : 
      25                 :            :  Further information about the GNU Lesser General Public License can also be found on
      26                 :            :  the world wide web at http://www.gnu.org.
      27                 :            : 
      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.
      32                 :            : 
      33                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      34                 :            : COMMENTS, REFERENCES,  and NOTES
      35                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      36                 :            : 
      37                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      38                 :            : INCLUDES
      39                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      40                 :            : 
      41                 :            : #include <sys/stat.h>
      42                 :            : #include <sys/types.h>
      43                 :            : 
      44                 :            : #include <cmath>
      45                 :            : 
      46                 :            : #include "FGAircraft.h"
      47                 :            : #include "FGMassBalance.h"
      48                 :            : #include "FGInertial.h"
      49                 :            : #include "FGGroundReactions.h"
      50                 :            : #include "FGExternalReactions.h"
      51                 :            : #include "FGBuoyantForces.h"
      52                 :            : #include "FGAerodynamics.h"
      53                 :            : #include "FGFDMExec.h"
      54                 :            : #include "FGPropagate.h"
      55                 :            : #include "FGPropulsion.h"
      56                 :            : #include "input_output/FGPropertyManager.h"
      57                 :            : #include <iostream>
      58                 :            : 
      59                 :            : using namespace std;
      60                 :            : 
      61                 :            : namespace JSBSim {
      62                 :            : 
      63                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      64                 :            : DEFINITIONS
      65                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      66                 :            : 
      67                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      68                 :            : GLOBAL DATA
      69                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      70                 :            : 
      71                 :            : static const char *IdSrc = "$Id: FGAircraft.cpp,v 1.27 2010/07/27 23:18:19 jberndt Exp $";
      72                 :            : static const char *IdHdr = ID_AIRCRAFT;
      73                 :            : 
      74                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      75                 :            : CLASS IMPLEMENTATION
      76                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      77                 :            : 
      78                 :          1 : FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
      79                 :            : {
      80                 :          1 :   Name = "FGAircraft";
      81                 :          1 :   WingSpan = 0.0;
      82                 :          1 :   HTailArea = VTailArea = 0.0;
      83                 :          1 :   HTailArm  = VTailArm  = 0.0;
      84                 :          1 :   lbarh = lbarv = 0.0;
      85                 :          1 :   vbarh = vbarv = 0.0;
      86                 :          1 :   WingIncidence = 0.0;
      87                 :          1 :   HoldDown = 0;
      88                 :            : 
      89                 :          1 :   bind();
      90                 :            : 
      91                 :          1 :   Debug(0);
      92                 :          1 : }
      93                 :            : 
      94                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      95                 :            : 
      96                 :          1 : FGAircraft::~FGAircraft()
      97                 :            : {
      98                 :          1 :   Debug(1);
      99                 :          1 : }
     100                 :            : 
     101                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     102                 :            : 
     103                 :          1 : bool FGAircraft::InitModel(void)
     104                 :            : {
     105         [ -  + ]:          1 :   if (!FGModel::InitModel()) return false;
     106                 :            : 
     107                 :          1 :   return true;
     108                 :            : }
     109                 :            : 
     110                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     111                 :            : 
     112                 :      54005 : bool FGAircraft::Run(void)
     113                 :            : {
     114         [ -  + ]:      54005 :   if (FGModel::Run()) return true;
     115         [ -  + ]:      54005 :   if (FDMExec->Holding()) return false;
     116                 :            : 
     117                 :      54005 :   RunPreFunctions();
     118                 :            : 
     119                 :      54005 :   vForces.InitMatrix();
     120         [ +  + ]:      54005 :   if (!HoldDown) {
     121                 :     105102 :     vForces += Aerodynamics->GetForces();
     122                 :     105102 :     vForces += Propulsion->GetForces();
     123                 :     105102 :     vForces += GroundReactions->GetForces();
     124                 :     105102 :     vForces += ExternalReactions->GetForces();
     125                 :     105102 :     vForces += BuoyantForces->GetForces();
     126                 :            :   } else {
     127                 :       2908 :     const FGMatrix33& mTl2b = Propagate->GetTl2b();
     128                 :       1454 :     vForces = mTl2b * FGColumnVector3(0,0,-MassBalance->GetWeight());
     129                 :            :   }
     130                 :            : 
     131                 :      54005 :   vMoments.InitMatrix();
     132         [ +  + ]:      54005 :   if (!HoldDown) {
     133                 :     105102 :     vMoments += Aerodynamics->GetMoments();
     134                 :     105102 :     vMoments += Propulsion->GetMoments();
     135                 :     105102 :     vMoments += GroundReactions->GetMoments();
     136                 :     105102 :     vMoments += ExternalReactions->GetMoments();
     137                 :     105102 :     vMoments += BuoyantForces->GetMoments();
     138                 :            :   }
     139                 :            : 
     140                 :      54005 :   vBodyAccel = vForces/MassBalance->GetMass();
     141                 :            : 
     142                 :      54005 :   vNcg = vBodyAccel/Inertial->SLgravity();
     143                 :            : 
     144                 :      54005 :   vNwcg = Aerodynamics->GetTb2w() * vNcg;
     145                 :     162015 :   vNwcg(3) = 1.0 - vNwcg(3);
     146                 :            : 
     147                 :      54005 :   RunPostFunctions();
     148                 :            : 
     149                 :      54005 :   return false;
     150                 :            : }
     151                 :            : 
     152                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     153                 :            : 
     154                 :          1 : double FGAircraft::GetNlf(void) const
     155                 :            : {
     156                 :          1 :   return -1*Aerodynamics->GetvFw(3)/MassBalance->GetWeight();
     157                 :            : }
     158                 :            : 
     159                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     160                 :            : 
     161                 :          1 : bool FGAircraft::Load(Element* el)
     162                 :            : {
     163                 :          1 :   string element_name;
     164                 :            :   Element* element;
     165                 :            : 
     166                 :          1 :   FGModel::Load(el);
     167                 :            : 
     168         [ +  - ]:          1 :   if (el->FindElement("wingarea"))
     169                 :          1 :     WingArea = el->FindElementValueAsNumberConvertTo("wingarea", "FT2");
     170         [ +  - ]:          1 :   if (el->FindElement("wingspan"))
     171                 :          1 :     WingSpan = el->FindElementValueAsNumberConvertTo("wingspan", "FT");
     172         [ +  - ]:          1 :   if (el->FindElement("chord"))
     173                 :          1 :     cbar = el->FindElementValueAsNumberConvertTo("chord", "FT");
     174         [ -  + ]:          1 :   if (el->FindElement("wing_incidence"))
     175                 :          0 :     WingIncidence = el->FindElementValueAsNumberConvertTo("wing_incidence", "RAD");
     176         [ -  + ]:          1 :   if (el->FindElement("htailarea"))
     177                 :          0 :     HTailArea = el->FindElementValueAsNumberConvertTo("htailarea", "FT2");
     178         [ -  + ]:          1 :   if (el->FindElement("htailarm"))
     179                 :          0 :     HTailArm = el->FindElementValueAsNumberConvertTo("htailarm", "FT");
     180         [ -  + ]:          1 :   if (el->FindElement("vtailarea"))
     181                 :          0 :     VTailArea = el->FindElementValueAsNumberConvertTo("vtailarea", "FT2");
     182         [ -  + ]:          1 :   if (el->FindElement("vtailarm"))
     183                 :          0 :     VTailArm = el->FindElementValueAsNumberConvertTo("vtailarm", "FT");
     184                 :            : 
     185                 :            :   // Find all LOCATION elements that descend from this METRICS branch of the
     186                 :            :   // config file. This would be CG location, eyepoint, etc.
     187                 :            : 
     188                 :          1 :   element = el->FindElement("location");
     189         [ +  + ]:          4 :   while (element) {
     190                 :          6 :     element_name = element->GetAttributeValue("name");
     191                 :            : 
     192         [ +  + ]:          3 :     if (element_name == "AERORP") vXYZrp = element->FindElementTripletConvertTo("IN");
     193         [ +  + ]:          2 :     else if (element_name == "EYEPOINT") vXYZep = element->FindElementTripletConvertTo("IN");
     194         [ +  - ]:          1 :     else if (element_name == "VRP") vXYZvrp = element->FindElementTripletConvertTo("IN");
     195                 :            : 
     196                 :          3 :     element = el->FindNextElement("location");
     197                 :            :   }
     198                 :            : 
     199                 :            :   // calculate some derived parameters
     200         [ +  - ]:          1 :   if (cbar != 0.0) {
     201                 :          1 :     lbarh = HTailArm/cbar;
     202                 :          1 :     lbarv = VTailArm/cbar;
     203         [ +  - ]:          1 :     if (WingArea != 0.0) {
     204                 :          1 :       vbarh = HTailArm*HTailArea / (cbar*WingArea);
     205                 :          1 :       vbarv = VTailArm*VTailArea / (WingSpan*WingArea);
     206                 :            :     }
     207                 :            :   }
     208                 :            : 
     209                 :          1 :   PostLoad(el, PropertyManager);
     210                 :            : 
     211                 :          1 :   Debug(2);
     212                 :            : 
     213                 :          1 :   return true;
     214                 :            : }
     215                 :            : 
     216                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     217                 :            : 
     218                 :          1 : void FGAircraft::bind(void)
     219                 :            : {
     220                 :            :   typedef double (FGAircraft::*PMF)(int) const;
     221                 :          1 :   PropertyManager->Tie("metrics/Sw-sqft", this, &FGAircraft::GetWingArea, &FGAircraft::SetWingArea);
     222                 :          1 :   PropertyManager->Tie("metrics/bw-ft", this, &FGAircraft::GetWingSpan);
     223                 :          1 :   PropertyManager->Tie("metrics/cbarw-ft", this, &FGAircraft::Getcbar);
     224                 :          1 :   PropertyManager->Tie("metrics/iw-rad", this, &FGAircraft::GetWingIncidence);
     225                 :          1 :   PropertyManager->Tie("metrics/iw-deg", this, &FGAircraft::GetWingIncidenceDeg);
     226                 :          1 :   PropertyManager->Tie("metrics/Sh-sqft", this, &FGAircraft::GetHTailArea);
     227                 :          1 :   PropertyManager->Tie("metrics/lh-ft", this, &FGAircraft::GetHTailArm);
     228                 :          1 :   PropertyManager->Tie("metrics/Sv-sqft", this, &FGAircraft::GetVTailArea);
     229                 :          1 :   PropertyManager->Tie("metrics/lv-ft", this, &FGAircraft::GetVTailArm);
     230                 :          1 :   PropertyManager->Tie("metrics/lh-norm", this, &FGAircraft::Getlbarh);
     231                 :          1 :   PropertyManager->Tie("metrics/lv-norm", this, &FGAircraft::Getlbarv);
     232                 :          1 :   PropertyManager->Tie("metrics/vbarh-norm", this, &FGAircraft::Getvbarh);
     233                 :          1 :   PropertyManager->Tie("metrics/vbarv-norm", this, &FGAircraft::Getvbarv);
     234                 :          1 :   PropertyManager->Tie("metrics/aero-rp-x-in", this, eX, (PMF)&FGAircraft::GetXYZrp);
     235                 :          1 :   PropertyManager->Tie("metrics/aero-rp-y-in", this, eY, (PMF)&FGAircraft::GetXYZrp);
     236                 :          1 :   PropertyManager->Tie("metrics/aero-rp-z-in", this, eZ, (PMF)&FGAircraft::GetXYZrp);
     237                 :          1 :   PropertyManager->Tie("metrics/eyepoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZep);
     238                 :          1 :   PropertyManager->Tie("metrics/eyepoint-y-in", this, eY,(PMF)&FGAircraft::GetXYZep);
     239                 :          1 :   PropertyManager->Tie("metrics/eyepoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZep);
     240                 :          1 :   PropertyManager->Tie("metrics/visualrefpoint-x-in", this, eX, (PMF)&FGAircraft::GetXYZvrp);
     241                 :          1 :   PropertyManager->Tie("metrics/visualrefpoint-y-in", this, eY, (PMF)&FGAircraft::GetXYZvrp);
     242                 :          1 :   PropertyManager->Tie("metrics/visualrefpoint-z-in", this, eZ, (PMF)&FGAircraft::GetXYZvrp);
     243                 :          1 :   PropertyManager->Tie("forces/fbx-total-lbs", this, eX, (PMF)&FGAircraft::GetForces);
     244                 :          1 :   PropertyManager->Tie("forces/fby-total-lbs", this, eY, (PMF)&FGAircraft::GetForces);
     245                 :          1 :   PropertyManager->Tie("forces/fbz-total-lbs", this, eZ, (PMF)&FGAircraft::GetForces);
     246                 :          1 :   PropertyManager->Tie("forces/load-factor", this, &FGAircraft::GetNlf);
     247                 :          2 :   PropertyManager->Tie("forces/hold-down", this, &FGAircraft::GetHoldDown, &FGAircraft::SetHoldDown);
     248                 :          1 :   PropertyManager->Tie("moments/l-total-lbsft", this, eL, (PMF)&FGAircraft::GetMoments);
     249                 :          1 :   PropertyManager->Tie("moments/m-total-lbsft", this, eM, (PMF)&FGAircraft::GetMoments);
     250                 :          1 :   PropertyManager->Tie("moments/n-total-lbsft", this, eN, (PMF)&FGAircraft::GetMoments);
     251                 :          1 : }
     252                 :            : 
     253                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     254                 :            : //    The bitmasked value choices are as follows:
     255                 :            : //    unset: In this case (the default) JSBSim would only print
     256                 :            : //       out the normally expected messages, essentially echoing
     257                 :            : //       the config files as they are read. If the environment
     258                 :            : //       variable is not set, debug_lvl is set to 1 internally
     259                 :            : //    0: This requests JSBSim not to output any messages
     260                 :            : //       whatsoever.
     261                 :            : //    1: This value explicity requests the normal JSBSim
     262                 :            : //       startup messages
     263                 :            : //    2: This value asks for a message to be printed out when
     264                 :            : //       a class is instantiated
     265                 :            : //    4: When this value is set, a message is displayed when a
     266                 :            : //       FGModel object executes its Run() method
     267                 :            : //    8: When this value is set, various runtime state variables
     268                 :            : //       are printed out periodically
     269                 :            : //    16: When set various parameters are sanity checked and
     270                 :            : //       a message is printed out when they go out of bounds
     271                 :            : 
     272                 :          3 : void FGAircraft::Debug(int from)
     273                 :            : {
     274         [ +  - ]:          3 :   if (debug_lvl <= 0) return;
     275                 :            : 
     276         [ +  - ]:          3 :   if (debug_lvl & 1) { // Standard console startup message output
     277         [ +  + ]:          3 :     if (from == 2) { // Loading
     278                 :          1 :       cout << endl << "  Aircraft Metrics:" << endl;
     279                 :          1 :       cout << "    WingArea: " << WingArea  << endl;
     280                 :          1 :       cout << "    WingSpan: " << WingSpan  << endl;
     281                 :          1 :       cout << "    Incidence: " << WingIncidence << endl;
     282                 :          1 :       cout << "    Chord: " << cbar << endl;
     283                 :          1 :       cout << "    H. Tail Area: " << HTailArea << endl;
     284                 :          1 :       cout << "    H. Tail Arm: " << HTailArm << endl;
     285                 :          1 :       cout << "    V. Tail Area: " << VTailArea << endl;
     286                 :          1 :       cout << "    V. Tail Arm: " << VTailArm << endl;
     287                 :          1 :       cout << "    Eyepoint (x, y, z): " << vXYZep << endl;
     288                 :          1 :       cout << "    Ref Pt (x, y, z): " << vXYZrp << endl;
     289                 :          1 :       cout << "    Visual Ref Pt (x, y, z): " << vXYZvrp << endl;
     290                 :            :     }
     291                 :            :   }
     292         [ -  + ]:          3 :   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
     293         [ #  # ]:          0 :     if (from == 0) cout << "Instantiated: FGAircraft" << endl;
     294         [ #  # ]:          0 :     if (from == 1) cout << "Destroyed:    FGAircraft" << endl;
     295                 :            :   }
     296                 :          3 :   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
     297                 :            :   }
     298                 :          3 :   if (debug_lvl & 8 ) { // Runtime state variables
     299                 :            :   }
     300                 :          3 :   if (debug_lvl & 16) { // Sanity checking
     301                 :            :   }
     302         [ -  + ]:          3 :   if (debug_lvl & 64) {
     303         [ #  # ]:          0 :     if (from == 0) { // Constructor
     304                 :          0 :       cout << IdSrc << endl;
     305                 :          0 :       cout << IdHdr << endl;
     306                 :            :     }
     307                 :            :   }
     308                 :            : }
     309                 :            : 
     310 [ +  + ][ +  - ]:         12 : } // namespace JSBSim

Generated by: LCOV version 1.9