![]() |
JSBSim Flight Dynamics Model 1.0 (23 February 2013)
An Open Source Flight Dynamics and Control Software Library in C++
|
00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00002 00003 Header: FGJSBBase.h 00004 Author: Jon S. Berndt 00005 Date started: 07/01/01 00006 00007 ------------- Copyright (C) 2001 Jon S. Berndt (jon@jsbsim.org) ------------- 00008 00009 This program is free software; you can redistribute it and/or modify it under 00010 the terms of the GNU Lesser General Public License as published by the Free Software 00011 Foundation; either version 2 of the License, or (at your option) any later 00012 version. 00013 00014 This program is distributed in the hope that it will be useful, but WITHOUT 00015 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00016 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00017 details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA. 00022 00023 Further information about the GNU Lesser General Public License can also be found on 00024 the world wide web at http://www.gnu.org. 00025 00026 HISTORY 00027 -------------------------------------------------------------------------------- 00028 07/01/01 JSB Created 00029 00030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00031 SENTRY 00032 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00033 00034 #ifndef FGJSBBASE_H 00035 #define FGJSBBASE_H 00036 00037 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00038 INCLUDES 00039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00040 00041 #include <float.h> 00042 #include <queue> 00043 #include <string> 00044 #include <cmath> 00045 00046 using std::min; 00047 using std::max; 00048 00049 #include "input_output/string_utilities.h" 00050 00051 #ifndef M_PI 00052 # define M_PI 3.14159265358979323846 00053 #endif 00054 00055 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00056 DEFINITIONS 00057 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00058 00059 #define ID_JSBBASE "$Id: FGJSBBase.h,v 1.36 2012/03/25 11:05:36 bcoconni Exp $" 00060 00061 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00062 FORWARD DECLARATIONS 00063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00064 00065 namespace JSBSim { 00066 00067 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00068 CLASS DOCUMENTATION 00069 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00070 00078 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00079 CLASS DECLARATION 00080 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00081 00082 class FGJSBBase { 00083 public: 00085 FGJSBBase() {}; 00086 00088 virtual ~FGJSBBase() {}; 00089 00091 class Message { 00092 public: 00093 unsigned int fdmId; 00094 unsigned int messageId; 00095 std::string text; 00096 std::string subsystem; 00097 enum mType {eText, eInteger, eDouble, eBool} type; 00098 bool bVal; 00099 int iVal; 00100 double dVal; 00101 }; 00102 00104 class Filter { 00105 double prev_in; 00106 double prev_out; 00107 double ca; 00108 double cb; 00109 public: Filter(void) {} 00110 public: Filter(double coeff, double dt) { 00111 prev_in = prev_out = 0.0; 00112 double denom = 2.0 + coeff*dt; 00113 ca = coeff*dt/denom; 00114 cb = (2.0 - coeff*dt)/denom; 00115 } 00116 public: double execute(double in) { 00117 double out = (in + prev_in)*ca + prev_out*cb; 00118 prev_in = in; 00119 prev_out = out; 00120 return out; 00121 } 00122 }; 00123 00125 00126 00127 static char highint[5]; 00129 static char halfint[5]; 00131 static char normint[6]; 00133 static char reset[5]; 00135 static char underon[5]; 00137 static char underoff[6]; 00139 static char fgblue[6]; 00141 static char fgcyan[6]; 00143 static char fgred[6]; 00145 static char fggreen[6]; 00147 static char fgdef[6]; 00149 00151 00152 00155 void PutMessage(const Message& msg); 00159 void PutMessage(const std::string& text); 00164 void PutMessage(const std::string& text, bool bVal); 00169 void PutMessage(const std::string& text, int iVal); 00174 void PutMessage(const std::string& text, double dVal); 00177 int SomeMessages(void); 00180 void ProcessMessage(void); 00184 Message* ProcessNextMessage(void); 00186 00189 std::string GetVersion(void) {return JSBSim_version;} 00190 00192 void disableHighLighting(void); 00193 00194 static short debug_lvl; 00195 00199 static double KelvinToFahrenheit (double kelvin) { 00200 return 1.8*kelvin - 459.4; 00201 } 00202 00206 static double CelsiusToRankine (double celsius) { 00207 return celsius * 1.8 + 491.67; 00208 } 00209 00213 static double RankineToCelsius (double rankine) { 00214 return (rankine - 491.67)/1.8; 00215 } 00216 00220 static double KelvinToRankine (double kelvin) { 00221 return kelvin * 1.8; 00222 } 00223 00227 static double RankineToKelvin (double rankine) { 00228 return rankine/1.8; 00229 } 00230 00234 static double FahrenheitToCelsius (double fahrenheit) { 00235 return (fahrenheit - 32.0)/1.8; 00236 } 00237 00241 static double CelsiusToFahrenheit (double celsius) { 00242 return celsius * 1.8 + 32.0; 00243 } 00244 00248 static double CelsiusToKelvin (double celsius) { 00249 return celsius + 273.15; 00250 } 00251 00255 static double KelvinToCelsius (double kelvin) { 00256 return kelvin - 273.15; 00257 } 00258 00269 static double VcalibratedFromMach(double mach, double p, double psl, double rhosl); 00270 00280 static double MachFromVcalibrated(double vcas, double p, double psl, double rhosl); 00281 00286 static bool EqualToRoundoff(double a, double b) { 00287 double eps = 2.0*DBL_EPSILON; 00288 return std::fabs(a - b) <= eps * max(std::fabs(a), std::fabs(b)); 00289 } 00290 00295 static bool EqualToRoundoff(float a, float b) { 00296 float eps = 2.0*FLT_EPSILON; 00297 return std::fabs(a - b) <= eps * max(std::fabs(a), std::fabs(b)); 00298 } 00299 00304 static bool EqualToRoundoff(float a, double b) { 00305 return EqualToRoundoff(a, (float)b); 00306 } 00307 00312 static bool EqualToRoundoff(double a, float b) { 00313 return EqualToRoundoff((float)a, b); 00314 } 00315 00318 static double Constrain(double min, double value, double max) { 00319 return value<min?(min):(value>max?(max):(value)); 00320 } 00321 00322 static double sign(double num) {return num>=0.0?1.0:-1.0;} 00323 00324 protected: 00325 static Message localMsg; 00326 00327 static std::queue <Message> Messages; 00328 00329 void Debug(int) {}; 00330 00331 static unsigned int messageId; 00332 00333 static const double radtodeg; 00334 static const double degtorad; 00335 static const double hptoftlbssec; 00336 static const double psftoinhg; 00337 static const double psftopa; 00338 static const double fpstokts; 00339 static const double ktstofps; 00340 static const double inchtoft; 00341 static const double in3tom3; 00342 static const double m3toft3; 00343 static const double inhgtopa; 00344 static const double fttom; 00345 static double Reng; // Specific Gas Constant,ft^2/(sec^2*R) 00346 static double Rstar; 00347 static double Mair; 00348 static const double SHRatio; 00349 static const double lbtoslug; 00350 static const double slugtolb; 00351 static const double kgtolb; 00352 static const double kgtoslug; 00353 static const std::string needed_cfg_version; 00354 static const std::string JSBSim_version; 00355 00356 static std::string CreateIndexedPropertyName(const std::string& Property, int index); 00357 00358 static double GaussianRandomNumber(void); 00359 00360 public: 00362 enum {eL = 1, eM, eN }; 00364 enum {eP = 1, eQ, eR }; 00366 enum {eU = 1, eV, eW }; 00368 enum {eX = 1, eY, eZ }; 00370 enum {ePhi = 1, eTht, ePsi }; 00372 enum {eDrag = 1, eSide, eLift }; 00374 enum {eRoll = 1, ePitch, eYaw }; 00376 enum {eNorth = 1, eEast, eDown }; 00378 enum {eLat = 1, eLong, eRad }; 00380 enum {inNone = 0, inDegrees, inRadians, inMeters, inFeet }; 00381 00382 }; 00383 00384 } 00385 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00386 #endif 00387