]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGJSBBase.h
Expose the strut compression.
[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 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 General Public License for more
17  details.
18
19  You should have received a copy of the GNU 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 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
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 # ifndef M_PI
69 #  define M_PI 3.14159265358979323846
70 # endif
71
72 #endif
73
74 #if !defined(WIN32) || defined(__GNUC__)
75 using std::max;
76 #endif
77
78 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79 DEFINITIONS
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
81
82 #define ID_JSBBASE "$Id$"
83
84 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85 FORWARD DECLARATIONS
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
87
88 namespace JSBSim {
89
90 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91 CLASS DOCUMENTATION
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
93
94 /** JSBSim Base class.
95     @author Jon S. Berndt
96     @version $Id$
97 */
98
99 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 CLASS DECLARATION
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
102
103 class FGJSBBase {
104 public:
105   /// Constructor for FGJSBBase.
106   FGJSBBase() {};
107
108   /// Destructor for FGJSBBase.
109   ~FGJSBBase() {};
110
111   /// JSBSim Message structure
112   typedef struct Msg {
113     unsigned int fdmId;
114     unsigned int messageId;
115     string text;
116     string subsystem;
117     enum mType {eText, eInteger, eDouble, eBool} type;
118     bool bVal;
119     int  iVal;
120     double dVal;
121   } Message;
122
123   ///@name JSBSim console output highlighting terms.
124   //@{
125   /// highlights text
126   static char highint[5];
127   /// low intensity text
128   static char halfint[5];
129   /// normal intensity text
130   static char normint[6];
131   /// resets text properties
132   static char reset[5];
133   /// underlines text
134   static char underon[5];
135   /// underline off
136   static char underoff[6];
137   /// blue text
138   static char fgblue[6];
139   /// cyan text
140   static char fgcyan[6];
141   /// red text
142   static char fgred[6];
143   /// green text
144   static char fggreen[6];
145   /// default text
146   static char fgdef[6];
147   //@}
148
149   ///@name JSBSim Messaging functions
150   //@{
151   /** Places a Message structure on the Message queue.
152       @param msg pointer to a Message structure
153       @return pointer to a Message structure */
154   Message* PutMessage(Message* msg);
155   /** Creates a message with the given text and places it on the queue.
156       @param text message text
157       @return pointer to a Message structure */
158   Message* PutMessage(const string& text);
159   /** Creates a message with the given text and boolean value and places it on the queue.
160       @param text message text
161       @param bVal boolean value associated with the message
162       @return pointer to a Message structure */
163   Message* PutMessage(const string& text, bool bVal);
164   /** Creates a message with the given text and integer value and places it on the queue.
165       @param text message text
166       @param iVal integer value associated with the message
167       @return pointer to a Message structure */
168   Message* PutMessage(const string& text, int iVal);
169   /** Creates a message with the given text and double value and places it on the queue.
170       @param text message text
171       @param dVal double value associated with the message
172       @return pointer to a Message structure */
173   Message* PutMessage(const string& text, double dVal);
174   /** Reads the message on the queue (but does not delete it).
175       @return pointer to a Message structure (or NULL if no mesage) */
176   Message* ReadMessage(void);
177   /** Reads the message on the queue and removes it from the queue.
178       @return pointer to a Message structure (or NULL if no mesage) */
179   Message* ProcessMessage(void);
180   //@}
181   string GetVersion(void) {return JSBSim_version;}
182
183   void disableHighLighting(void);
184
185   static short debug_lvl;
186   static double KelvinToFahrenheit (double kelvin) {
187     return 1.8*kelvin - 459.4;
188   }
189
190   static double RankineToCelsius (double rankine) {
191     return (rankine - 491.67)/1.8;
192   }
193
194   static double FahrenheitToCelsius (double fahrenheit) {
195     return (fahrenheit - 32.0)/1.8;
196   }
197
198   static double CelsiusToFahrenheit (double celsius) {
199     return celsius * 1.8 + 32.0;
200   }
201
202   /** Finite precision comparison.
203       @param a first value to compare
204       @param b second value to compare
205       @return if the two values can be considered equal up to roundoff */
206   static bool EqualToRoundoff(double a, double b) {
207     double eps = 2.0*DBL_EPSILON;
208     return fabs(a - b) <= eps*max(fabs(a), fabs(b));
209   }
210
211   /** Finite precision comparison.
212       @param a first value to compare
213       @param b second value to compare
214       @return if the two values can be considered equal up to roundoff */
215   static bool EqualToRoundoff(float a, float b) {
216     float eps = 2.0*FLT_EPSILON;
217     return fabs(a - b) <= eps*max(fabs(a), fabs(b));
218   }
219
220   /** Finite precision comparison.
221       @param a first value to compare
222       @param b second value to compare
223       @return if the two values can be considered equal up to roundoff */
224   static bool EqualToRoundoff(float a, double b) {
225     return EqualToRoundoff(a, (float)b);
226   }
227
228   /** Finite precision comparison.
229       @param a first value to compare
230       @param b second value to compare
231       @return if the two values can be considered equal up to roundoff */
232   static bool EqualToRoundoff(double a, float b) {
233     return EqualToRoundoff((float)a, b);
234   }
235
236 protected:
237   static Message localMsg;
238
239   static std::queue <Message*> Messages;
240
241   void Debug(int from) {};
242
243   static unsigned int frame;
244   static unsigned int messageId;
245
246   static const double radtodeg;
247   static const double degtorad;
248   static const double hptoftlbssec;
249   static const double psftoinhg;
250   static const double fpstokts;
251   static const double ktstofps;
252   static const double inchtoft;
253   static const double in3tom3;
254   static double Reng;         // Specific Gas Constant,ft^2/(sec^2*R)
255   static const double SHRatio;
256   static const double lbtoslug;
257   static const double slugtolb;
258   static const string needed_cfg_version;
259   static const string JSBSim_version;
260 };
261
262 /// Moments L, M, N
263 enum {eL     = 1, eM,     eN    };
264 /// Rates P, Q, R
265 enum {eP     = 1, eQ,     eR    };
266 /// Velocities U, V, W
267 enum {eU     = 1, eV,     eW    };
268 /// Positions X, Y, Z
269 enum {eX     = 1, eY,     eZ    };
270 /// Euler angles Phi, Theta, Psi
271 enum {ePhi   = 1, eTht,   ePsi  };
272 /// Stability axis forces, Drag, Side force, Lift
273 enum {eDrag  = 1, eSide,  eLift };
274 /// Local frame orientation Roll, Pitch, Yaw
275 enum {eRoll  = 1, ePitch, eYaw  };
276 /// Local frame position North, East, Down
277 enum {eNorth = 1, eEast,  eDown };
278 /// Locations Radius, Latitude, Longitude
279 enum {eLat = 1, eLong, eRad     };
280 /// Conversion specifiers
281 enum {inNone = 0, inDegrees, inRadians, inMeters, inFeet };
282
283 }
284 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 #endif
286