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