1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 2001 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
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.
27 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 # include <simgear/compiler.h>
52 # include <simgear/constants.h>
56 #else // JSBSim section
60 # if defined(sgi) && !defined(__GNUC__)
68 # if defined(_MSC_VER) && _MSC_VER <= 1200
70 # define max(a,b) (((a) > (b)) ? (a) : (b))
74 # define min(a,b) (((a) < (b)) ? (a) : (b))
83 # define M_PI 3.14159265358979323846
88 #if !defined(WIN32) || defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 1300))
92 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
96 #define ID_JSBBASE "$Id$"
98 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
104 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
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
115 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
121 /// Constructor for FGJSBBase.
124 /// Destructor for FGJSBBase.
127 /// JSBSim Message structure
130 unsigned int messageId;
133 enum mType {eText, eInteger, eDouble, eBool} type;
139 ///@name JSBSim console output highlighting terms.
142 static char highint[5];
143 /// low intensity text
144 static char halfint[5];
145 /// normal intensity text
146 static char normint[6];
147 /// resets text properties
148 static char reset[5];
150 static char underon[5];
152 static char underoff[6];
154 static char fgblue[6];
156 static char fgcyan[6];
158 static char fgred[6];
160 static char fggreen[6];
162 static char fgdef[6];
165 ///@name JSBSim Messaging functions
167 /** Places a Message structure on the Message queue.
168 @param msg pointer to a Message structure
169 @return pointer to a Message structure */
170 Message* PutMessage(Message* msg);
171 /** Creates a message with the given text and places it on the queue.
172 @param text message text
173 @return pointer to a Message structure */
174 Message* PutMessage(const string& text);
175 /** Creates a message with the given text and boolean value and places it on the queue.
176 @param text message text
177 @param bVal boolean value associated with the message
178 @return pointer to a Message structure */
179 Message* PutMessage(const string& text, bool bVal);
180 /** Creates a message with the given text and integer value and places it on the queue.
181 @param text message text
182 @param iVal integer value associated with the message
183 @return pointer to a Message structure */
184 Message* PutMessage(const string& text, int iVal);
185 /** Creates a message with the given text and double value and places it on the queue.
186 @param text message text
187 @param dVal double value associated with the message
188 @return pointer to a Message structure */
189 Message* PutMessage(const string& text, double dVal);
190 /** Reads the message on the queue (but does not delete it).
191 @return pointer to a Message structure (or NULL if no mesage) */
192 Message* ReadMessage(void);
193 /** Reads the message on the queue and removes it from the queue.
194 @return pointer to a Message structure (or NULL if no mesage) */
195 Message* ProcessMessage(void);
198 /** Returns the version number of JSBSim.
199 * @return The version number of JSBSim. */
200 string GetVersion(void) {return JSBSim_version;}
202 /// Disables highlighting in the console output.
203 void disableHighLighting(void);
205 static short debug_lvl;
207 /** Converts from degrees Kelvin to degrees Fahrenheit.
208 * @param kelvin The temperature in degrees Kelvin.
209 * @return The temperature in Fahrenheit. */
210 static double KelvinToFahrenheit (double kelvin) {
211 return 1.8*kelvin - 459.4;
214 /** Converts from degrees Rankine to degrees Celsius.
215 * @param rankine The temperature in degrees Rankine.
216 * @return The temperature in Celsius. */
217 static double RankineToCelsius (double rankine) {
218 return (rankine - 491.67)/1.8;
221 /** Converts from degrees Rankine to degrees Kelvin.
222 * @param rankine The temperature in degrees Rankine.
223 * @return The temperature in Kelvin. */
224 static double RankineToKelvin (double rankine) {
228 /** Converts from degrees Fahrenheit to degrees Celsius.
229 * @param fahrenheit The temperature in degrees Fahrenheit.
230 * @return The temperature in Celsius. */
231 static double FahrenheitToCelsius (double fahrenheit) {
232 return (fahrenheit - 32.0)/1.8;
235 /** Converts from degrees Celsius to degrees Fahrenheit.
236 * @param celsius The temperature in degrees Celsius.
237 * @return The temperature in Fahrenheit. */
238 static double CelsiusToFahrenheit (double celsius) {
239 return celsius * 1.8 + 32.0;
242 /** Finite precision comparison.
243 @param a first value to compare
244 @param b second value to compare
245 @return if the two values can be considered equal up to roundoff */
246 static bool EqualToRoundoff(double a, double b) {
247 double eps = 2.0*DBL_EPSILON;
248 return fabs(a - b) <= eps*max(fabs(a), fabs(b));
251 /** Finite precision comparison.
252 @param a first value to compare
253 @param b second value to compare
254 @return if the two values can be considered equal up to roundoff */
255 static bool EqualToRoundoff(float a, float b) {
256 float eps = 2.0*FLT_EPSILON;
257 return fabs(a - b) <= eps*max(fabs(a), fabs(b));
260 /** Finite precision comparison.
261 @param a first value to compare
262 @param b second value to compare
263 @return if the two values can be considered equal up to roundoff */
264 static bool EqualToRoundoff(float a, double b) {
265 return EqualToRoundoff(a, (float)b);
268 /** Finite precision comparison.
269 @param a first value to compare
270 @param b second value to compare
271 @return if the two values can be considered equal up to roundoff */
272 static bool EqualToRoundoff(double a, float b) {
273 return EqualToRoundoff((float)a, b);
277 static Message localMsg;
279 static std::queue <Message*> Messages;
281 void Debug(int from) {};
283 static unsigned int frame;
284 static unsigned int messageId;
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;
304 enum {eL = 1, eM, eN };
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 };
327 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%