LCOV - code coverage report
Current view: top level - home/jon/JSBSim/src - FGJSBBase.h (source / functions) Hit Total Coverage
Test: JSBSim-Coverage-Statistics Lines: 3 18 16.7 %
Date: 2010-08-24 Functions: 2 4 50.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 34 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
       2                 :            : 
       3                 :            :  Header:       FGJSBBase.h
       4                 :            :  Author:       Jon S. Berndt
       5                 :            :  Date started: 07/01/01
       6                 :            : 
       7                 :            :  ------------- Copyright (C) 2001  Jon S. Berndt (jon@jsbsim.org) -------------
       8                 :            : 
       9                 :            :  This program is free software; you can redistribute it and/or modify it under
      10                 :            :  the terms of the GNU Lesser General Public License as published by the Free Software
      11                 :            :  Foundation; either version 2 of the License, or (at your option) any later
      12                 :            :  version.
      13                 :            : 
      14                 :            :  This program is distributed in the hope that it will be useful, but WITHOUT
      15                 :            :  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      16                 :            :  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      17                 :            :  details.
      18                 :            : 
      19                 :            :  You should have received a copy of the GNU Lesser General Public License along with
      20                 :            :  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
      21                 :            :  Place - Suite 330, Boston, MA  02111-1307, USA.
      22                 :            : 
      23                 :            :  Further information about the GNU Lesser General Public License can also be found on
      24                 :            :  the world wide web at http://www.gnu.org.
      25                 :            : 
      26                 :            : HISTORY
      27                 :            : --------------------------------------------------------------------------------
      28                 :            : 07/01/01  JSB  Created
      29                 :            : 
      30                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      31                 :            : SENTRY
      32                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      33                 :            : 
      34                 :            : #ifndef FGJSBBASE_H
      35                 :            : #define FGJSBBASE_H
      36                 :            : 
      37                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      38                 :            : INCLUDES
      39                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      40                 :            : 
      41                 :            : #include <float.h>
      42                 :            : #include <queue>
      43                 :            : #include <string>
      44                 :            : #include <cmath>
      45                 :            : 
      46                 :            : #include "input_output/string_utilities.h"
      47                 :            : 
      48                 :            : #ifndef M_PI
      49                 :            : #  define M_PI 3.14159265358979323846
      50                 :            : #endif
      51                 :            : 
      52                 :            : #if defined(_MSC_VER) && (_MSC_VER < 1300)
      53                 :            : namespace std
      54                 :            : {
      55                 :            :   template <class T> inline T max(const T& a, const T& b)
      56                 :            :   {
      57                 :            :     return (a > b) ? a : b;
      58                 :            :   }
      59                 :            : }
      60                 :            : #endif
      61                 :            : 
      62                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      63                 :            : DEFINITIONS
      64                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      65                 :            : 
      66                 :            : #define ID_JSBBASE "$Id: FGJSBBase.h,v 1.30 2010/07/01 23:13:19 jberndt Exp $"
      67                 :            : 
      68                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      69                 :            : FORWARD DECLARATIONS
      70                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      71                 :            : 
      72                 :            : namespace JSBSim {
      73                 :            : 
      74                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      75                 :            : CLASS DOCUMENTATION
      76                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      77                 :            : 
      78                 :            : /** JSBSim Base class.
      79                 :            : *   This class provides universal constants, utility functions, messaging
      80                 :            : *   functions, and enumerated constants to JSBSim.
      81                 :            :     @author Jon S. Berndt
      82                 :            :     @version $Id: FGJSBBase.h,v 1.30 2010/07/01 23:13:19 jberndt Exp $
      83                 :            : */
      84                 :            : 
      85                 :            : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      86                 :            : CLASS DECLARATION
      87                 :            : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
      88                 :            : 
      89                 :            : class FGJSBBase {
      90                 :            : public:
      91                 :            :   /// Constructor for FGJSBBase.
      92                 :            :   FGJSBBase() {};
      93                 :            : 
      94                 :            :   /// Destructor for FGJSBBase.
      95                 :            :   ~FGJSBBase() {};
      96                 :            : 
      97                 :            :   /// JSBSim Message structure
      98                 :          4 :   class Message {
      99                 :            :   public:
     100                 :            :     unsigned int fdmId;
     101                 :            :     unsigned int messageId;
     102                 :            :     std::string text;
     103                 :            :     std::string subsystem;
     104                 :            :     enum mType {eText, eInteger, eDouble, eBool} type;
     105                 :            :     bool bVal;
     106                 :            :     int  iVal;
     107                 :            :     double dVal;
     108                 :            :   };
     109                 :            : 
     110                 :            :   /// First order, (low pass / lag) filter
     111                 :            :   class Filter {
     112                 :            :     double prev_in;
     113                 :            :     double prev_out;
     114                 :            :     double ca;
     115                 :            :     double cb;
     116                 :            :     public: Filter(void) {}
     117                 :            :     public: Filter(double coeff, double dt) {
     118                 :          0 :       prev_in = prev_out = 0.0;
     119                 :          0 :       double denom = 2.0 + coeff*dt;
     120                 :          0 :       ca = coeff*dt/denom;
     121                 :          0 :       cb = (2.0 - coeff*dt)/denom;
     122                 :            :     }
     123                 :            :     public: double execute(double in) {
     124                 :          0 :       double out = (in + prev_in)*ca + prev_out*cb;
     125                 :          0 :       prev_in = in;
     126                 :          0 :       prev_out = out;
     127                 :          0 :       return out;
     128                 :            :     }
     129                 :            :   };
     130                 :            : 
     131                 :            :   ///@name JSBSim console output highlighting terms.
     132                 :            :   //@{
     133                 :            :   /// highlights text
     134                 :            :   static char highint[5];
     135                 :            :   /// low intensity text
     136                 :            :   static char halfint[5];
     137                 :            :   /// normal intensity text
     138                 :            :   static char normint[6];
     139                 :            :   /// resets text properties
     140                 :            :   static char reset[5];
     141                 :            :   /// underlines text
     142                 :            :   static char underon[5];
     143                 :            :   /// underline off
     144                 :            :   static char underoff[6];
     145                 :            :   /// blue text
     146                 :            :   static char fgblue[6];
     147                 :            :   /// cyan text
     148                 :            :   static char fgcyan[6];
     149                 :            :   /// red text
     150                 :            :   static char fgred[6];
     151                 :            :   /// green text
     152                 :            :   static char fggreen[6];
     153                 :            :   /// default text
     154                 :            :   static char fgdef[6];
     155                 :            :   //@}
     156                 :            : 
     157                 :            :   ///@name JSBSim Messaging functions
     158                 :            :   //@{
     159                 :            :   /** Places a Message structure on the Message queue.
     160                 :            :       @param msg pointer to a Message structure
     161                 :            :       @return pointer to a Message structure */
     162                 :            :   void PutMessage(const Message& msg);
     163                 :            :   /** Creates a message with the given text and places it on the queue.
     164                 :            :       @param text message text
     165                 :            :       @return pointer to a Message structure */
     166                 :            :   void PutMessage(const std::string& text);
     167                 :            :   /** Creates a message with the given text and boolean value and places it on the queue.
     168                 :            :       @param text message text
     169                 :            :       @param bVal boolean value associated with the message
     170                 :            :       @return pointer to a Message structure */
     171                 :            :   void PutMessage(const std::string& text, bool bVal);
     172                 :            :   /** Creates a message with the given text and integer value and places it on the queue.
     173                 :            :       @param text message text
     174                 :            :       @param iVal integer value associated with the message
     175                 :            :       @return pointer to a Message structure */
     176                 :            :   void PutMessage(const std::string& text, int iVal);
     177                 :            :   /** Creates a message with the given text and double value and places it on the queue.
     178                 :            :       @param text message text
     179                 :            :       @param dVal double value associated with the message
     180                 :            :       @return pointer to a Message structure */
     181                 :            :   void PutMessage(const std::string& text, double dVal);
     182                 :            :   /** Reads the message on the queue (but does not delete it).
     183                 :            :       @return 1 if some messages */
     184                 :            :   int SomeMessages(void);
     185                 :            :   /** Reads the message on the queue and removes it from the queue.
     186                 :            :       This function also prints out the message.*/
     187                 :            :   void ProcessMessage(void);
     188                 :            :   /** Reads the next message on the queue and removes it from the queue.
     189                 :            :       This function also prints out the message.
     190                 :            :       @return a pointer to the message, or NULL if there are no messages.*/
     191                 :            :   Message* ProcessNextMessage(void);
     192                 :            :   //@}
     193                 :            : 
     194                 :            :   /** Returns the version number of JSBSim.
     195                 :            :   *   @return The version number of JSBSim. */
     196                 :          1 :   std::string GetVersion(void) {return JSBSim_version;}
     197                 :            : 
     198                 :            :   /// Disables highlighting in the console output.
     199                 :            :   void disableHighLighting(void);
     200                 :            : 
     201                 :            :   static short debug_lvl;
     202                 :            : 
     203                 :            :   /** Converts from degrees Kelvin to degrees Fahrenheit.
     204                 :            :   *   @param kelvin The temperature in degrees Kelvin.
     205                 :            :   *   @return The temperature in Fahrenheit. */
     206                 :            :   static double KelvinToFahrenheit (double kelvin) {
     207                 :          0 :     return 1.8*kelvin - 459.4;
     208                 :            :   }
     209                 :            : 
     210                 :            :   /** Converts from degrees Celsius to degrees Rankine.
     211                 :            :   *   @param celsius The temperature in degrees Celsius.
     212                 :            :   *   @return The temperature in Rankine. */
     213                 :            :   static double CelsiusToRankine (double celsius) {
     214                 :            :     return celsius * 1.8 + 491.67;
     215                 :            :   }
     216                 :            : 
     217                 :            :   /** Converts from degrees Rankine to degrees Celsius.
     218                 :            :   *   @param rankine The temperature in degrees Rankine.
     219                 :            :   *   @return The temperature in Celsius. */
     220                 :            :   static double RankineToCelsius (double rankine) {
     221                 :      54006 :     return (rankine - 491.67)/1.8;
     222                 :            :   }
     223                 :            : 
     224                 :            :   /** Converts from degrees Kelvin to degrees Rankine.
     225                 :            :   *   @param kelvin The temperature in degrees Kelvin.
     226                 :            :   *   @return The temperature in Rankine. */
     227                 :            :   static double KelvinToRankine (double kelvin) {
     228                 :            :     return kelvin * 1.8;
     229                 :            :   }
     230                 :            : 
     231                 :            :   /** Converts from degrees Rankine to degrees Kelvin.
     232                 :            :   *   @param rankine The temperature in degrees Rankine.
     233                 :            :   *   @return The temperature in Kelvin. */
     234                 :            :   static double RankineToKelvin (double rankine) {
     235                 :          0 :     return rankine/1.8;
     236                 :            :   }
     237                 :            : 
     238                 :            :   /** Converts from degrees Fahrenheit to degrees Celsius.
     239                 :            :   *   @param fahrenheit The temperature in degrees Fahrenheit.
     240                 :            :   *   @return The temperature in Celsius. */
     241                 :            :   static double FahrenheitToCelsius (double fahrenheit) {
     242                 :          0 :     return (fahrenheit - 32.0)/1.8;
     243                 :            :   }
     244                 :            : 
     245                 :            :   /** Converts from degrees Celsius to degrees Fahrenheit.
     246                 :            :   *   @param celsius The temperature in degrees Celsius.
     247                 :            :   *   @return The temperature in Fahrenheit. */
     248                 :            :   static double CelsiusToFahrenheit (double celsius) {
     249                 :            :     return celsius * 1.8 + 32.0;
     250                 :            :   }
     251                 :            : 
     252                 :            :   /** Converts from degrees Celsius to degrees Kelvin
     253                 :            :   *   @param celsius The temperature in degrees Celsius.
     254                 :            :   *   @return The temperature in Kelvin. */
     255                 :            :   static double CelsiusToKelvin (double celsius) {
     256                 :            :     return celsius + 273.15;
     257                 :            :   }
     258                 :            : 
     259                 :            :   /** Converts from degrees Kelvin to degrees Celsius
     260                 :            :   *   @param celsius The temperature in degrees Kelvin.
     261                 :            :   *   @return The temperature in Celsius. */
     262                 :            :   static double KelvinToCelsius (double kelvin) {
     263                 :            :     return kelvin - 273.15;
     264                 :            :   }
     265                 :            : 
     266                 :            :   /** Finite precision comparison.
     267                 :            :       @param a first value to compare
     268                 :            :       @param b second value to compare
     269                 :            :       @return if the two values can be considered equal up to roundoff */
     270                 :            :   static bool EqualToRoundoff(double a, double b) {
     271                 :          0 :     double eps = 2.0*DBL_EPSILON;
     272                 :          0 :     return std::fabs(a - b) <= eps*std::max(std::fabs(a), std::fabs(b));
     273                 :            :   }
     274                 :            : 
     275                 :            :   /** Finite precision comparison.
     276                 :            :       @param a first value to compare
     277                 :            :       @param b second value to compare
     278                 :            :       @return if the two values can be considered equal up to roundoff */
     279                 :            :   static bool EqualToRoundoff(float a, float b) {
     280                 :            :     float eps = 2.0*FLT_EPSILON;
     281                 :            :     return std::fabs(a - b) <= eps*std::max(std::fabs(a), std::fabs(b));
     282                 :            :   }
     283                 :            : 
     284                 :            :   /** Finite precision comparison.
     285                 :            :       @param a first value to compare
     286                 :            :       @param b second value to compare
     287                 :            :       @return if the two values can be considered equal up to roundoff */
     288                 :            :   static bool EqualToRoundoff(float a, double b) {
     289                 :            :     return EqualToRoundoff(a, (float)b);
     290                 :            :   }
     291                 :            : 
     292                 :            :   /** Finite precision comparison.
     293                 :            :       @param a first value to compare
     294                 :            :       @param b second value to compare
     295                 :            :       @return if the two values can be considered equal up to roundoff */
     296                 :            :   static bool EqualToRoundoff(double a, float b) {
     297                 :            :     return EqualToRoundoff((float)a, b);
     298                 :            :   }
     299                 :            :   
     300                 :            :   /** Constrain a value between a minimum and a maximum value.
     301                 :            :   */
     302                 :            :   static double Constrain(double min, double value, double max) {
     303 [ #  # ][ #  # ]:          0 :     return value<min?(min):(value>max?(max):(value));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     304                 :            :   }
     305                 :            :   
     306         [ #  # ]:          0 :   static double sign(double num) {return num>=0.0?1.0:-1.0;}
     307                 :            : 
     308                 :            : protected:
     309                 :            :   static Message localMsg;
     310                 :            : 
     311                 :            :   static std::queue <Message> Messages;
     312                 :            : 
     313                 :            :   void Debug(int) {};
     314                 :            : 
     315                 :            :   static unsigned int messageId;
     316                 :            : 
     317                 :            :   static const double radtodeg;
     318                 :            :   static const double degtorad;
     319                 :            :   static const double hptoftlbssec;
     320                 :            :   static const double psftoinhg;
     321                 :            :   static const double psftopa;
     322                 :            :   static const double fpstokts;
     323                 :            :   static const double ktstofps;
     324                 :            :   static const double inchtoft;
     325                 :            :   static const double in3tom3;
     326                 :            :   static const double m3toft3;
     327                 :            :   static const double inhgtopa;
     328                 :            :   static const double fttom;
     329                 :            :   static double Reng;         // Specific Gas Constant,ft^2/(sec^2*R)
     330                 :            :   static const double SHRatio;
     331                 :            :   static const double lbtoslug;
     332                 :            :   static const double slugtolb;
     333                 :            :   static const double kgtolb;
     334                 :            :   static const double kgtoslug;
     335                 :            :   static const std::string needed_cfg_version;
     336                 :            :   static const std::string JSBSim_version;
     337                 :            : 
     338                 :            :   static std::string CreateIndexedPropertyName(const std::string& Property, int index);
     339                 :            : 
     340                 :            :   static double GaussianRandomNumber(void);
     341                 :            : 
     342                 :            : public:
     343                 :            : /// Moments L, M, N
     344                 :            : enum {eL     = 1, eM,     eN    };
     345                 :            : /// Rates P, Q, R
     346                 :            : enum {eP     = 1, eQ,     eR    };
     347                 :            : /// Velocities U, V, W
     348                 :            : enum {eU     = 1, eV,     eW    };
     349                 :            : /// Positions X, Y, Z
     350                 :            : enum {eX     = 1, eY,     eZ    };
     351                 :            : /// Euler angles Phi, Theta, Psi
     352                 :            : enum {ePhi   = 1, eTht,   ePsi  };
     353                 :            : /// Stability axis forces, Drag, Side force, Lift
     354                 :            : enum {eDrag  = 1, eSide,  eLift };
     355                 :            : /// Local frame orientation Roll, Pitch, Yaw
     356                 :            : enum {eRoll  = 1, ePitch, eYaw  };
     357                 :            : /// Local frame position North, East, Down
     358                 :            : enum {eNorth = 1, eEast,  eDown };
     359                 :            : /// Locations Radius, Latitude, Longitude
     360                 :            : enum {eLat = 1, eLong, eRad     };
     361                 :            : /// Conversion specifiers
     362                 :            : enum {inNone = 0, inDegrees, inRadians, inMeters, inFeet };
     363                 :            : 
     364                 :            : };
     365                 :            : 
     366                 :            : }
     367                 :            : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     368                 :            : #endif
     369                 :            : 

Generated by: LCOV version 1.9