JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGJSBBase.h
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 #define IDENT(a,b) static const char* const (a)[] = {b,(a)[0]}
52 
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 DEFINITIONS
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 
57 #define ID_JSBBASE "$Id: FGJSBBase.h,v 1.45 2016/01/10 12:07:49 bcoconni Exp $"
58 
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 FORWARD DECLARATIONS
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 
63 namespace JSBSim {
64 
65 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 CLASS DOCUMENTATION
67 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77 CLASS DECLARATION
78 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
79 
80 class FGJSBBase {
81 public:
83  FGJSBBase() {};
84 
86  virtual ~FGJSBBase() {};
87 
89  class Message {
90  public:
91  unsigned int fdmId;
92  unsigned int messageId;
93  std::string text;
94  std::string subsystem;
95  enum mType {eText, eInteger, eDouble, eBool} type;
96  bool bVal;
97  int iVal;
98  double dVal;
99  };
100 
102  class Filter {
103  double prev_in;
104  double prev_out;
105  double ca;
106  double cb;
107  public: Filter(void) {}
108  public: Filter(double coeff, double dt) {
109  prev_in = prev_out = 0.0;
110  double denom = 2.0 + coeff*dt;
111  ca = coeff*dt/denom;
112  cb = (2.0 - coeff*dt)/denom;
113  }
114  public: double execute(double in) {
115  double out = (in + prev_in)*ca + prev_out*cb;
116  prev_in = in;
117  prev_out = out;
118  return out;
119  }
120  };
121 
123 
124  static char highint[5];
127  static char halfint[5];
129  static char normint[6];
131  static char reset[5];
133  static char underon[5];
135  static char underoff[6];
137  static char fgblue[6];
139  static char fgcyan[6];
141  static char fgred[6];
143  static char fggreen[6];
145  static char fgdef[6];
147 
149 
150 
153  void PutMessage(const Message& msg);
157  void PutMessage(const std::string& text);
162  void PutMessage(const std::string& text, bool bVal);
167  void PutMessage(const std::string& text, int iVal);
172  void PutMessage(const std::string& text, double dVal);
175  int SomeMessages(void) { return !Messages.empty(); }
178  void ProcessMessage(void);
184 
187  std::string GetVersion(void) {return JSBSim_version;}
188 
190  void disableHighLighting(void);
191 
192  static short debug_lvl;
193 
197  static double KelvinToFahrenheit (double kelvin) {
198  return 1.8*kelvin - 459.4;
199  }
200 
204  static double CelsiusToRankine (double celsius) {
205  return celsius * 1.8 + 491.67;
206  }
207 
211  static double RankineToCelsius (double rankine) {
212  return (rankine - 491.67)/1.8;
213  }
214 
218  static double KelvinToRankine (double kelvin) {
219  return kelvin * 1.8;
220  }
221 
225  static double RankineToKelvin (double rankine) {
226  return rankine/1.8;
227  }
228 
232  static double FahrenheitToCelsius (double fahrenheit) {
233  return (fahrenheit - 32.0)/1.8;
234  }
235 
239  static double CelsiusToFahrenheit (double celsius) {
240  return celsius * 1.8 + 32.0;
241  }
242 
246  static double CelsiusToKelvin (double celsius) {
247  return celsius + 273.15;
248  }
249 
253  static double KelvinToCelsius (double kelvin) {
254  return kelvin - 273.15;
255  }
256 
260  static double FeetToMeters (double measure) {
261  return measure*0.3048;
262  }
263 
271  static double PitotTotalPressure(double mach, double p);
272 
283  static double VcalibratedFromMach(double mach, double p, double psl, double rhosl);
284 
294  static double MachFromVcalibrated(double vcas, double p, double psl, double rhosl);
295 
300  static bool EqualToRoundoff(double a, double b) {
301  double eps = 2.0*DBL_EPSILON;
302  return std::fabs(a - b) <= eps * std::max<double>(std::fabs(a), std::fabs(b));
303  }
304 
309  static bool EqualToRoundoff(float a, float b) {
310  float eps = 2.0*FLT_EPSILON;
311  return std::fabs(a - b) <= eps * std::max<double>(std::fabs(a), std::fabs(b));
312  }
313 
318  static bool EqualToRoundoff(float a, double b) {
319  return EqualToRoundoff(a, (float)b);
320  }
321 
326  static bool EqualToRoundoff(double a, float b) {
327  return EqualToRoundoff((float)a, b);
328  }
329 
332  static double Constrain(double min, double value, double max) {
333  return value<min?(min):(value>max?(max):(value));
334  }
335 
336  static double sign(double num) {return num>=0.0?1.0:-1.0;}
337 
338  static double GaussianRandomNumber(void);
339 
340 protected:
341  static Message localMsg;
342 
343  static std::queue <Message> Messages;
344 
345  void Debug(int) {};
346 
347  static unsigned int messageId;
348 
349  static const double radtodeg;
350  static const double degtorad;
351  static const double hptoftlbssec;
352  static const double psftoinhg;
353  static const double psftopa;
354  static const double fpstokts;
355  static const double ktstofps;
356  static const double inchtoft;
357  static const double in3tom3;
358  static const double m3toft3;
359  static const double inhgtopa;
360  static const double fttom;
361  static double Reng; // Specific Gas Constant,ft^2/(sec^2*R)
362  static double Rstar;
363  static double Mair;
364  static const double SHRatio;
365  static const double lbtoslug;
366  static const double slugtolb;
367  static const double kgtolb;
368  static const double kgtoslug;
369  static const std::string needed_cfg_version;
370  static const std::string JSBSim_version;
371 
372  static std::string CreateIndexedPropertyName(const std::string& Property, int index);
373 
374  static int gaussian_random_number_phase;
375 
376 public:
378 enum {eL = 1, eM, eN };
380 enum {eP = 1, eQ, eR };
382 enum {eU = 1, eV, eW };
384 enum {eX = 1, eY, eZ };
386 enum {ePhi = 1, eTht, ePsi };
388 enum {eDrag = 1, eSide, eLift };
390 enum {eRoll = 1, ePitch, eYaw };
392 enum {eNorth = 1, eEast, eDown };
394 enum {eLat = 1, eLong, eRad };
396 enum {inNone = 0, inDegrees, inRadians, inMeters, inFeet };
397 
398 };
399 
400 }
401 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402 #endif
403 
virtual ~FGJSBBase()
Destructor for FGJSBBase.
Definition: FGJSBBase.h:86
static char fgcyan[6]
cyan text
Definition: FGJSBBase.h:139
static bool EqualToRoundoff(float a, float b)
Finite precision comparison.
Definition: FGJSBBase.h:309
static double Constrain(double min, double value, double max)
Constrain a value between a minimum and a maximum value.
Definition: FGJSBBase.h:332
int SomeMessages(void)
Reads the message on the queue (but does not delete it).
Definition: FGJSBBase.h:175
static double KelvinToFahrenheit(double kelvin)
Converts from degrees Kelvin to degrees Fahrenheit.
Definition: FGJSBBase.h:197
static double CelsiusToFahrenheit(double celsius)
Converts from degrees Celsius to degrees Fahrenheit.
Definition: FGJSBBase.h:239
static double RankineToCelsius(double rankine)
Converts from degrees Rankine to degrees Celsius.
Definition: FGJSBBase.h:211
FGJSBBase()
Constructor for FGJSBBase.
Definition: FGJSBBase.h:83
static char halfint[5]
low intensity text
Definition: FGJSBBase.h:127
static char reset[5]
resets text properties
Definition: FGJSBBase.h:131
std::string GetVersion(void)
Returns the version number of JSBSim.
Definition: FGJSBBase.h:187
void disableHighLighting(void)
Disables highlighting in the console output.
Definition: FGJSBBase.cpp:224
static char normint[6]
normal intensity text
Definition: FGJSBBase.h:129
void PutMessage(const Message &msg)
Places a Message structure on the Message queue.
Definition: FGJSBBase.cpp:123
static double PitotTotalPressure(double mach, double p)
Compute the total pressure in front of the Pitot tube.
Definition: FGJSBBase.cpp:278
static char fgred[6]
red text
Definition: FGJSBBase.h:141
static double VcalibratedFromMach(double mach, double p, double psl, double rhosl)
Calculate the calibrated airspeed from the Mach number.
Definition: FGJSBBase.cpp:305
static double CelsiusToRankine(double celsius)
Converts from degrees Celsius to degrees Rankine.
Definition: FGJSBBase.h:204
First order, (low pass / lag) filter.
Definition: FGJSBBase.h:102
static double MachFromVcalibrated(double vcas, double p, double psl, double rhosl)
Calculate the Mach number from the calibrated airspeed.
Definition: FGJSBBase.cpp:315
static char fgdef[6]
default text
Definition: FGJSBBase.h:145
void ProcessMessage(void)
Reads the message on the queue and removes it from the queue.
Definition: FGJSBBase.cpp:181
static bool EqualToRoundoff(double a, float b)
Finite precision comparison.
Definition: FGJSBBase.h:326
JSBSim Base class.
Definition: FGJSBBase.h:80
static double RankineToKelvin(double rankine)
Converts from degrees Rankine to degrees Kelvin.
Definition: FGJSBBase.h:225
static char fggreen[6]
green text
Definition: FGJSBBase.h:143
static char underoff[6]
underline off
Definition: FGJSBBase.h:135
static bool EqualToRoundoff(double a, double b)
Finite precision comparison.
Definition: FGJSBBase.h:300
static char fgblue[6]
blue text
Definition: FGJSBBase.h:137
static double CelsiusToKelvin(double celsius)
Converts from degrees Celsius to degrees Kelvin.
Definition: FGJSBBase.h:246
JSBSim Message structure.
Definition: FGJSBBase.h:89
static double FeetToMeters(double measure)
Converts from feet to meters.
Definition: FGJSBBase.h:260
static char highint[5]
highlights text
Definition: FGJSBBase.h:125
static bool EqualToRoundoff(float a, double b)
Finite precision comparison.
Definition: FGJSBBase.h:318
static double FahrenheitToCelsius(double fahrenheit)
Converts from degrees Fahrenheit to degrees Celsius.
Definition: FGJSBBase.h:232
static double KelvinToRankine(double kelvin)
Converts from degrees Kelvin to degrees Rankine.
Definition: FGJSBBase.h:218
static char underon[5]
underlines text
Definition: FGJSBBase.h:133
static double KelvinToCelsius(double kelvin)
Converts from degrees Kelvin to degrees Celsius.
Definition: FGJSBBase.h:253
Message * ProcessNextMessage(void)
Reads the next message on the queue and removes it from the queue.
Definition: FGJSBBase.cpp:213