]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGJSBBase.h
2dd3637389cc29d78ee4e132a31ea1009e2b6e15
[flightgear.git] / src / FDM / JSBSim / 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 (jsb@hal-pc.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
43 #ifdef FGFS
44 #  include <simgear/compiler.h>
45 #  include <math.h>
46 #  include <queue>
47 #  include STL_STRING
48
49 SG_USING_STD(string);
50
51 #  ifndef M_PI
52 #    include <simgear/constants.h>
53 #    define M_PI SG_PI
54 #  endif
55
56 #else  // JSBSim section
57
58 #  include <queue>
59 #  include <string>
60 #  if defined(sgi) && !defined(__GNUC__)
61 #    include <math.h>
62 #  else
63 #    include <cmath>
64 #  endif
65
66 using std::string;
67
68 #  if defined(_MSC_VER) && _MSC_VER <= 1200
69 #    ifndef max
70 #      define max(a,b)            (((a) > (b)) ? (a) : (b))
71 #    endif
72
73 #    ifndef min
74 #      define min(a,b)            (((a) < (b)) ? (a) : (b))
75 #    endif
76 #  else
77
78 using std::fabs;
79
80 #  endif
81
82 #  ifndef M_PI
83 #    define M_PI 3.14159265358979323846
84 #  endif
85
86 #endif
87
88 #if !defined(WIN32) || defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 1300))
89 using std::max;
90 #endif
91
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 DEFINITIONS
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
95
96 #define ID_JSBBASE "$Id$"
97
98 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99 FORWARD DECLARATIONS
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
101
102 namespace JSBSim {
103
104 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 CLASS DOCUMENTATION
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
107
108 /** JSBSim Base class.
109 *   This class provides universal constants, utility functions, messaging
110 *   functions, and enumerated constants to JSBSim.
111     @author Jon S. Berndt
112     @version $Id$
113 */
114
115 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116 CLASS DECLARATION
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
118
119 class FGJSBBase {
120 public:
121   /// Constructor for FGJSBBase.
122   FGJSBBase() {};
123
124   /// Destructor for FGJSBBase.
125   ~FGJSBBase() {};
126
127   /// JSBSim Message structure
128   class Message {
129   public:
130     unsigned int fdmId;
131     unsigned int messageId;
132     string text;
133     string subsystem;
134     enum mType {eText, eInteger, eDouble, eBool} type;
135     bool bVal;
136     int  iVal;
137     double dVal;
138   };
139
140   ///@name JSBSim console output highlighting terms.
141   //@{
142   /// highlights text
143   static char highint[5];
144   /// low intensity text
145   static char halfint[5];
146   /// normal intensity text
147   static char normint[6];
148   /// resets text properties
149   static char reset[5];
150   /// underlines text
151   static char underon[5];
152   /// underline off
153   static char underoff[6];
154   /// blue text
155   static char fgblue[6];
156   /// cyan text
157   static char fgcyan[6];
158   /// red text
159   static char fgred[6];
160   /// green text
161   static char fggreen[6];
162   /// default text
163   static char fgdef[6];
164   //@}
165
166   ///@name JSBSim Messaging functions
167   //@{
168   /** Places a Message structure on the Message queue.
169       @param msg pointer to a Message structure
170       @return pointer to a Message structure */
171 void PutMessage(const Message& msg);
172   /** Creates a message with the given text and places it on the queue.
173       @param text message text
174       @return pointer to a Message structure */
175   void PutMessage(const string& text);
176   /** Creates a message with the given text and boolean value and places it on the queue.
177       @param text message text
178       @param bVal boolean value associated with the message
179       @return pointer to a Message structure */
180 void PutMessage(const string& text, bool bVal);
181   /** Creates a message with the given text and integer value and places it on the queue.
182       @param text message text
183       @param iVal integer value associated with the message
184       @return pointer to a Message structure */
185 void PutMessage(const string& text, int iVal);
186   /** Creates a message with the given text and double value and places it on the queue.
187       @param text message text
188       @param dVal double value associated with the message
189       @return pointer to a Message structure */
190 void PutMessage(const string& text, double dVal);
191   /** Reads the message on the queue (but does not delete it).
192       @return 1 if some messages */
193   int SomeMessages(void);
194   /** Reads the message on the queue and removes it from the queue.
195       @return pointer to a Message structure (or NULL if no mesage) */
196   Message* ProcessMessage(void);
197   //@}
198
199   /** Returns the version number of JSBSim.
200   *   @return The version number of JSBSim. */
201   string GetVersion(void) {return JSBSim_version;}
202
203   /// Disables highlighting in the console output.
204   void disableHighLighting(void);
205
206   static short debug_lvl;
207
208   /** Converts from degrees Kelvin to degrees Fahrenheit.
209   *   @param kelvin The temperature in degrees Kelvin.
210   *   @return The temperature in Fahrenheit. */
211   static double KelvinToFahrenheit (double kelvin) {
212     return 1.8*kelvin - 459.4;
213   }
214
215   /** Converts from degrees Rankine to degrees Celsius.
216   *   @param rankine The temperature in degrees Rankine.
217   *   @return The temperature in Celsius. */
218   static double RankineToCelsius (double rankine) {
219     return (rankine - 491.67)/1.8;
220   }
221
222   /** Converts from degrees Rankine to degrees Kelvin.
223   *   @param rankine The temperature in degrees Rankine.
224   *   @return The temperature in Kelvin. */
225   static double RankineToKelvin (double rankine) {
226     return rankine/1.8;
227   }
228
229   /** Converts from degrees Fahrenheit to degrees Celsius.
230   *   @param fahrenheit The temperature in degrees Fahrenheit.
231   *   @return The temperature in Celsius. */
232   static double FahrenheitToCelsius (double fahrenheit) {
233     return (fahrenheit - 32.0)/1.8;
234   }
235
236   /** Converts from degrees Celsius to degrees Fahrenheit.
237   *   @param celsius The temperature in degrees Celsius.
238   *   @return The temperature in Fahrenheit. */
239   static double CelsiusToFahrenheit (double celsius) {
240     return celsius * 1.8 + 32.0;
241   }
242
243   /** Finite precision comparison.
244       @param a first value to compare
245       @param b second value to compare
246       @return if the two values can be considered equal up to roundoff */
247   static bool EqualToRoundoff(double a, double b) {
248     double eps = 2.0*DBL_EPSILON;
249     return fabs(a - b) <= eps*max(fabs(a), fabs(b));
250   }
251
252   /** Finite precision comparison.
253       @param a first value to compare
254       @param b second value to compare
255       @return if the two values can be considered equal up to roundoff */
256   static bool EqualToRoundoff(float a, float b) {
257     float eps = 2.0*FLT_EPSILON;
258     return fabs(a - b) <= eps*max(fabs(a), fabs(b));
259   }
260
261   /** Finite precision comparison.
262       @param a first value to compare
263       @param b second value to compare
264       @return if the two values can be considered equal up to roundoff */
265   static bool EqualToRoundoff(float a, double b) {
266     return EqualToRoundoff(a, (float)b);
267   }
268
269   /** Finite precision comparison.
270       @param a first value to compare
271       @param b second value to compare
272       @return if the two values can be considered equal up to roundoff */
273   static bool EqualToRoundoff(double a, float b) {
274     return EqualToRoundoff((float)a, b);
275   }
276
277 protected:
278   static Message localMsg;
279
280   static std::queue <Message> Messages;
281
282   void Debug(int from) {};
283
284   static unsigned int messageId;
285
286   static const double radtodeg;
287   static const double degtorad;
288   static const double hptoftlbssec;
289   static const double psftoinhg;
290   static const double psftopa;
291   static const double fpstokts;
292   static const double ktstofps;
293   static const double inchtoft;
294   static const double in3tom3;
295   static double Reng;         // Specific Gas Constant,ft^2/(sec^2*R)
296   static const double SHRatio;
297   static const double lbtoslug;
298   static const double slugtolb;
299   static const string needed_cfg_version;
300   static const string JSBSim_version;
301
302 public:
303 /// Moments L, M, N
304 enum {eL     = 1, eM,     eN    };
305 /// Rates P, Q, R
306 enum {eP     = 1, eQ,     eR    };
307 /// Velocities U, V, W
308 enum {eU     = 1, eV,     eW    };
309 /// Positions X, Y, Z
310 enum {eX     = 1, eY,     eZ    };
311 /// Euler angles Phi, Theta, Psi
312 enum {ePhi   = 1, eTht,   ePsi  };
313 /// Stability axis forces, Drag, Side force, Lift
314 enum {eDrag  = 1, eSide,  eLift };
315 /// Local frame orientation Roll, Pitch, Yaw
316 enum {eRoll  = 1, ePitch, eYaw  };
317 /// Local frame position North, East, Down
318 enum {eNorth = 1, eEast,  eDown };
319 /// Locations Radius, Latitude, Longitude
320 enum {eLat = 1, eLong, eRad     };
321 /// Conversion specifiers
322 enum {inNone = 0, inDegrees, inRadians, inMeters, inFeet };
323
324 };
325
326 }
327 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328 #endif
329